Skip to content

Commit

Permalink
features: fix unsupported progtype/helper probes
Browse files Browse the repository at this point in the history
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 <r.goegge@isovalent.com>
  • Loading branch information
rgo3 authored and lmb committed Jul 6, 2023
1 parent f963728 commit 270c859
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions features/prog.go
Expand Up @@ -234,6 +234,10 @@ func HaveProgramHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error {
}

func haveProgramHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error {
if ok := helperProbeNotImplemented(pt); ok {
return fmt.Errorf("no feature probe for %v/%v", pt, helper)
}

if err := HaveProgramType(pt); err != nil {
return err
}
Expand Down Expand Up @@ -283,3 +287,11 @@ func haveProgramHelper(pt ebpf.ProgramType, helper asm.BuiltinFunc) error {

return err
}

func helperProbeNotImplemented(pt ebpf.ProgramType) bool {
switch pt {
case ebpf.Extension, ebpf.LSM, ebpf.StructOps, ebpf.Tracing:
return true
}
return false
}
12 changes: 12 additions & 0 deletions features/prog_test.go
Expand Up @@ -80,3 +80,15 @@ func TestHaveProgramHelper(t *testing.T) {

}
}

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

0 comments on commit 270c859

Please sign in to comment.