Skip to content

Commit

Permalink
tetragon: Use ebpf/cilium feature test for large instructions
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri authored and jrfastab committed Jan 8, 2024
1 parent 2dcd983 commit c1db417
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions pkg/bpf/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ type Feature struct {
}

var (
kprobeMulti Feature
buildid Feature
modifyReturn Feature
largeProgramSize Feature
kprobeMulti Feature
buildid Feature
modifyReturn Feature
)

func HasOverrideHelper() bool {
Expand Down Expand Up @@ -127,32 +126,8 @@ func HasModifyReturn() bool {
return modifyReturn.detected
}

func detectLargeProgramSize() bool {
insns := asm.Instructions{}

for i := 0; i < 4096; i++ {
insns = append(insns, asm.Mov.Imm(asm.R0, 1))
}
insns = append(insns, asm.Return())

prog, err := ebpf.NewProgram(&ebpf.ProgramSpec{
Type: ebpf.Kprobe,
Instructions: insns,
AttachType: ebpf.AttachModifyReturn,
License: "MIT",
})
if err != nil {
return false
}
prog.Close()
return true
}

func HasProgramLargeSize() bool {
largeProgramSize.init.Do(func() {
largeProgramSize.detected = detectLargeProgramSize()
})
return largeProgramSize.detected
return features.HaveLargeInstructions() == nil
}

func LogFeatures() string {
Expand Down

0 comments on commit c1db417

Please sign in to comment.