From 7e5a2461e928e1a41cfa7cd95af904f56b10fbdb Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Tue, 3 May 2022 21:21:14 +0200 Subject: [PATCH] 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",