Skip to content

Commit c8e7a4b

Browse files
luisgerhorstKernel Patches Daemon
authored andcommitted
selftests/bpf: Add missing SPEC_V1-ifdefs
For errors that only occur if bpf_jit_bypass_spec_v1() is set (e.g., on LoongArch), add the missing '#ifdef SPEC_V1' to the selftests. Fixes: 03c68a0 ("bpf, arm64, powerpc: Add bpf_jit_bypass_spec_v1/v4()") Reported-by: Hengqi Chen <[email protected]> Closes: https://lore.kernel.org/bpf/CAEyhmHTvj4cDRfu1FXSEXmdCqyWfs3ehw5gtB9qJCrThuUy2Kw@mail.gmail.com/ Signed-off-by: Luis Gerhorst <[email protected]>
1 parent 4f02588 commit c8e7a4b

File tree

8 files changed

+100
-22
lines changed

8 files changed

+100
-22
lines changed

tools/testing/selftests/bpf/progs/verifier_bounds.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ SEC("socket")
4848
__description("subtraction bounds (map value) variant 2")
4949
__failure
5050
__msg("R0 min value is negative, either use unsigned index or do a if (index >=0) check.")
51+
#ifdef SPEC_V1
5152
__msg_unpriv("R0 pointer arithmetic of map value goes out of range, prohibited for !root")
53+
#endif
5254
__naked void bounds_map_value_variant_2(void)
5355
{
5456
/* unpriv: nospec inserted to prevent "R1 has unknown scalar with mixed
@@ -545,7 +547,9 @@ l1_%=: exit; \
545547
SEC("socket")
546548
__description("bounds check map access with off+size signed 32bit overflow. test2")
547549
__failure __msg("pointer offset 1073741822")
550+
#ifdef SPEC_V1
548551
__msg_unpriv("R0 pointer arithmetic of map value goes out of range")
552+
#endif
549553
__naked void size_signed_32bit_overflow_test2(void)
550554
{
551555
asm volatile (" \
@@ -572,7 +576,9 @@ l1_%=: exit; \
572576
SEC("socket")
573577
__description("bounds check map access with off+size signed 32bit overflow. test3")
574578
__failure __msg("pointer offset -1073741822")
579+
#ifdef SPEC_V1
575580
__msg_unpriv("R0 pointer arithmetic of map value goes out of range")
581+
#endif
576582
__naked void size_signed_32bit_overflow_test3(void)
577583
{
578584
asm volatile (" \

tools/testing/selftests/bpf/progs/verifier_direct_stack_access_wraparound.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ __naked void with_32_bit_wraparound_test2(void)
4040
SEC("socket")
4141
__description("direct stack access with 32-bit wraparound. test3")
4242
__failure __msg("fp pointer offset 1073741822")
43+
#ifdef SPEC_V1
4344
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
45+
#endif
4446
__naked void with_32_bit_wraparound_test3(void)
4547
{
4648
asm volatile (" \

tools/testing/selftests/bpf/progs/verifier_map_ptr_mixing.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ void lookup_hash_map_in_map__2(void)
218218

219219
SEC("socket")
220220
__description("cond: two branches returning different map pointers for lookup (tail, tail)")
221-
__success __failure_unpriv __msg_unpriv("tail_call abusing map_ptr")
221+
__success
222+
#ifdef SPEC_V1
223+
__failure_unpriv __msg_unpriv("tail_call abusing map_ptr")
224+
#endif
222225
__retval(42)
223226
__naked void pointers_for_lookup_tail_tail_1(void)
224227
{

tools/testing/selftests/bpf/progs/verifier_runtime_jit.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ l1_%=: call %[bpf_tail_call]; \
252252

253253
SEC("socket")
254254
__description("runtime/jit: tail_call within bounds, different maps, first branch")
255-
__success __failure_unpriv __msg_unpriv("tail_call abusing map_ptr")
255+
__success
256+
#ifdef SPEC_V1
257+
__failure_unpriv __msg_unpriv("tail_call abusing map_ptr")
258+
#endif
256259
__retval(1)
257260
__naked void bounds_different_maps_first_branch(void)
258261
{
@@ -279,7 +282,10 @@ l1_%=: call %[bpf_tail_call]; \
279282

280283
SEC("socket")
281284
__description("runtime/jit: tail_call within bounds, different maps, second branch")
282-
__success __failure_unpriv __msg_unpriv("tail_call abusing map_ptr")
285+
__success
286+
#ifdef SPEC_V1
287+
__failure_unpriv __msg_unpriv("tail_call abusing map_ptr")
288+
#endif
283289
__retval(42)
284290
__naked void bounds_different_maps_second_branch(void)
285291
{
@@ -341,8 +347,10 @@ __naked void negative_index_to_tail_call(void)
341347
SEC("socket")
342348
__description("runtime/jit: pass > 32bit index to tail_call")
343349
__success __success_unpriv __retval(42)
350+
#ifdef SPEC_V1
344351
/* Verifier rewrite for unpriv skips tail call here. */
345352
__retval_unpriv(2)
353+
#endif
346354
__naked void _32bit_index_to_tail_call(void)
347355
{
348356
asm volatile (" \

tools/testing/selftests/bpf/progs/verifier_stack_ptr.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ __naked void load_bad_alignment_on_reg(void)
7070
SEC("socket")
7171
__description("PTR_TO_STACK store/load - out of bounds low")
7272
__failure __msg("invalid write to stack R1 off=-79992 size=8")
73+
#ifdef SPEC_V1
7374
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
75+
#endif
7476
__naked void load_out_of_bounds_low(void)
7577
{
7678
asm volatile (" \
@@ -130,8 +132,10 @@ __naked void to_stack_check_high_2(void)
130132

131133
SEC("socket")
132134
__description("PTR_TO_STACK check high 3")
133-
__success __failure_unpriv
134-
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
135+
__success
136+
#ifdef SPEC_V1
137+
__failure_unpriv __msg_unpriv("R1 stack pointer arithmetic goes out of range")
138+
#endif
135139
__retval(42)
136140
__naked void to_stack_check_high_3(void)
137141
{
@@ -148,7 +152,9 @@ __naked void to_stack_check_high_3(void)
148152
SEC("socket")
149153
__description("PTR_TO_STACK check high 4")
150154
__failure __msg("invalid write to stack R1 off=0 size=1")
155+
#ifdef SPEC_V1
151156
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
157+
#endif
152158
__naked void to_stack_check_high_4(void)
153159
{
154160
asm volatile (" \
@@ -164,7 +170,9 @@ __naked void to_stack_check_high_4(void)
164170
SEC("socket")
165171
__description("PTR_TO_STACK check high 5")
166172
__failure __msg("invalid write to stack R1")
173+
#ifdef SPEC_V1
167174
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
175+
#endif
168176
__naked void to_stack_check_high_5(void)
169177
{
170178
asm volatile (" \
@@ -182,7 +190,9 @@ __naked void to_stack_check_high_5(void)
182190
SEC("socket")
183191
__description("PTR_TO_STACK check high 6")
184192
__failure __msg("invalid write to stack")
193+
#ifdef SPEC_V1
185194
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
195+
#endif
186196
__naked void to_stack_check_high_6(void)
187197
{
188198
asm volatile (" \
@@ -201,7 +211,9 @@ __naked void to_stack_check_high_6(void)
201211
SEC("socket")
202212
__description("PTR_TO_STACK check high 7")
203213
__failure __msg("fp pointer offset")
214+
#ifdef SPEC_V1
204215
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
216+
#endif
205217
__naked void to_stack_check_high_7(void)
206218
{
207219
asm volatile (" \
@@ -235,8 +247,10 @@ __naked void to_stack_check_low_1(void)
235247

236248
SEC("socket")
237249
__description("PTR_TO_STACK check low 2")
238-
__success __failure_unpriv
239-
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
250+
__success
251+
#ifdef SPEC_V1
252+
__failure_unpriv __msg_unpriv("R1 stack pointer arithmetic goes out of range")
253+
#endif
240254
__retval(42)
241255
__naked void to_stack_check_low_2(void)
242256
{
@@ -253,7 +267,9 @@ __naked void to_stack_check_low_2(void)
253267
SEC("socket")
254268
__description("PTR_TO_STACK check low 3")
255269
__failure __msg("invalid write to stack R1 off=-513 size=1")
270+
#ifdef SPEC_V1
256271
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
272+
#endif
257273
__naked void to_stack_check_low_3(void)
258274
{
259275
asm volatile (" \
@@ -287,7 +303,9 @@ __naked void to_stack_check_low_4(void)
287303
SEC("socket")
288304
__description("PTR_TO_STACK check low 5")
289305
__failure __msg("invalid write to stack")
306+
#ifdef SPEC_V1
290307
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
308+
#endif
291309
__naked void to_stack_check_low_5(void)
292310
{
293311
asm volatile (" \
@@ -305,7 +323,9 @@ __naked void to_stack_check_low_5(void)
305323
SEC("socket")
306324
__description("PTR_TO_STACK check low 6")
307325
__failure __msg("invalid write to stack")
326+
#ifdef SPEC_V1
308327
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
328+
#endif
309329
__naked void to_stack_check_low_6(void)
310330
{
311331
asm volatile (" \
@@ -324,7 +344,9 @@ __naked void to_stack_check_low_6(void)
324344
SEC("socket")
325345
__description("PTR_TO_STACK check low 7")
326346
__failure __msg("fp pointer offset")
347+
#ifdef SPEC_V1
327348
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
349+
#endif
328350
__naked void to_stack_check_low_7(void)
329351
{
330352
asm volatile (" \

tools/testing/selftests/bpf/progs/verifier_unpriv.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,10 @@ l0_%=: r0 = 0; \
699699

700700
SEC("socket")
701701
__description("unpriv: adding of fp, reg")
702-
__success __failure_unpriv
703-
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
702+
__success
703+
#ifdef SPEC_V1
704+
__failure_unpriv __msg_unpriv("R1 stack pointer arithmetic goes out of range")
705+
#endif
704706
__retval(0)
705707
__naked void unpriv_adding_of_fp_reg(void)
706708
{
@@ -715,8 +717,10 @@ __naked void unpriv_adding_of_fp_reg(void)
715717

716718
SEC("socket")
717719
__description("unpriv: adding of fp, imm")
718-
__success __failure_unpriv
719-
__msg_unpriv("R1 stack pointer arithmetic goes out of range")
720+
__success
721+
#ifdef SPEC_V1
722+
__failure_unpriv __msg_unpriv("R1 stack pointer arithmetic goes out of range")
723+
#endif
720724
__retval(0)
721725
__naked void unpriv_adding_of_fp_imm(void)
722726
{

tools/testing/selftests/bpf/progs/verifier_value_ptr_arith.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,10 @@ l2_%=: r0 = 1; \
379379

380380
SEC("socket")
381381
__description("map access: value_ptr -= known scalar from different maps")
382-
__success __failure_unpriv
383-
__msg_unpriv("R0 min value is outside of the allowed memory range")
382+
__success
383+
#ifdef SPEC_V1
384+
__failure_unpriv __msg_unpriv("R0 min value is outside of the allowed memory range")
385+
#endif
384386
__retval(1)
385387
__naked void known_scalar_from_different_maps(void)
386388
{
@@ -669,8 +671,11 @@ __naked void alu_with_different_scalars_3(void)
669671

670672
SEC("socket")
671673
__description("map access: value_ptr += known scalar, upper oob arith, test 1")
672-
__success __failure_unpriv
674+
__success
675+
#ifdef SPEC_V1
676+
__failure_unpriv
673677
__msg_unpriv("R0 pointer arithmetic of map value goes out of range")
678+
#endif
674679
__retval(1)
675680
__naked void upper_oob_arith_test_1(void)
676681
{
@@ -696,8 +701,11 @@ l0_%=: r0 = 1; \
696701

697702
SEC("socket")
698703
__description("map access: value_ptr += known scalar, upper oob arith, test 2")
699-
__success __failure_unpriv
704+
__success
705+
#ifdef SPEC_V1
706+
__failure_unpriv
700707
__msg_unpriv("R0 pointer arithmetic of map value goes out of range")
708+
#endif
701709
__retval(1)
702710
__naked void upper_oob_arith_test_2(void)
703711
{
@@ -749,8 +757,10 @@ l0_%=: r0 = 1; \
749757
SEC("socket")
750758
__description("map access: value_ptr -= known scalar, lower oob arith, test 1")
751759
__failure __msg("R0 min value is outside of the allowed memory range")
760+
#ifdef SPEC_V1
752761
__failure_unpriv
753762
__msg_unpriv("R0 pointer arithmetic of map value goes out of range")
763+
#endif
754764
__naked void lower_oob_arith_test_1(void)
755765
{
756766
asm volatile (" \
@@ -776,8 +786,11 @@ l0_%=: r0 = 1; \
776786

777787
SEC("socket")
778788
__description("map access: value_ptr -= known scalar, lower oob arith, test 2")
779-
__success __failure_unpriv
789+
__success
790+
#ifdef SPEC_V1
791+
__failure_unpriv
780792
__msg_unpriv("R0 pointer arithmetic of map value goes out of range")
793+
#endif
781794
__retval(1)
782795
__naked void lower_oob_arith_test_2(void)
783796
{
@@ -1084,8 +1097,11 @@ l0_%=: exit; \
10841097

10851098
SEC("socket")
10861099
__description("map access: unknown scalar += value_ptr, 3")
1087-
__success __failure_unpriv
1100+
__success
1101+
#ifdef SPEC_V1
1102+
__failure_unpriv
10881103
__msg_unpriv("R0 pointer arithmetic of map value goes out of range")
1104+
#endif
10891105
__retval(0xabcdef12) __flag(BPF_F_ANY_ALIGNMENT)
10901106
__naked void unknown_scalar_value_ptr_3(void)
10911107
{
@@ -1115,7 +1131,9 @@ l0_%=: exit; \
11151131
SEC("socket")
11161132
__description("map access: unknown scalar += value_ptr, 4")
11171133
__failure __msg("R1 max value is outside of the allowed memory range")
1134+
#ifdef SPEC_V1
11181135
__msg_unpriv("R1 pointer arithmetic of map value goes out of range")
1136+
#endif
11191137
__flag(BPF_F_ANY_ALIGNMENT)
11201138
__naked void unknown_scalar_value_ptr_4(void)
11211139
{

0 commit comments

Comments
 (0)