Skip to content

Commit e23967a

Browse files
borkmanngregkh
authored andcommitted
bpf: Update selftests to reflect new error states
commit d7a5091 upstream. Update various selftest error messages: * The 'Rx tried to sub from different maps, paths, or prohibited types' is reworked into more specific/differentiated error messages for better guidance. * The change into 'value -4294967168 makes map_value pointer be out of bounds' is due to moving the mixed bounds check into the speculation handling and thus occuring slightly later than above mentioned sanity check. * The change into 'math between map_value pointer and register with unbounded min value' is similarly due to register sanity check coming before the mixed bounds check. * The case of 'map access: known scalar += value_ptr from different maps' now loads fine given masks are the same from the different paths (despite max map value size being different). Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Alexei Starovoitov <ast@kernel.org> [fllinden@amazon - skip bounds.c test mods, they won't change error msg on 5.4] Signed-off-by: Frank van der Linden <fllinden@amazon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ef4e68f commit e23967a

4 files changed

Lines changed: 14 additions & 28 deletions

File tree

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
77
BPF_EXIT_INSN(),
88
},
9-
.errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types",
9+
.errstr_unpriv = "R1 has pointer with unsupported alu operation",
1010
.errstr = "R0 tried to subtract pointer from scalar",
1111
.result = REJECT,
1212
},
@@ -21,7 +21,7 @@
2121
BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_0),
2222
BPF_EXIT_INSN(),
2323
},
24-
.errstr_unpriv = "R1 tried to sub from different maps, paths, or prohibited types",
24+
.errstr_unpriv = "R1 has pointer with unsupported alu operation",
2525
.result_unpriv = REJECT,
2626
.result = ACCEPT,
2727
.retval = 1,
@@ -34,22 +34,23 @@
3434
BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
3535
BPF_EXIT_INSN(),
3636
},
37-
.errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types",
37+
.errstr_unpriv = "R1 has pointer with unsupported alu operation",
3838
.errstr = "R0 tried to subtract pointer from scalar",
3939
.result = REJECT,
4040
},
4141
{
4242
"check deducing bounds from const, 4",
4343
.insns = {
44+
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
4445
BPF_MOV64_IMM(BPF_REG_0, 0),
4546
BPF_JMP_IMM(BPF_JSLE, BPF_REG_0, 0, 1),
4647
BPF_EXIT_INSN(),
4748
BPF_JMP_IMM(BPF_JSGE, BPF_REG_0, 0, 1),
4849
BPF_EXIT_INSN(),
49-
BPF_ALU64_REG(BPF_SUB, BPF_REG_1, BPF_REG_0),
50+
BPF_ALU64_REG(BPF_SUB, BPF_REG_6, BPF_REG_0),
5051
BPF_EXIT_INSN(),
5152
},
52-
.errstr_unpriv = "R1 tried to sub from different maps, paths, or prohibited types",
53+
.errstr_unpriv = "R6 has pointer with unsupported alu operation",
5354
.result_unpriv = REJECT,
5455
.result = ACCEPT,
5556
},
@@ -61,7 +62,7 @@
6162
BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
6263
BPF_EXIT_INSN(),
6364
},
64-
.errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types",
65+
.errstr_unpriv = "R1 has pointer with unsupported alu operation",
6566
.errstr = "R0 tried to subtract pointer from scalar",
6667
.result = REJECT,
6768
},
@@ -74,7 +75,7 @@
7475
BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
7576
BPF_EXIT_INSN(),
7677
},
77-
.errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types",
78+
.errstr_unpriv = "R1 has pointer with unsupported alu operation",
7879
.errstr = "R0 tried to subtract pointer from scalar",
7980
.result = REJECT,
8081
},
@@ -88,7 +89,7 @@
8889
offsetof(struct __sk_buff, mark)),
8990
BPF_EXIT_INSN(),
9091
},
91-
.errstr_unpriv = "R1 tried to sub from different maps, paths, or prohibited types",
92+
.errstr_unpriv = "R1 has pointer with unsupported alu operation",
9293
.errstr = "dereference of modified ctx ptr",
9394
.result = REJECT,
9495
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
@@ -103,7 +104,7 @@
103104
offsetof(struct __sk_buff, mark)),
104105
BPF_EXIT_INSN(),
105106
},
106-
.errstr_unpriv = "R1 tried to add from different maps, paths, or prohibited types",
107+
.errstr_unpriv = "R1 has pointer with unsupported alu operation",
107108
.errstr = "dereference of modified ctx ptr",
108109
.result = REJECT,
109110
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
@@ -116,7 +117,7 @@
116117
BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1),
117118
BPF_EXIT_INSN(),
118119
},
119-
.errstr_unpriv = "R0 tried to sub from different maps, paths, or prohibited types",
120+
.errstr_unpriv = "R1 has pointer with unsupported alu operation",
120121
.errstr = "R0 tried to subtract pointer from scalar",
121122
.result = REJECT,
122123
},

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
},
2020
.fixup_map_hash_8b = { 3 },
2121
.errstr = "unbounded min value",
22-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
2322
.result = REJECT,
2423
},
2524
{
@@ -43,7 +42,6 @@
4342
},
4443
.fixup_map_hash_8b = { 3 },
4544
.errstr = "unbounded min value",
46-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
4745
.result = REJECT,
4846
},
4947
{
@@ -69,7 +67,6 @@
6967
},
7068
.fixup_map_hash_8b = { 3 },
7169
.errstr = "unbounded min value",
72-
.errstr_unpriv = "R8 has unknown scalar with mixed signed bounds",
7370
.result = REJECT,
7471
},
7572
{
@@ -94,7 +91,6 @@
9491
},
9592
.fixup_map_hash_8b = { 3 },
9693
.errstr = "unbounded min value",
97-
.errstr_unpriv = "R8 has unknown scalar with mixed signed bounds",
9894
.result = REJECT,
9995
},
10096
{
@@ -141,7 +137,6 @@
141137
},
142138
.fixup_map_hash_8b = { 3 },
143139
.errstr = "unbounded min value",
144-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
145140
.result = REJECT,
146141
},
147142
{
@@ -210,7 +205,6 @@
210205
},
211206
.fixup_map_hash_8b = { 3 },
212207
.errstr = "unbounded min value",
213-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
214208
.result = REJECT,
215209
},
216210
{
@@ -260,7 +254,6 @@
260254
},
261255
.fixup_map_hash_8b = { 3 },
262256
.errstr = "unbounded min value",
263-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
264257
.result = REJECT,
265258
},
266259
{
@@ -287,7 +280,6 @@
287280
},
288281
.fixup_map_hash_8b = { 3 },
289282
.errstr = "unbounded min value",
290-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
291283
.result = REJECT,
292284
},
293285
{
@@ -313,7 +305,6 @@
313305
},
314306
.fixup_map_hash_8b = { 3 },
315307
.errstr = "unbounded min value",
316-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
317308
.result = REJECT,
318309
},
319310
{
@@ -342,7 +333,6 @@
342333
},
343334
.fixup_map_hash_8b = { 3 },
344335
.errstr = "unbounded min value",
345-
.errstr_unpriv = "R7 has unknown scalar with mixed signed bounds",
346336
.result = REJECT,
347337
},
348338
{
@@ -372,7 +362,6 @@
372362
},
373363
.fixup_map_hash_8b = { 4 },
374364
.errstr = "unbounded min value",
375-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
376365
.result = REJECT,
377366
},
378367
{
@@ -400,7 +389,5 @@
400389
},
401390
.fixup_map_hash_8b = { 3 },
402391
.errstr = "unbounded min value",
403-
.errstr_unpriv = "R1 has unknown scalar with mixed signed bounds",
404392
.result = REJECT,
405-
.result_unpriv = REJECT,
406393
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@
503503
BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, -8),
504504
BPF_EXIT_INSN(),
505505
},
506-
.errstr_unpriv = "R1 tried to add from different maps, paths, or prohibited types",
506+
.errstr_unpriv = "R1 stack pointer arithmetic goes out of range",
507507
.result_unpriv = REJECT,
508508
.result = ACCEPT,
509509
},

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
.fixup_map_hash_16b = { 5 },
2222
.fixup_map_array_48b = { 8 },
2323
.result = ACCEPT,
24-
.result_unpriv = REJECT,
25-
.errstr_unpriv = "R1 tried to add from different maps",
2624
.retval = 1,
2725
},
2826
{
@@ -122,7 +120,7 @@
122120
.fixup_map_array_48b = { 1 },
123121
.result = ACCEPT,
124122
.result_unpriv = REJECT,
125-
.errstr_unpriv = "R2 tried to add from different pointers or scalars",
123+
.errstr_unpriv = "R2 tried to add from different maps, paths or scalars",
126124
.retval = 0,
127125
},
128126
{
@@ -169,7 +167,7 @@
169167
.fixup_map_array_48b = { 1 },
170168
.result = ACCEPT,
171169
.result_unpriv = REJECT,
172-
.errstr_unpriv = "R2 tried to add from different maps, paths, or prohibited types",
170+
.errstr_unpriv = "R2 tried to add from different maps, paths or scalars",
173171
.retval = 0,
174172
},
175173
{

0 commit comments

Comments
 (0)