1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/div0.c */
3 
4 #include <linux/bpf.h>
5 #include <bpf/bpf_helpers.h>
6 #include "bpf_misc.h"
7 
8 SEC("socket")
9 __description("DIV32 by 0, zero check 1")
10 __success __success_unpriv __retval(42)
11 __naked void by_0_zero_check_1_1(void)
12 {
13 	asm volatile ("					\
14 	w0 = 42;					\
15 	w1 = 0;						\
16 	w2 = 1;						\
17 	w2 /= w1;					\
18 	exit;						\
19 "	::: __clobber_all);
20 }
21 
22 SEC("socket")
23 __description("DIV32 by 0, zero check 2")
24 __success __success_unpriv __retval(42)
25 __naked void by_0_zero_check_2_1(void)
26 {
27 	asm volatile ("					\
28 	w0 = 42;					\
29 	r1 = 0xffffffff00000000LL ll;			\
30 	w2 = 1;						\
31 	w2 /= w1;					\
32 	exit;						\
33 "	::: __clobber_all);
34 }
35 
36 SEC("socket")
37 __description("DIV64 by 0, zero check")
38 __success __success_unpriv __retval(42)
39 __naked void div64_by_0_zero_check(void)
40 {
41 	asm volatile ("					\
42 	w0 = 42;					\
43 	w1 = 0;						\
44 	w2 = 1;						\
45 	r2 /= r1;					\
46 	exit;						\
47 "	::: __clobber_all);
48 }
49 
50 SEC("socket")
51 __description("MOD32 by 0, zero check 1")
52 __success __success_unpriv __retval(42)
53 __naked void by_0_zero_check_1_2(void)
54 {
55 	asm volatile ("					\
56 	w0 = 42;					\
57 	w1 = 0;						\
58 	w2 = 1;						\
59 	w2 %%= w1;					\
60 	exit;						\
61 "	::: __clobber_all);
62 }
63 
64 SEC("socket")
65 __description("MOD32 by 0, zero check 2")
66 __success __success_unpriv __retval(42)
67 __naked void by_0_zero_check_2_2(void)
68 {
69 	asm volatile ("					\
70 	w0 = 42;					\
71 	r1 = 0xffffffff00000000LL ll;			\
72 	w2 = 1;						\
73 	w2 %%= w1;					\
74 	exit;						\
75 "	::: __clobber_all);
76 }
77 
78 SEC("socket")
79 __description("MOD64 by 0, zero check")
80 __success __success_unpriv __retval(42)
81 __naked void mod64_by_0_zero_check(void)
82 {
83 	asm volatile ("					\
84 	w0 = 42;					\
85 	w1 = 0;						\
86 	w2 = 1;						\
87 	r2 %%= r1;					\
88 	exit;						\
89 "	::: __clobber_all);
90 }
91 
92 SEC("tc")
93 __description("DIV32 by 0, zero check ok, cls")
94 __success __retval(8)
95 __naked void _0_zero_check_ok_cls_1(void)
96 {
97 	asm volatile ("					\
98 	w0 = 42;					\
99 	w1 = 2;						\
100 	w2 = 16;					\
101 	w2 /= w1;					\
102 	r0 = r2;					\
103 	exit;						\
104 "	::: __clobber_all);
105 }
106 
107 SEC("tc")
108 __description("DIV32 by 0, zero check 1, cls")
109 __success __retval(0)
110 __naked void _0_zero_check_1_cls_1(void)
111 {
112 	asm volatile ("					\
113 	w1 = 0;						\
114 	w0 = 1;						\
115 	w0 /= w1;					\
116 	exit;						\
117 "	::: __clobber_all);
118 }
119 
120 SEC("tc")
121 __description("DIV32 by 0, zero check 2, cls")
122 __success __retval(0)
123 __naked void _0_zero_check_2_cls_1(void)
124 {
125 	asm volatile ("					\
126 	r1 = 0xffffffff00000000LL ll;			\
127 	w0 = 1;						\
128 	w0 /= w1;					\
129 	exit;						\
130 "	::: __clobber_all);
131 }
132 
133 SEC("tc")
134 __description("DIV64 by 0, zero check, cls")
135 __success __retval(0)
136 __naked void by_0_zero_check_cls(void)
137 {
138 	asm volatile ("					\
139 	w1 = 0;						\
140 	w0 = 1;						\
141 	r0 /= r1;					\
142 	exit;						\
143 "	::: __clobber_all);
144 }
145 
146 SEC("tc")
147 __description("MOD32 by 0, zero check ok, cls")
148 __success __retval(2)
149 __naked void _0_zero_check_ok_cls_2(void)
150 {
151 	asm volatile ("					\
152 	w0 = 42;					\
153 	w1 = 3;						\
154 	w2 = 5;						\
155 	w2 %%= w1;					\
156 	r0 = r2;					\
157 	exit;						\
158 "	::: __clobber_all);
159 }
160 
161 SEC("tc")
162 __description("MOD32 by 0, zero check 1, cls")
163 __success __retval(1)
164 __naked void _0_zero_check_1_cls_2(void)
165 {
166 	asm volatile ("					\
167 	w1 = 0;						\
168 	w0 = 1;						\
169 	w0 %%= w1;					\
170 	exit;						\
171 "	::: __clobber_all);
172 }
173 
174 SEC("tc")
175 __description("MOD32 by 0, zero check 2, cls")
176 __success __retval(1)
177 __naked void _0_zero_check_2_cls_2(void)
178 {
179 	asm volatile ("					\
180 	r1 = 0xffffffff00000000LL ll;			\
181 	w0 = 1;						\
182 	w0 %%= w1;					\
183 	exit;						\
184 "	::: __clobber_all);
185 }
186 
187 SEC("tc")
188 __description("MOD64 by 0, zero check 1, cls")
189 __success __retval(2)
190 __naked void _0_zero_check_1_cls_3(void)
191 {
192 	asm volatile ("					\
193 	w1 = 0;						\
194 	w0 = 2;						\
195 	r0 %%= r1;					\
196 	exit;						\
197 "	::: __clobber_all);
198 }
199 
200 SEC("tc")
201 __description("MOD64 by 0, zero check 2, cls")
202 __success __retval(-1)
203 __naked void _0_zero_check_2_cls_3(void)
204 {
205 	asm volatile ("					\
206 	w1 = 0;						\
207 	w0 = -1;					\
208 	r0 %%= r1;					\
209 	exit;						\
210 "	::: __clobber_all);
211 }
212 
213 char _license[] SEC("license") = "GPL";
214