Skip to content

Commit 99fca41

Browse files
jrfastabkernel-patches-bot
authored andcommitted
bpf: Add AND verifier test case where 32bit and 64bit bounds differ
If we AND two values together that are known in the 32bit subregs, but not known in the 64bit registers we rely on the tnum value to report the 32bit subreg is known. And do not use mark_reg_known() directly from scalar32_min_max_and() Add an AND test to cover the case with known 32bit subreg, but unknown 64bit reg. Signed-off-by: John Fastabend <[email protected]>
1 parent 589ede7 commit 99fca41

File tree

1 file changed

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

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,19 @@
4848
.result = REJECT,
4949
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
5050
},
51+
{
52+
"check known subreg with unknown reg",
53+
.insns = {
54+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_get_prandom_u32),
55+
BPF_ALU64_IMM(BPF_LSH, BPF_REG_0, 32),
56+
BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
57+
BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xFFFF1234),
58+
/* Upper bits are unknown but AND above masks out 1 zero'ing lower bits */
59+
BPF_JMP32_IMM(BPF_JLT, BPF_REG_0, 1, 1),
60+
BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_1, 512),
61+
BPF_MOV64_IMM(BPF_REG_0, 0),
62+
BPF_EXIT_INSN(),
63+
},
64+
.result = ACCEPT,
65+
.retval = 0
66+
},

0 commit comments

Comments
 (0)