From 270c859894bd38cdd0c7783317b16343409e4df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20G=C3=B6gge?= Date: Tue, 4 Jul 2023 17:23:09 +0200 Subject: [PATCH] features: fix unsupported progtype/helper probes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- features/prog.go | 12 ++++++++++++ features/prog_test.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/features/prog.go b/features/prog.go index 7a6a71b8f..a11363796 100644 --- a/features/prog.go +++ b/features/prog.go @@ -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 } @@ -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 +} diff --git a/features/prog_test.go b/features/prog_test.go index edd01e76b..16e4b4609 100644 --- a/features/prog_test.go +++ b/features/prog_test.go @@ -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") + } + }) + } +}