Skip to content

Commit

Permalink
pkg/bpf: improve modify return syscall detection err flow
Browse files Browse the repository at this point in the history
Avoiding logging in private function (except for debug), pass the error
to the caller.

Signed-off-by: Mahe Tardy <[email protected]>
  • Loading branch information
mtardy authored and jrfastab committed Jan 25, 2024
1 parent d06d955 commit 0430d5b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/bpf/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ func detectModifyReturn() bool {
return true
}

func detectModifyReturnSyscall() bool {
func detectModifyReturnSyscall() (bool, error) {
sysGetcpu, err := arch.AddSyscallPrefix("sys_getcpu")
if err != nil {
return false
return false, fmt.Errorf("failed to add arch specific syscall prefix: %w", err)
}
logger.GetLogger().Debugf("probing detectModifyReturnSyscall using %s", sysGetcpu)
prog, err := ebpf.NewProgram(&ebpf.ProgramSpec{
Expand All @@ -140,20 +140,18 @@ func detectModifyReturnSyscall() bool {
License: "MIT",
})
if err != nil {
logger.GetLogger().WithError(err).Info("detectModifyReturnSyscall: failed to load")
return false
return false, fmt.Errorf("failed to load: %w", err)
}
defer prog.Close()

link, err := link.AttachTracing(link.TracingOptions{
Program: prog,
})
if err != nil {
logger.GetLogger().WithError(err).Info("detectModifyReturnSyscall, failed to attach")
return false
return false, fmt.Errorf("failed to attach: %w", err)
}
link.Close()
return true
return true, nil
}

func HasModifyReturn() bool {
Expand All @@ -165,7 +163,11 @@ func HasModifyReturn() bool {

func HasModifyReturnSyscall() bool {
modifyReturnSyscall.init.Do(func() {
modifyReturnSyscall.detected = detectModifyReturnSyscall()
var err error
modifyReturnSyscall.detected, err = detectModifyReturnSyscall()
if err != nil {
logger.GetLogger().WithError(err).Error("detect modify return syscall")
}
})
return modifyReturnSyscall.detected
}
Expand Down

0 comments on commit 0430d5b

Please sign in to comment.