Skip to content

Commit a49b8ce

Browse files
borkmannanakryiko
authored andcommitted
bpf, selftests: Add verifier test case for jmp32's jeq/jne
Add a test case to trigger the verifier's incorrect conclusion in the case of jmp32's jeq/jne. Also here, make use of dead code elimination, so that we can see the verifier bailing out on unfixed kernels. Before: # ./test_verifier 724 #724/p jeq32/jne32: bounds checking FAIL Failed to load prog 'Permission denied'! R4 !read_ok verification time 8 usec stack depth 0 processed 8 insns (limit 1000000) max_states_per_insn 0 total_states 1 peak_states 1 mark_read 0 Summary: 0 PASSED, 0 SKIPPED, 1 FAILED After: # ./test_verifier 724 #724/p jeq32/jne32: bounds checking OK Summary: 1 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Daniel Borkmann <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 73c4936 commit a49b8ce

File tree

1 file changed

+21
-0
lines changed
  • tools/testing/selftests/bpf/verifier

1 file changed

+21
-0
lines changed

tools/testing/selftests/bpf/verifier/jmp32.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,24 @@
864864
.result = ACCEPT,
865865
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
866866
},
867+
{
868+
"jeq32/jne32: bounds checking",
869+
.insns = {
870+
BPF_MOV64_IMM(BPF_REG_6, 563),
871+
BPF_MOV64_IMM(BPF_REG_2, 0),
872+
BPF_ALU64_IMM(BPF_NEG, BPF_REG_2, 0),
873+
BPF_ALU64_IMM(BPF_NEG, BPF_REG_2, 0),
874+
BPF_ALU32_REG(BPF_OR, BPF_REG_2, BPF_REG_6),
875+
BPF_JMP32_IMM(BPF_JNE, BPF_REG_2, 8, 5),
876+
BPF_JMP_IMM(BPF_JSGE, BPF_REG_2, 500, 2),
877+
BPF_MOV64_IMM(BPF_REG_0, 2),
878+
BPF_EXIT_INSN(),
879+
BPF_MOV64_REG(BPF_REG_0, BPF_REG_4),
880+
BPF_EXIT_INSN(),
881+
BPF_MOV64_IMM(BPF_REG_0, 1),
882+
BPF_EXIT_INSN(),
883+
},
884+
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
885+
.result = ACCEPT,
886+
.retval = 1,
887+
},

0 commit comments

Comments
 (0)