Skip to content

Commit 973377f

Browse files
committed
bpf, selftests: Adjust few selftest outcomes wrt unreachable code
In almost all cases from test_verifier that have been changed in here, we've had an unreachable path with a load from a register which has an invalid address on purpose. This was basically to make sure that we never walk this path and to have the verifier complain if it would otherwise. Change it to match on the right error for unprivileged given we now test these paths under speculative execution. There's one case where we match on exact # of insns_processed. Due to the extra path, this will of course mismatch on unprivileged. Thus, restrict the test->insn_processed check to privileged-only. In one other case, we result in a 'pointer comparison prohibited' error. This is similarly due to verifying an 'invalid' branch where we end up with a value pointer on one side of the comparison. Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: John Fastabend <[email protected]> Acked-by: Alexei Starovoitov <[email protected]>
1 parent 9183671 commit 973377f

File tree

8 files changed

+53
-8
lines changed

8 files changed

+53
-8
lines changed

tools/testing/selftests/bpf/test_verifier.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
11471147
}
11481148
}
11491149

1150-
if (test->insn_processed) {
1150+
if (!unpriv && test->insn_processed) {
11511151
uint32_t insn_processed;
11521152
char *proc;
11531153

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

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
BPF_MOV64_IMM(BPF_REG_0, 0),
6262
BPF_EXIT_INSN(),
6363
},
64+
.errstr_unpriv = "R1 !read_ok",
65+
.result_unpriv = REJECT,
6466
.result = ACCEPT,
6567
.retval = 0
6668
},

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

+14
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@
508508
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, -1),
509509
BPF_EXIT_INSN(),
510510
},
511+
.errstr_unpriv = "R0 invalid mem access 'inv'",
512+
.result_unpriv = REJECT,
511513
.result = ACCEPT
512514
},
513515
{
@@ -528,6 +530,8 @@
528530
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, -1),
529531
BPF_EXIT_INSN(),
530532
},
533+
.errstr_unpriv = "R0 invalid mem access 'inv'",
534+
.result_unpriv = REJECT,
531535
.result = ACCEPT
532536
},
533537
{
@@ -569,6 +573,8 @@
569573
BPF_MOV64_IMM(BPF_REG_0, 0),
570574
BPF_EXIT_INSN(),
571575
},
576+
.errstr_unpriv = "R0 min value is outside of the allowed memory range",
577+
.result_unpriv = REJECT,
572578
.fixup_map_hash_8b = { 3 },
573579
.result = ACCEPT,
574580
},
@@ -589,6 +595,8 @@
589595
BPF_MOV64_IMM(BPF_REG_0, 0),
590596
BPF_EXIT_INSN(),
591597
},
598+
.errstr_unpriv = "R0 min value is outside of the allowed memory range",
599+
.result_unpriv = REJECT,
592600
.fixup_map_hash_8b = { 3 },
593601
.result = ACCEPT,
594602
},
@@ -609,6 +617,8 @@
609617
BPF_MOV64_IMM(BPF_REG_0, 0),
610618
BPF_EXIT_INSN(),
611619
},
620+
.errstr_unpriv = "R0 min value is outside of the allowed memory range",
621+
.result_unpriv = REJECT,
612622
.fixup_map_hash_8b = { 3 },
613623
.result = ACCEPT,
614624
},
@@ -674,6 +684,8 @@
674684
BPF_MOV64_IMM(BPF_REG_0, 0),
675685
BPF_EXIT_INSN(),
676686
},
687+
.errstr_unpriv = "R0 min value is outside of the allowed memory range",
688+
.result_unpriv = REJECT,
677689
.fixup_map_hash_8b = { 3 },
678690
.result = ACCEPT,
679691
},
@@ -695,6 +707,8 @@
695707
BPF_MOV64_IMM(BPF_REG_0, 0),
696708
BPF_EXIT_INSN(),
697709
},
710+
.errstr_unpriv = "R0 min value is outside of the allowed memory range",
711+
.result_unpriv = REJECT,
698712
.fixup_map_hash_8b = { 3 },
699713
.result = ACCEPT,
700714
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 10, -4),
99
BPF_EXIT_INSN(),
1010
},
11+
.errstr_unpriv = "R9 !read_ok",
12+
.result_unpriv = REJECT,
1113
.result = ACCEPT,
1214
.retval = 7,
1315
},

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

+22
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
8888
BPF_EXIT_INSN(),
8989
},
90+
.errstr_unpriv = "R9 !read_ok",
91+
.result_unpriv = REJECT,
9092
.result = ACCEPT,
9193
},
9294
{
@@ -150,6 +152,8 @@
150152
BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
151153
BPF_EXIT_INSN(),
152154
},
155+
.errstr_unpriv = "R9 !read_ok",
156+
.result_unpriv = REJECT,
153157
.result = ACCEPT,
154158
},
155159
{
@@ -213,6 +217,8 @@
213217
BPF_LDX_MEM(BPF_B, BPF_REG_8, BPF_REG_9, 0),
214218
BPF_EXIT_INSN(),
215219
},
220+
.errstr_unpriv = "R9 !read_ok",
221+
.result_unpriv = REJECT,
216222
.result = ACCEPT,
217223
},
218224
{
@@ -280,6 +286,8 @@
280286
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0),
281287
BPF_EXIT_INSN(),
282288
},
289+
.errstr_unpriv = "R0 invalid mem access 'inv'",
290+
.result_unpriv = REJECT,
283291
.result = ACCEPT,
284292
.retval = 2,
285293
},
@@ -348,6 +356,8 @@
348356
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0),
349357
BPF_EXIT_INSN(),
350358
},
359+
.errstr_unpriv = "R0 invalid mem access 'inv'",
360+
.result_unpriv = REJECT,
351361
.result = ACCEPT,
352362
.retval = 2,
353363
},
@@ -416,6 +426,8 @@
416426
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0),
417427
BPF_EXIT_INSN(),
418428
},
429+
.errstr_unpriv = "R0 invalid mem access 'inv'",
430+
.result_unpriv = REJECT,
419431
.result = ACCEPT,
420432
.retval = 2,
421433
},
@@ -484,6 +496,8 @@
484496
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0),
485497
BPF_EXIT_INSN(),
486498
},
499+
.errstr_unpriv = "R0 invalid mem access 'inv'",
500+
.result_unpriv = REJECT,
487501
.result = ACCEPT,
488502
.retval = 2,
489503
},
@@ -552,6 +566,8 @@
552566
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0),
553567
BPF_EXIT_INSN(),
554568
},
569+
.errstr_unpriv = "R0 invalid mem access 'inv'",
570+
.result_unpriv = REJECT,
555571
.result = ACCEPT,
556572
.retval = 2,
557573
},
@@ -620,6 +636,8 @@
620636
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0),
621637
BPF_EXIT_INSN(),
622638
},
639+
.errstr_unpriv = "R0 invalid mem access 'inv'",
640+
.result_unpriv = REJECT,
623641
.result = ACCEPT,
624642
.retval = 2,
625643
},
@@ -688,6 +706,8 @@
688706
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0),
689707
BPF_EXIT_INSN(),
690708
},
709+
.errstr_unpriv = "R0 invalid mem access 'inv'",
710+
.result_unpriv = REJECT,
691711
.result = ACCEPT,
692712
.retval = 2,
693713
},
@@ -756,6 +776,8 @@
756776
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0),
757777
BPF_EXIT_INSN(),
758778
},
779+
.errstr_unpriv = "R0 invalid mem access 'inv'",
780+
.result_unpriv = REJECT,
759781
.result = ACCEPT,
760782
.retval = 2,
761783
},

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
BPF_EXIT_INSN(),
8383
},
8484
.prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
85-
.retval_unpriv = 1,
86-
.result_unpriv = ACCEPT,
85+
.errstr_unpriv = "R9 !read_ok",
86+
.result_unpriv = REJECT,
8787
.retval = 1,
8888
.result = ACCEPT,
8989
},
@@ -141,7 +141,8 @@
141141
BPF_EXIT_INSN(),
142142
},
143143
.prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
144-
.result_unpriv = ACCEPT,
144+
.errstr_unpriv = "R9 !read_ok",
145+
.result_unpriv = REJECT,
145146
.result = ACCEPT,
146147
},
147148
{
@@ -162,6 +163,7 @@
162163
BPF_EXIT_INSN(),
163164
},
164165
.prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
165-
.result_unpriv = ACCEPT,
166+
.errstr_unpriv = "R9 !read_ok",
167+
.result_unpriv = REJECT,
166168
.result = ACCEPT,
167169
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@
420420
BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_7, 0),
421421
BPF_EXIT_INSN(),
422422
},
423+
.errstr_unpriv = "R7 invalid mem access 'inv'",
424+
.result_unpriv = REJECT,
423425
.result = ACCEPT,
424426
.retval = 0,
425427
},

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
.fixup_map_array_48b = { 1 },
121121
.result = ACCEPT,
122122
.result_unpriv = REJECT,
123-
.errstr_unpriv = "R2 tried to add from different maps, paths or scalars",
123+
.errstr_unpriv = "R2 pointer comparison prohibited",
124124
.retval = 0,
125125
},
126126
{
@@ -159,15 +159,16 @@
159159
BPF_MOV64_IMM(BPF_REG_0, 0),
160160
BPF_EXIT_INSN(),
161161
// fake-dead code; targeted from branch A to
162-
// prevent dead code sanitization
162+
// prevent dead code sanitization, rejected
163+
// via branch B however
163164
BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_0, 0),
164165
BPF_MOV64_IMM(BPF_REG_0, 0),
165166
BPF_EXIT_INSN(),
166167
},
167168
.fixup_map_array_48b = { 1 },
168169
.result = ACCEPT,
169170
.result_unpriv = REJECT,
170-
.errstr_unpriv = "R2 tried to add from different maps, paths or scalars",
171+
.errstr_unpriv = "R0 invalid mem access 'inv'",
171172
.retval = 0,
172173
},
173174
{

0 commit comments

Comments
 (0)