1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/subreg.c */
5 #include <bpf/bpf_helpers.h>
8 /* This file contains sub-register zero extension checks for insns defining
9 * sub-registers, meaning:
10 * - All insns under BPF_ALU class. Their BPF_ALU32 variants or narrow width
11 * forms (BPF_END) could define sub-registers.
12 * - Narrow direct loads, BPF_B/H/W | BPF_LDX.
13 * - BPF_LD is not exposed to JIT back-ends, so no need for testing.
15 * "get_prandom_u32" is used to initialize low 32-bit of some registers to
16 * prevent potential optimizations done by verifier or JIT back-ends which could
17 * optimize register back into constant when range info shows one register is a
22 __description("add32 reg zero extend check")
23 __success __success_unpriv __retval(0)
24 __naked void add32_reg_zero_extend_check(void)
27 call %[bpf_get_prandom_u32]; \
29 r0 = 0x100000000 ll; \
34 : __imm(bpf_get_prandom_u32)
39 __description("add32 imm zero extend check")
40 __success __success_unpriv __retval(0)
41 __naked void add32_imm_zero_extend_check(void)
44 call %[bpf_get_prandom_u32]; \
45 r1 = 0x1000000000 ll; \
47 /* An insn could have no effect on the low 32-bit, for example:\
51 * But, they should still zero high 32-bit. \
56 call %[bpf_get_prandom_u32]; \
57 r1 = 0x1000000000 ll; \
64 : __imm(bpf_get_prandom_u32)
69 __description("sub32 reg zero extend check")
70 __success __success_unpriv __retval(0)
71 __naked void sub32_reg_zero_extend_check(void)
74 call %[bpf_get_prandom_u32]; \
76 r0 = 0x1ffffffff ll; \
81 : __imm(bpf_get_prandom_u32)
86 __description("sub32 imm zero extend check")
87 __success __success_unpriv __retval(0)
88 __naked void sub32_imm_zero_extend_check(void)
91 call %[bpf_get_prandom_u32]; \
92 r1 = 0x1000000000 ll; \
97 call %[bpf_get_prandom_u32]; \
98 r1 = 0x1000000000 ll; \
105 : __imm(bpf_get_prandom_u32)
110 __description("mul32 reg zero extend check")
111 __success __success_unpriv __retval(0)
112 __naked void mul32_reg_zero_extend_check(void)
115 call %[bpf_get_prandom_u32]; \
117 r0 = 0x100000001 ll; \
122 : __imm(bpf_get_prandom_u32)
127 __description("mul32 imm zero extend check")
128 __success __success_unpriv __retval(0)
129 __naked void mul32_imm_zero_extend_check(void)
132 call %[bpf_get_prandom_u32]; \
133 r1 = 0x1000000000 ll; \
138 call %[bpf_get_prandom_u32]; \
139 r1 = 0x1000000000 ll; \
146 : __imm(bpf_get_prandom_u32)
151 __description("div32 reg zero extend check")
152 __success __success_unpriv __retval(0)
153 __naked void div32_reg_zero_extend_check(void)
156 call %[bpf_get_prandom_u32]; \
163 : __imm(bpf_get_prandom_u32)
168 __description("div32 imm zero extend check")
169 __success __success_unpriv __retval(0)
170 __naked void div32_imm_zero_extend_check(void)
173 call %[bpf_get_prandom_u32]; \
174 r1 = 0x1000000000 ll; \
179 call %[bpf_get_prandom_u32]; \
180 r1 = 0x1000000000 ll; \
187 : __imm(bpf_get_prandom_u32)
192 __description("or32 reg zero extend check")
193 __success __success_unpriv __retval(0)
194 __naked void or32_reg_zero_extend_check(void)
197 call %[bpf_get_prandom_u32]; \
199 r0 = 0x100000001 ll; \
204 : __imm(bpf_get_prandom_u32)
209 __description("or32 imm zero extend check")
210 __success __success_unpriv __retval(0)
211 __naked void or32_imm_zero_extend_check(void)
214 call %[bpf_get_prandom_u32]; \
215 r1 = 0x1000000000 ll; \
220 call %[bpf_get_prandom_u32]; \
221 r1 = 0x1000000000 ll; \
228 : __imm(bpf_get_prandom_u32)
233 __description("and32 reg zero extend check")
234 __success __success_unpriv __retval(0)
235 __naked void and32_reg_zero_extend_check(void)
238 call %[bpf_get_prandom_u32]; \
239 r1 = 0x100000000 ll; \
241 r0 = 0x1ffffffff ll; \
246 : __imm(bpf_get_prandom_u32)
251 __description("and32 imm zero extend check")
252 __success __success_unpriv __retval(0)
253 __naked void and32_imm_zero_extend_check(void)
256 call %[bpf_get_prandom_u32]; \
257 r1 = 0x1000000000 ll; \
262 call %[bpf_get_prandom_u32]; \
263 r1 = 0x1000000000 ll; \
270 : __imm(bpf_get_prandom_u32)
275 __description("lsh32 reg zero extend check")
276 __success __success_unpriv __retval(0)
277 __naked void lsh32_reg_zero_extend_check(void)
280 call %[bpf_get_prandom_u32]; \
281 r1 = 0x100000000 ll; \
288 : __imm(bpf_get_prandom_u32)
293 __description("lsh32 imm zero extend check")
294 __success __success_unpriv __retval(0)
295 __naked void lsh32_imm_zero_extend_check(void)
298 call %[bpf_get_prandom_u32]; \
299 r1 = 0x1000000000 ll; \
304 call %[bpf_get_prandom_u32]; \
305 r1 = 0x1000000000 ll; \
312 : __imm(bpf_get_prandom_u32)
317 __description("rsh32 reg zero extend check")
318 __success __success_unpriv __retval(0)
319 __naked void rsh32_reg_zero_extend_check(void)
322 call %[bpf_get_prandom_u32]; \
323 r1 = 0x1000000000 ll; \
330 : __imm(bpf_get_prandom_u32)
335 __description("rsh32 imm zero extend check")
336 __success __success_unpriv __retval(0)
337 __naked void rsh32_imm_zero_extend_check(void)
340 call %[bpf_get_prandom_u32]; \
341 r1 = 0x1000000000 ll; \
346 call %[bpf_get_prandom_u32]; \
347 r1 = 0x1000000000 ll; \
354 : __imm(bpf_get_prandom_u32)
359 __description("neg32 reg zero extend check")
360 __success __success_unpriv __retval(0)
361 __naked void neg32_reg_zero_extend_check(void)
364 call %[bpf_get_prandom_u32]; \
365 r1 = 0x1000000000 ll; \
371 : __imm(bpf_get_prandom_u32)
376 __description("mod32 reg zero extend check")
377 __success __success_unpriv __retval(0)
378 __naked void mod32_reg_zero_extend_check(void)
381 call %[bpf_get_prandom_u32]; \
388 : __imm(bpf_get_prandom_u32)
393 __description("mod32 imm zero extend check")
394 __success __success_unpriv __retval(0)
395 __naked void mod32_imm_zero_extend_check(void)
398 call %[bpf_get_prandom_u32]; \
399 r1 = 0x1000000000 ll; \
404 call %[bpf_get_prandom_u32]; \
405 r1 = 0x1000000000 ll; \
412 : __imm(bpf_get_prandom_u32)
417 __description("xor32 reg zero extend check")
418 __success __success_unpriv __retval(0)
419 __naked void xor32_reg_zero_extend_check(void)
422 call %[bpf_get_prandom_u32]; \
424 r0 = 0x100000000 ll; \
429 : __imm(bpf_get_prandom_u32)
434 __description("xor32 imm zero extend check")
435 __success __success_unpriv __retval(0)
436 __naked void xor32_imm_zero_extend_check(void)
439 call %[bpf_get_prandom_u32]; \
440 r1 = 0x1000000000 ll; \
446 : __imm(bpf_get_prandom_u32)
451 __description("mov32 reg zero extend check")
452 __success __success_unpriv __retval(0)
453 __naked void mov32_reg_zero_extend_check(void)
456 call %[bpf_get_prandom_u32]; \
457 r1 = 0x100000000 ll; \
459 r0 = 0x100000000 ll; \
464 : __imm(bpf_get_prandom_u32)
469 __description("mov32 imm zero extend check")
470 __success __success_unpriv __retval(0)
471 __naked void mov32_imm_zero_extend_check(void)
474 call %[bpf_get_prandom_u32]; \
475 r1 = 0x1000000000 ll; \
480 call %[bpf_get_prandom_u32]; \
481 r1 = 0x1000000000 ll; \
488 : __imm(bpf_get_prandom_u32)
493 __description("arsh32 reg zero extend check")
494 __success __success_unpriv __retval(0)
495 __naked void arsh32_reg_zero_extend_check(void)
498 call %[bpf_get_prandom_u32]; \
499 r1 = 0x1000000000 ll; \
506 : __imm(bpf_get_prandom_u32)
511 __description("arsh32 imm zero extend check")
512 __success __success_unpriv __retval(0)
513 __naked void arsh32_imm_zero_extend_check(void)
516 call %[bpf_get_prandom_u32]; \
517 r1 = 0x1000000000 ll; \
522 call %[bpf_get_prandom_u32]; \
523 r1 = 0x1000000000 ll; \
530 : __imm(bpf_get_prandom_u32)
535 __description("end16 (to_le) reg zero extend check")
536 __success __success_unpriv __retval(0)
537 __naked void le_reg_zero_extend_check_1(void)
540 call %[bpf_get_prandom_u32]; \
543 call %[bpf_get_prandom_u32]; \
549 : __imm(bpf_get_prandom_u32)
554 __description("end32 (to_le) reg zero extend check")
555 __success __success_unpriv __retval(0)
556 __naked void le_reg_zero_extend_check_2(void)
559 call %[bpf_get_prandom_u32]; \
562 call %[bpf_get_prandom_u32]; \
568 : __imm(bpf_get_prandom_u32)
573 __description("end16 (to_be) reg zero extend check")
574 __success __success_unpriv __retval(0)
575 __naked void be_reg_zero_extend_check_1(void)
578 call %[bpf_get_prandom_u32]; \
581 call %[bpf_get_prandom_u32]; \
587 : __imm(bpf_get_prandom_u32)
592 __description("end32 (to_be) reg zero extend check")
593 __success __success_unpriv __retval(0)
594 __naked void be_reg_zero_extend_check_2(void)
597 call %[bpf_get_prandom_u32]; \
600 call %[bpf_get_prandom_u32]; \
606 : __imm(bpf_get_prandom_u32)
611 __description("ldx_b zero extend check")
612 __success __success_unpriv __retval(0)
613 __naked void ldx_b_zero_extend_check(void)
619 *(u32*)(r6 + 0) = r7; \
620 call %[bpf_get_prandom_u32]; \
621 r1 = 0x1000000000 ll; \
623 r0 = *(u8*)(r6 + 0); \
627 : __imm(bpf_get_prandom_u32)
632 __description("ldx_h zero extend check")
633 __success __success_unpriv __retval(0)
634 __naked void ldx_h_zero_extend_check(void)
640 *(u32*)(r6 + 0) = r7; \
641 call %[bpf_get_prandom_u32]; \
642 r1 = 0x1000000000 ll; \
644 r0 = *(u16*)(r6 + 0); \
648 : __imm(bpf_get_prandom_u32)
653 __description("ldx_w zero extend check")
654 __success __success_unpriv __retval(0)
655 __naked void ldx_w_zero_extend_check(void)
661 *(u32*)(r6 + 0) = r7; \
662 call %[bpf_get_prandom_u32]; \
663 r1 = 0x1000000000 ll; \
665 r0 = *(u32*)(r6 + 0); \
669 : __imm(bpf_get_prandom_u32)
673 char _license[] SEC("license") = "GPL";