Skip to content

Commit a1b5da8

Browse files
mannkafaiKernel Patches Daemon
authored andcommitted
selftests/bpf: Add test for conditional jumps on same register
Add a test case to verify that conditional jumps on the same register (e.g., JGT r0 > r0) do not trigger verifier BUG warnings when the register holds a scalar with range. Signed-off-by: KaFai Wan <[email protected]>
1 parent 01c324b commit a1b5da8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tools/testing/selftests/bpf/progs/verifier_bounds.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,4 +1709,21 @@ __naked void jeq_disagreeing_tnums(void *ctx)
17091709
: __clobber_all);
17101710
}
17111711

1712+
SEC("socket")
1713+
__description("JGT on same register")
1714+
__success __log_level(2)
1715+
__naked void jgt_same_register(void *ctx)
1716+
{
1717+
asm volatile(" \
1718+
call %[bpf_get_prandom_u32]; \
1719+
w8 = 0x80000000; \
1720+
r0 &= r8; \
1721+
if r0 > r0 goto +1; \
1722+
call %[bpf_get_prandom_u32]; \
1723+
exit; \
1724+
" :
1725+
: __imm(bpf_get_prandom_u32)
1726+
: __clobber_all);
1727+
}
1728+
17121729
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)