Skip to content

Commit f1a8b8e

Browse files
yonghong-songborkmann
authored andcommitted
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: b6ff639 ("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>
1 parent 6547f42 commit f1a8b8e

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,11 +4377,10 @@ static struct bpf_test tests[] = {
43774377
BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
43784378
BPF_LD_MAP_FD(BPF_REG_1, 0),
43794379
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),
43854384
BPF_EXIT_INSN(),
43864385
},
43874386
.fixup_map2 = { 3 },
@@ -4481,14 +4480,12 @@ static struct bpf_test tests[] = {
44814480
BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
44824481
BPF_LD_MAP_FD(BPF_REG_1, 0),
44834482
BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
4484-
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
4483+
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4),
44854484
BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
44864485
BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
44874486
offsetof(struct test_val, foo)),
4488-
BPF_MOV64_REG(BPF_REG_2, BPF_REG_1),
4489-
BPF_MOV64_IMM(BPF_REG_1, 0),
4490-
BPF_MOV64_IMM(BPF_REG_3, 0),
4491-
BPF_EMIT_CALL(BPF_FUNC_probe_write_user),
4487+
BPF_MOV64_IMM(BPF_REG_2, 0),
4488+
BPF_EMIT_CALL(BPF_FUNC_trace_printk),
44924489
BPF_EXIT_INSN(),
44934490
},
44944491
.fixup_map2 = { 3 },
@@ -4618,18 +4615,16 @@ static struct bpf_test tests[] = {
46184615
BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
46194616
BPF_LD_MAP_FD(BPF_REG_1, 0),
46204617
BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
4621-
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
4618+
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
46224619
BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
46234620
BPF_MOV64_IMM(BPF_REG_3, 0),
46244621
BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
4625-
BPF_MOV64_REG(BPF_REG_2, BPF_REG_1),
4626-
BPF_MOV64_IMM(BPF_REG_1, 0),
4627-
BPF_MOV64_IMM(BPF_REG_3, 0),
4628-
BPF_EMIT_CALL(BPF_FUNC_probe_write_user),
4622+
BPF_MOV64_IMM(BPF_REG_2, 0),
4623+
BPF_EMIT_CALL(BPF_FUNC_trace_printk),
46294624
BPF_EXIT_INSN(),
46304625
},
46314626
.fixup_map2 = { 3 },
4632-
.errstr = "R2 min value is outside of the array range",
4627+
.errstr = "R1 min value is outside of the array range",
46334628
.result = REJECT,
46344629
.prog_type = BPF_PROG_TYPE_TRACEPOINT,
46354630
},
@@ -4760,20 +4755,18 @@ static struct bpf_test tests[] = {
47604755
BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
47614756
BPF_LD_MAP_FD(BPF_REG_1, 0),
47624757
BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
4763-
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
4758+
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
47644759
BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
47654760
BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0),
47664761
BPF_JMP_IMM(BPF_JGT, BPF_REG_3,
4767-
offsetof(struct test_val, foo), 4),
4762+
offsetof(struct test_val, foo), 3),
47684763
BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
4769-
BPF_MOV64_REG(BPF_REG_2, BPF_REG_1),
4770-
BPF_MOV64_IMM(BPF_REG_1, 0),
4771-
BPF_MOV64_IMM(BPF_REG_3, 0),
4772-
BPF_EMIT_CALL(BPF_FUNC_probe_write_user),
4764+
BPF_MOV64_IMM(BPF_REG_2, 0),
4765+
BPF_EMIT_CALL(BPF_FUNC_trace_printk),
47734766
BPF_EXIT_INSN(),
47744767
},
47754768
.fixup_map2 = { 3 },
4776-
.errstr = "R2 min value is outside of the array range",
4769+
.errstr = "R1 min value is outside of the array range",
47774770
.result = REJECT,
47784771
.prog_type = BPF_PROG_TYPE_TRACEPOINT,
47794772
},

0 commit comments

Comments
 (0)