1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/const_or.c */
3 
4 #include <linux/bpf.h>
5 #include <bpf/bpf_helpers.h>
6 #include "bpf_misc.h"
7 
8 SEC("tracepoint")
9 __description("constant register |= constant should keep constant type")
10 __success
11 __naked void constant_should_keep_constant_type(void)
12 {
13 	asm volatile ("					\
14 	r1 = r10;					\
15 	r1 += -48;					\
16 	r2 = 34;					\
17 	r2 |= 13;					\
18 	r3 = 0;						\
19 	call %[bpf_probe_read_kernel];			\
20 	exit;						\
21 "	:
22 	: __imm(bpf_probe_read_kernel)
23 	: __clobber_all);
24 }
25 
26 SEC("tracepoint")
27 __description("constant register |= constant should not bypass stack boundary checks")
28 __failure __msg("invalid indirect access to stack R1 off=-48 size=58")
29 __naked void not_bypass_stack_boundary_checks_1(void)
30 {
31 	asm volatile ("					\
32 	r1 = r10;					\
33 	r1 += -48;					\
34 	r2 = 34;					\
35 	r2 |= 24;					\
36 	r3 = 0;						\
37 	call %[bpf_probe_read_kernel];			\
38 	exit;						\
39 "	:
40 	: __imm(bpf_probe_read_kernel)
41 	: __clobber_all);
42 }
43 
44 SEC("tracepoint")
45 __description("constant register |= constant register should keep constant type")
46 __success
47 __naked void register_should_keep_constant_type(void)
48 {
49 	asm volatile ("					\
50 	r1 = r10;					\
51 	r1 += -48;					\
52 	r2 = 34;					\
53 	r4 = 13;					\
54 	r2 |= r4;					\
55 	r3 = 0;						\
56 	call %[bpf_probe_read_kernel];			\
57 	exit;						\
58 "	:
59 	: __imm(bpf_probe_read_kernel)
60 	: __clobber_all);
61 }
62 
63 SEC("tracepoint")
64 __description("constant register |= constant register should not bypass stack boundary checks")
65 __failure __msg("invalid indirect access to stack R1 off=-48 size=58")
66 __naked void not_bypass_stack_boundary_checks_2(void)
67 {
68 	asm volatile ("					\
69 	r1 = r10;					\
70 	r1 += -48;					\
71 	r2 = 34;					\
72 	r4 = 24;					\
73 	r2 |= r4;					\
74 	r3 = 0;						\
75 	call %[bpf_probe_read_kernel];			\
76 	exit;						\
77 "	:
78 	: __imm(bpf_probe_read_kernel)
79 	: __clobber_all);
80 }
81 
82 char _license[] SEC("license") = "GPL";
83