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

bpf: change bpf_probe_write_user to bpf_trace_printk in test_verifier

There are four tests in test_verifier using bpf_probe_write_user
helper. These four tests will emit the following kernel messages
[ 12.974753] test_verifier[220] is installing a program with bpf_probe_write_user
helper that may corrupt user memory!
[ 12.979285] test_verifier[220] is installing a program with bpf_probe_write_user
helper that may corrupt user memory!
......

This may confuse certain users. This patch replaces bpf_probe_write_user
with bpf_trace_printk. The test_verifier already uses bpf_trace_printk
earlier in the test and a trace_printk warning message has been printed.
So this patch does not emit any more kernel messages.

Fixes: b6ff63911232 ("bpf: fix and add test cases for ARG_CONST_SIZE_OR_ZERO semantics change")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Yonghong Song and committed by
Daniel Borkmann
f1a8b8e3 6547f424

+16 -23
+16 -23
tools/testing/selftests/bpf/test_verifier.c
··· 4377 4377 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), 4378 4378 BPF_LD_MAP_FD(BPF_REG_1, 0), 4379 4379 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), 4380 - BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4), 4381 - BPF_MOV64_IMM(BPF_REG_1, 0), 4382 - BPF_MOV64_REG(BPF_REG_2, BPF_REG_0), 4383 - BPF_MOV64_IMM(BPF_REG_3, 0), 4384 - BPF_EMIT_CALL(BPF_FUNC_probe_write_user), 4380 + BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 3), 4381 + BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 4382 + BPF_MOV64_IMM(BPF_REG_2, 0), 4383 + BPF_EMIT_CALL(BPF_FUNC_trace_printk), 4385 4384 BPF_EXIT_INSN(), 4386 4385 }, 4387 4386 .fixup_map2 = { 3 }, ··· 4480 4481 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), 4481 4482 BPF_LD_MAP_FD(BPF_REG_1, 0), 4482 4483 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), 4483 - BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5), 4484 + BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4), 4484 4485 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 4485 4486 BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 4486 4487 offsetof(struct test_val, foo)), 4487 - BPF_MOV64_REG(BPF_REG_2, BPF_REG_1), 4488 - BPF_MOV64_IMM(BPF_REG_1, 0), 4489 - BPF_MOV64_IMM(BPF_REG_3, 0), 4490 - BPF_EMIT_CALL(BPF_FUNC_probe_write_user), 4488 + BPF_MOV64_IMM(BPF_REG_2, 0), 4489 + BPF_EMIT_CALL(BPF_FUNC_trace_printk), 4491 4490 BPF_EXIT_INSN(), 4492 4491 }, 4493 4492 .fixup_map2 = { 3 }, ··· 4615 4618 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), 4616 4619 BPF_LD_MAP_FD(BPF_REG_1, 0), 4617 4620 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), 4618 - BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6), 4621 + BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5), 4619 4622 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 4620 4623 BPF_MOV64_IMM(BPF_REG_3, 0), 4621 4624 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3), 4622 - BPF_MOV64_REG(BPF_REG_2, BPF_REG_1), 4623 - BPF_MOV64_IMM(BPF_REG_1, 0), 4624 - BPF_MOV64_IMM(BPF_REG_3, 0), 4625 - BPF_EMIT_CALL(BPF_FUNC_probe_write_user), 4625 + BPF_MOV64_IMM(BPF_REG_2, 0), 4626 + BPF_EMIT_CALL(BPF_FUNC_trace_printk), 4626 4627 BPF_EXIT_INSN(), 4627 4628 }, 4628 4629 .fixup_map2 = { 3 }, 4629 - .errstr = "R2 min value is outside of the array range", 4630 + .errstr = "R1 min value is outside of the array range", 4630 4631 .result = REJECT, 4631 4632 .prog_type = BPF_PROG_TYPE_TRACEPOINT, 4632 4633 }, ··· 4755 4760 BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), 4756 4761 BPF_LD_MAP_FD(BPF_REG_1, 0), 4757 4762 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), 4758 - BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7), 4763 + BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6), 4759 4764 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), 4760 4765 BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0), 4761 4766 BPF_JMP_IMM(BPF_JGT, BPF_REG_3, 4762 - offsetof(struct test_val, foo), 4), 4767 + offsetof(struct test_val, foo), 3), 4763 4768 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3), 4764 - BPF_MOV64_REG(BPF_REG_2, BPF_REG_1), 4765 - BPF_MOV64_IMM(BPF_REG_1, 0), 4766 - BPF_MOV64_IMM(BPF_REG_3, 0), 4767 - BPF_EMIT_CALL(BPF_FUNC_probe_write_user), 4769 + BPF_MOV64_IMM(BPF_REG_2, 0), 4770 + BPF_EMIT_CALL(BPF_FUNC_trace_printk), 4768 4771 BPF_EXIT_INSN(), 4769 4772 }, 4770 4773 .fixup_map2 = { 3 }, 4771 - .errstr = "R2 min value is outside of the array range", 4774 + .errstr = "R1 min value is outside of the array range", 4772 4775 .result = REJECT, 4773 4776 .prog_type = BPF_PROG_TYPE_TRACEPOINT, 4774 4777 },