Skip to content

Commit b7b7c66

Browse files
mannkafaiKernel Patches Daemon
authored andcommitted
selftests/bpf: Range analysis test case for JEQ
This patch adds coverage for the warning detected by syzkaller and fixed in the previous patch. Without the previous patch, this test fails with: verifier bug: REG INVARIANTS VIOLATION (true_reg1): range bounds violation u64=[0xffffffffffffff01, 0xffffffffffffff00] s64=[0xffffffffffffff01, 0xffffffffffffff00] u32=[0xffffff01, 0xffffff00] s32=[0xffffff00, 0xffffff00] var_off=(0xffffffffffffff00, 0x0) verifier bug: REG INVARIANTS VIOLATION (true_reg2): range bounds violation u64=[0xffffffffffffff01, 0xffffffffffffff00] s64=[0xffffffffffffff01, 0xffffffffffffff00] u32=[0xffffff01, 0xffffff00] s32=[0xffffff01, 0xffffff00] var_off=(0xffffffffffffff00, 0x0) Signed-off-by: KaFai Wan <[email protected]>
1 parent 1df579f commit b7b7c66

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,29 @@ l0_%=: r0 = 0; \
15501550
: __clobber_all);
15511551
}
15521552

1553+
SEC("socket")
1554+
__description("dead branch on jeq, does not result in invariants violation error")
1555+
__success __log_level(2)
1556+
__retval(0) __flag(BPF_F_TEST_REG_INVARIANTS)
1557+
__naked void jeq_range_analysis(void)
1558+
{
1559+
asm volatile (" \
1560+
call %[bpf_get_prandom_u32]; \
1561+
r6 = r0; \
1562+
r6 &= 0xFFFFFFFFFFFFFFF0; \
1563+
r7 = r0; \
1564+
r7 &= 0x07; \
1565+
r7 -= 0xFF; \
1566+
if r6 == r7 goto l1_%=; \
1567+
l0_%=: r0 = 0; \
1568+
exit; \
1569+
l1_%=: r0 = 1; \
1570+
exit; \
1571+
" :
1572+
: __imm(bpf_get_prandom_u32)
1573+
: __clobber_all);
1574+
}
1575+
15531576
/* This test covers the bounds deduction on 64bits when the s64 and u64 ranges
15541577
* overlap on the negative side. At instruction 7, the ranges look as follows:
15551578
*

0 commit comments

Comments
 (0)