Skip to content

Commit

Permalink
Attempt to fix ARM CI
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Fedotov <anfedotoff@yandex-team.ru>
  • Loading branch information
anfedotoff committed Jul 12, 2024
1 parent 7025814 commit 256b762
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion pkg/bpf/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
modifyReturn Feature
modifyReturnSyscall Feature
linkPin Feature
lsm Feature
)

func HasOverrideHelper() bool {
Expand Down Expand Up @@ -222,7 +223,7 @@ func HasProgramLargeSize() bool {
return features.HaveLargeInstructions() == nil
}

func HasLSMPrograms() bool {
func detectLSM() bool {
if features.HaveProgramType(ebpf.LSM) != nil {
return false
}
Expand All @@ -232,11 +233,44 @@ func HasLSMPrograms() bool {
return false
}
if strings.Contains(string(b), "bpf") {
prog, err := ebpf.NewProgram(&ebpf.ProgramSpec{
Name: "probe_lsm_file_open",
Type: ebpf.LSM,
Instructions: asm.Instructions{
asm.Mov.Imm(asm.R0, 0),
asm.Return(),
},
AttachTo: "file_open",
AttachType: ebpf.AttachLSMMac,
License: "Dual BSD/GPL",
})
if err != nil {
logger.GetLogger().WithError(err).Error("failed to load lsm probe")
return false
}
defer prog.Close()

link, err := link.AttachLSM(link.LSMOptions{
Program: prog,
})
if err != nil {
logger.GetLogger().WithError(err).Error("failed to attach lsm probe")
return false
}
link.Close()
return true
}

return false
}

func HasLSMPrograms() bool {
lsm.init.Do(func() {
lsm.detected = detectLSM()
})
return lsm.detected
}

func detectLinkPin() (bool, error) {
prog, err := ebpf.NewProgram(&ebpf.ProgramSpec{
Name: "probe_bpf_kprobe",
Expand Down

0 comments on commit 256b762

Please sign in to comment.