Skip to content

Commit

Permalink
prog_test: remove map from TestProgramInstructions
Browse files Browse the repository at this point in the history
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 <timo@isovalent.com>
  • Loading branch information
ti-mo committed May 4, 2022
1 parent b00a330 commit 7e5a246
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 4 additions & 1 deletion info.go
Expand Up @@ -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.
//
Expand Down
5 changes: 0 additions & 5 deletions prog_test.go
Expand Up @@ -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",
Expand Down

0 comments on commit 7e5a246

Please sign in to comment.