Skip to content

Commit 2e7239e

Browse files
mannkafaiKernel Patches Daemon
authored andcommitted
selftests/bpf: Add test for BPF_JGT on same register
Add a test to verify that conditional jumps using the BPF_JGT opcode on the same register (e.g., "if r0 > r0") do not trigger verifier BUG warnings when the register contains a scalar value with range information. Signed-off-by: KaFai Wan <[email protected]>
1 parent 574dd1b commit 2e7239e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,4 +1709,22 @@ __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+
__retval(0)
1716+
__naked void jgt_same_register(void *ctx)
1717+
{
1718+
asm volatile(" \
1719+
call %[bpf_get_prandom_u32]; \
1720+
w8 = 0x80000000; \
1721+
r0 &= r8; \
1722+
if r0 > r0 goto +1; \
1723+
r0 = 0; \
1724+
exit; \
1725+
" :
1726+
: __imm(bpf_get_prandom_u32)
1727+
: __clobber_all);
1728+
}
1729+
17121730
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)