Skip to content

Commit 270c859

Browse files
rgo3lmb
authored andcommitted
features: fix unsupported progtype/helper probes
By enabling feature probes for the program types Tracing, Extension, LSM and StructOps within the HaveProgramType API, we overlooked that this would cause false negative results when using these types with the HaveProgramHelper API. To probe for these program types we craft specialized ProgramSpecs, but don't do the same when probing for these types in combination with an arbitrary helper. For now we should return an inconclusive error from the HaveProgramHelper API until we find a better way to probe for helpers with these program types. Fixes: #1082 Signed-off-by: Robin Gögge <[email protected]>
1 parent f963728 commit 270c859

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

features/prog.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ func HaveProgramHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error {
234234
}
235235

236236
func haveProgramHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error {
237+
if ok := helperProbeNotImplemented(pt); ok {
238+
return fmt.Errorf("no feature probe for %v/%v", pt, helper)
239+
}
240+
237241
if err := HaveProgramType(pt); err != nil {
238242
return err
239243
}
@@ -283,3 +287,11 @@ func haveProgramHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error {
283287

284288
return err
285289
}
290+
291+
func helperProbeNotImplemented(pt ebpf.ProgramType) bool {
292+
switch pt {
293+
case ebpf.Extension, ebpf.LSM, ebpf.StructOps, ebpf.Tracing:
294+
return true
295+
}
296+
return false
297+
}

features/prog_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ func TestHaveProgramHelper(t *testing.T) {
8080

8181
}
8282
}
83+
84+
func TestHelperProbeNotImplemented(t *testing.T) {
85+
// Currently we don't support probing helpers for Tracing, Extension, LSM and StructOps programs.
86+
// For each of those test the availability of the FnMapLookupElem helper and expect it to fail.
87+
for _, pt := range []ebpf.ProgramType{ebpf.Tracing, ebpf.Extension, ebpf.LSM, ebpf.StructOps} {
88+
t.Run(pt.String(), func(t *testing.T) {
89+
if err := HaveProgramHelper(pt, asm.FnMapLookupElem); err == nil {
90+
t.Fatal("Expected an error")
91+
}
92+
})
93+
}
94+
}

0 commit comments

Comments
 (0)