From 953d2f59ddf8a6eae816b3af5603857157c9f683 Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Mon, 2 May 2022 17:57:21 +0200 Subject: [PATCH 1/3] map_test: BPF_OBJ_GET file_flags appeared in 4.15 Off by one; 6e71b04a8224 was first tagged in 4.15-rc1. Signed-off-by: Timo Beckers --- map_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map_test.go b/map_test.go index 00b36b705..01afb712d 100644 --- a/map_test.go +++ b/map_test.go @@ -642,7 +642,7 @@ func TestMapLoadPinnedUnpin(t *testing.T) { func TestMapLoadPinnedWithOptions(t *testing.T) { // Introduced in commit 6e71b04a8224. - testutils.SkipOnOldKernel(t, "4.14", "file_flags in BPF_OBJ_GET") + testutils.SkipOnOldKernel(t, "4.15", "file_flags in BPF_OBJ_GET") array := createArray(t) defer array.Close() From 2a6dfb701c9824114d44e945cdfc6670c3a91d7b Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Tue, 3 May 2022 11:57:40 +0200 Subject: [PATCH 2/3] link_test: remove AttachType from cgroup fixtures Since the test is gated by haveProgAttach(), it should not specify AttachType, which is a feature available as of 4.17. Also, CGroupSKB doesn't require specifying AttachType. Signed-off-by: Timo Beckers --- link/link_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/link/link_test.go b/link/link_test.go index f8142fd0c..bafbb4716 100644 --- a/link/link_test.go +++ b/link/link_test.go @@ -85,7 +85,7 @@ func mustCgroupFixtures(t *testing.T) (*os.File, *ebpf.Program) { testutils.SkipIfNotSupported(t, haveProgAttach()) - return testutils.CreateCgroup(t), mustLoadProgram(t, ebpf.CGroupSKB, ebpf.AttachCGroupInetEgress, "") + return testutils.CreateCgroup(t), mustLoadProgram(t, ebpf.CGroupSKB, 0, "") } func testLink(t *testing.T, link Link, prog *ebpf.Program) { From 1bf90d8c193883c9c5bd26d2cfbaaf328abb05b7 Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Tue, 3 May 2022 21:21:14 +0200 Subject: [PATCH 3/3] prog_test: remove map from TestProgramInstructions Kernels up until 4.16 return kernel pointers in the constant field of map load instructions and don't set the source register to pseudo values correctly. This results in an incorrect Tag value calculation on the userspace side. Remove the use of a map fd in TestProgramInstructions to fix the test between kernel versions 4.13 and 4.16. Signed-off-by: Timo Beckers --- info.go | 5 ++++- prog_test.go | 5 ----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/info.go b/info.go index c1ad3fa5a..296da4e9d 100644 --- a/info.go +++ b/info.go @@ -214,7 +214,10 @@ func (pi *ProgramInfo) Runtime() (time.Duration, bool) { // inspecting loaded programs for troubleshooting, dumping, etc. // // For example, map accesses are made to reference their kernel map IDs, -// not the FDs they had when the program was inserted. +// not the FDs they had when the program was inserted. Note that before +// the introduction of bpf_insn_prepare_dump in kernel 4.16, xlated +// instructions were not sanitized, making the output even less reusable +// and less likely to round-trip or evaluate to the same program Tag. // // The first instruction is marked as a symbol using the Program's name. // diff --git a/prog_test.go b/prog_test.go index 78f1e9adf..52e2400a0 100644 --- a/prog_test.go +++ b/prog_test.go @@ -687,17 +687,12 @@ func TestProgramBindMap(t *testing.T) { } func TestProgramInstructions(t *testing.T) { - arr := createArray(t) - defer arr.Close() - name := "test_prog" spec := &ProgramSpec{ Type: SocketFilter, Name: name, Instructions: asm.Instructions{ asm.LoadImm(asm.R0, -1, asm.DWord).WithSymbol(name), - asm.LoadMapPtr(asm.R1, arr.FD()), - asm.Mov.Imm32(asm.R0, 0), asm.Return(), }, License: "MIT",