Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add regression test for pruning fix

Add a test to ensure we do mark_chain_precision for the argument type
ARG_CONST_ALLOC_SIZE_OR_ZERO. For other argument types, this was already
done, but propagation for missing for this case. Without the fix, this
test case loads successfully.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20220823185500.467-1-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Kumar Kartikeya Dwivedi and committed by
Alexei Starovoitov
1800b2ac 2fc31465

+25
+25
tools/testing/selftests/bpf/verifier/precise.c
··· 192 192 .result = VERBOSE_ACCEPT, 193 193 .retval = -1, 194 194 }, 195 + { 196 + "precise: mark_chain_precision for ARG_CONST_ALLOC_SIZE_OR_ZERO", 197 + .insns = { 198 + BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1, offsetof(struct xdp_md, ingress_ifindex)), 199 + BPF_LD_MAP_FD(BPF_REG_6, 0), 200 + BPF_MOV64_REG(BPF_REG_1, BPF_REG_6), 201 + BPF_MOV64_IMM(BPF_REG_2, 1), 202 + BPF_MOV64_IMM(BPF_REG_3, 0), 203 + BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 0, 1), 204 + BPF_MOV64_IMM(BPF_REG_2, 0x1000), 205 + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_ringbuf_reserve), 206 + BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1), 207 + BPF_EXIT_INSN(), 208 + BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 209 + BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_0, 42), 210 + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_ringbuf_submit), 211 + BPF_MOV64_IMM(BPF_REG_0, 0), 212 + BPF_EXIT_INSN(), 213 + }, 214 + .fixup_map_ringbuf = { 1 }, 215 + .prog_type = BPF_PROG_TYPE_XDP, 216 + .flags = BPF_F_TEST_STATE_FREQ, 217 + .errstr = "invalid access to memory, mem_size=1 off=42 size=8", 218 + .result = REJECT, 219 + },