Skip to content

Commit

Permalink
Remove kernel version check for LSM Resolve flag
Browse files Browse the repository at this point in the history
This condition was not necessary because in any case following code will
return an error since it can not found the required hook. So this commit
remove this check and add a specific case where the error should raise
for LSM hooks only.

Signed-off-by: Tristan d'Audibert <[email protected]>
  • Loading branch information
ScriptSathi authored and olsajiri committed Feb 28, 2025
1 parent 9f60b23 commit 886cad3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pkg/btf/btf.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func FindBtfFuncParamFromHook(hook string, argIndex int) (*btf.FuncParam, error)
}

if err = spec.TypeByName(hook, &hookFn); err != nil {
if strings.HasPrefix(hook, "bpf_lsm_") {
return nil, fmt.Errorf("failed to find BTF type for hook %q: %w."+
"Please check if the hook exists or if your kernel supports BTF for lsm hooks."+
"As an alternative, consider switching to kprobes. ", hook, err)
}
return nil, fmt.Errorf("failed to find BTF type for hook %q: %w", hook, err)
}

Expand Down
6 changes: 0 additions & 6 deletions pkg/sensors/tracing/genericlsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,6 @@ func addLsm(f *v1alpha1.LsmHookSpec, in *addLsmIn) (id idtable.EntryID, err erro
if !bpf.HasProgramLargeSize() {
return errFn(fmt.Errorf("Error: Resolve flag can't be used for your kernel version. Please update to version 5.4 or higher or disable Resolve flag"))
}
if !kernels.MinKernelVersion("5.7.0") {
// bpf_lsm_<hook_name> does not exist in BTF file before 5.7
// https://lore.kernel.org/bpf/[email protected]/
return errFn(fmt.Errorf("Error: LSM programs can not use Resolve flag for your kernel version." +
"Please use Kprobe instead or update your kernel to version 5.7 or higher"))
}
lastBtfType, btfArg, err := resolveBtfArg("bpf_lsm_"+f.Hook, a)
if err != nil {
return errFn(fmt.Errorf("Error on hook %q for index %d : %v", f.Hook, a.Index, err))
Expand Down

0 comments on commit 886cad3

Please sign in to comment.