1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/xdp_direct_packet_access.c */
3
4 #include <linux/bpf.h>
5 #include <bpf/bpf_helpers.h>
6 #include "bpf_misc.h"
7
8 SEC("xdp")
9 __description("XDP pkt read, pkt_end mangling, bad access 1")
10 __failure __msg("R3 pointer arithmetic on pkt_end")
end_mangling_bad_access_1(void)11 __naked void end_mangling_bad_access_1(void)
12 {
13 asm volatile (" \
14 r2 = *(u32*)(r1 + %[xdp_md_data]); \
15 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
16 r1 = r2; \
17 r1 += 8; \
18 r3 += 8; \
19 if r1 > r3 goto l0_%=; \
20 r0 = *(u64*)(r1 - 8); \
21 l0_%=: r0 = 0; \
22 exit; \
23 " :
24 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
25 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
26 : __clobber_all);
27 }
28
29 SEC("xdp")
30 __description("XDP pkt read, pkt_end mangling, bad access 2")
31 __failure __msg("R3 pointer arithmetic on pkt_end")
end_mangling_bad_access_2(void)32 __naked void end_mangling_bad_access_2(void)
33 {
34 asm volatile (" \
35 r2 = *(u32*)(r1 + %[xdp_md_data]); \
36 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
37 r1 = r2; \
38 r1 += 8; \
39 r3 -= 8; \
40 if r1 > r3 goto l0_%=; \
41 r0 = *(u64*)(r1 - 8); \
42 l0_%=: r0 = 0; \
43 exit; \
44 " :
45 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
46 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
47 : __clobber_all);
48 }
49
50 SEC("xdp")
51 __description("XDP pkt read, pkt_data' > pkt_end, corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)52 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
53 __naked void end_corner_case_good_access_1(void)
54 {
55 asm volatile (" \
56 r2 = *(u32*)(r1 + %[xdp_md_data]); \
57 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
58 r1 = r2; \
59 r1 += 8; \
60 if r1 > r3 goto l0_%=; \
61 r0 = *(u64*)(r1 - 8); \
62 l0_%=: r0 = 0; \
63 exit; \
64 " :
65 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
66 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
67 : __clobber_all);
68 }
69
70 SEC("xdp")
71 __description("XDP pkt read, pkt_data' > pkt_end, bad access 1")
72 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)73 __flag(BPF_F_ANY_ALIGNMENT)
74 __naked void pkt_end_bad_access_1_1(void)
75 {
76 asm volatile (" \
77 r2 = *(u32*)(r1 + %[xdp_md_data]); \
78 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
79 r1 = r2; \
80 r1 += 8; \
81 if r1 > r3 goto l0_%=; \
82 r0 = *(u64*)(r1 - 4); \
83 l0_%=: r0 = 0; \
84 exit; \
85 " :
86 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
87 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
88 : __clobber_all);
89 }
90
91 SEC("xdp")
92 __description("XDP pkt read, pkt_data' > pkt_end, bad access 2")
93 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)94 __flag(BPF_F_ANY_ALIGNMENT)
95 __naked void pkt_end_bad_access_2_1(void)
96 {
97 asm volatile (" \
98 r2 = *(u32*)(r1 + %[xdp_md_data]); \
99 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
100 r1 = r2; \
101 r1 += 8; \
102 if r1 > r3 goto l0_%=; \
103 l0_%=: r0 = *(u64*)(r1 - 8); \
104 r0 = 0; \
105 exit; \
106 " :
107 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
108 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
109 : __clobber_all);
110 }
111
112 SEC("xdp")
113 __description("XDP pkt read, pkt_data' > pkt_end, corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)114 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
115 __naked void corner_case_1_good_access_1(void)
116 {
117 asm volatile (" \
118 r2 = *(u32*)(r1 + %[xdp_md_data]); \
119 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
120 r1 = r2; \
121 r1 += 9; \
122 if r1 > r3 goto l0_%=; \
123 r0 = *(u64*)(r1 - 9); \
124 l0_%=: r0 = 0; \
125 exit; \
126 " :
127 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
128 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
129 : __clobber_all);
130 }
131
132 SEC("xdp")
133 __description("XDP pkt read, pkt_data' > pkt_end, corner case -1, bad access")
134 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)135 __flag(BPF_F_ANY_ALIGNMENT)
136 __naked void corner_case_1_bad_access_1(void)
137 {
138 asm volatile (" \
139 r2 = *(u32*)(r1 + %[xdp_md_data]); \
140 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
141 r1 = r2; \
142 r1 += 7; \
143 if r1 > r3 goto l0_%=; \
144 r0 = *(u64*)(r1 - 7); \
145 l0_%=: r0 = 0; \
146 exit; \
147 " :
148 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
149 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
150 : __clobber_all);
151 }
152
153 SEC("xdp")
154 __description("XDP pkt read, pkt_end > pkt_data', good access")
__flag(BPF_F_ANY_ALIGNMENT)155 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
156 __naked void end_pkt_data_good_access_1(void)
157 {
158 asm volatile (" \
159 r2 = *(u32*)(r1 + %[xdp_md_data]); \
160 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
161 r1 = r2; \
162 r1 += 8; \
163 if r3 > r1 goto l0_%=; \
164 goto l1_%=; \
165 l0_%=: r0 = *(u32*)(r1 - 5); \
166 l1_%=: r0 = 0; \
167 exit; \
168 " :
169 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
170 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
171 : __clobber_all);
172 }
173
174 SEC("xdp")
175 __description("XDP pkt read, pkt_end > pkt_data', corner case -1, bad access")
176 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)177 __flag(BPF_F_ANY_ALIGNMENT)
178 __naked void corner_case_1_bad_access_2(void)
179 {
180 asm volatile (" \
181 r2 = *(u32*)(r1 + %[xdp_md_data]); \
182 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
183 r1 = r2; \
184 r1 += 6; \
185 if r3 > r1 goto l0_%=; \
186 goto l1_%=; \
187 l0_%=: r0 = *(u64*)(r1 - 6); \
188 l1_%=: r0 = 0; \
189 exit; \
190 " :
191 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
192 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
193 : __clobber_all);
194 }
195
196 SEC("xdp")
197 __description("XDP pkt read, pkt_end > pkt_data', bad access 2")
198 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)199 __flag(BPF_F_ANY_ALIGNMENT)
200 __naked void pkt_data_bad_access_2_1(void)
201 {
202 asm volatile (" \
203 r2 = *(u32*)(r1 + %[xdp_md_data]); \
204 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
205 r1 = r2; \
206 r1 += 8; \
207 if r3 > r1 goto l0_%=; \
208 r0 = *(u64*)(r1 - 8); \
209 l0_%=: r0 = 0; \
210 exit; \
211 " :
212 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
213 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
214 : __clobber_all);
215 }
216
217 SEC("xdp")
218 __description("XDP pkt read, pkt_end > pkt_data', corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)219 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
220 __naked void data_corner_case_good_access_1(void)
221 {
222 asm volatile (" \
223 r2 = *(u32*)(r1 + %[xdp_md_data]); \
224 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
225 r1 = r2; \
226 r1 += 7; \
227 if r3 > r1 goto l0_%=; \
228 goto l1_%=; \
229 l0_%=: r0 = *(u64*)(r1 - 7); \
230 l1_%=: r0 = 0; \
231 exit; \
232 " :
233 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
234 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
235 : __clobber_all);
236 }
237
238 SEC("xdp")
239 __description("XDP pkt read, pkt_end > pkt_data', corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)240 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
241 __naked void corner_case_1_good_access_2(void)
242 {
243 asm volatile (" \
244 r2 = *(u32*)(r1 + %[xdp_md_data]); \
245 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
246 r1 = r2; \
247 r1 += 8; \
248 if r3 > r1 goto l0_%=; \
249 goto l1_%=; \
250 l0_%=: r0 = *(u64*)(r1 - 8); \
251 l1_%=: r0 = 0; \
252 exit; \
253 " :
254 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
255 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
256 : __clobber_all);
257 }
258
259 SEC("xdp")
260 __description("XDP pkt read, pkt_data' < pkt_end, good access")
__flag(BPF_F_ANY_ALIGNMENT)261 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
262 __naked void data_pkt_end_good_access_1(void)
263 {
264 asm volatile (" \
265 r2 = *(u32*)(r1 + %[xdp_md_data]); \
266 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
267 r1 = r2; \
268 r1 += 8; \
269 if r1 < r3 goto l0_%=; \
270 goto l1_%=; \
271 l0_%=: r0 = *(u32*)(r1 - 5); \
272 l1_%=: r0 = 0; \
273 exit; \
274 " :
275 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
276 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
277 : __clobber_all);
278 }
279
280 SEC("xdp")
281 __description("XDP pkt read, pkt_data' < pkt_end, corner case -1, bad access")
282 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)283 __flag(BPF_F_ANY_ALIGNMENT)
284 __naked void corner_case_1_bad_access_3(void)
285 {
286 asm volatile (" \
287 r2 = *(u32*)(r1 + %[xdp_md_data]); \
288 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
289 r1 = r2; \
290 r1 += 6; \
291 if r1 < r3 goto l0_%=; \
292 goto l1_%=; \
293 l0_%=: r0 = *(u64*)(r1 - 6); \
294 l1_%=: r0 = 0; \
295 exit; \
296 " :
297 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
298 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
299 : __clobber_all);
300 }
301
302 SEC("xdp")
303 __description("XDP pkt read, pkt_data' < pkt_end, bad access 2")
304 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)305 __flag(BPF_F_ANY_ALIGNMENT)
306 __naked void pkt_end_bad_access_2_2(void)
307 {
308 asm volatile (" \
309 r2 = *(u32*)(r1 + %[xdp_md_data]); \
310 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
311 r1 = r2; \
312 r1 += 8; \
313 if r1 < r3 goto l0_%=; \
314 r0 = *(u64*)(r1 - 8); \
315 l0_%=: r0 = 0; \
316 exit; \
317 " :
318 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
319 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
320 : __clobber_all);
321 }
322
323 SEC("xdp")
324 __description("XDP pkt read, pkt_data' < pkt_end, corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)325 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
326 __naked void end_corner_case_good_access_2(void)
327 {
328 asm volatile (" \
329 r2 = *(u32*)(r1 + %[xdp_md_data]); \
330 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
331 r1 = r2; \
332 r1 += 7; \
333 if r1 < r3 goto l0_%=; \
334 goto l1_%=; \
335 l0_%=: r0 = *(u64*)(r1 - 7); \
336 l1_%=: r0 = 0; \
337 exit; \
338 " :
339 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
340 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
341 : __clobber_all);
342 }
343
344 SEC("xdp")
345 __description("XDP pkt read, pkt_data' < pkt_end, corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)346 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
347 __naked void corner_case_1_good_access_3(void)
348 {
349 asm volatile (" \
350 r2 = *(u32*)(r1 + %[xdp_md_data]); \
351 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
352 r1 = r2; \
353 r1 += 8; \
354 if r1 < r3 goto l0_%=; \
355 goto l1_%=; \
356 l0_%=: r0 = *(u64*)(r1 - 8); \
357 l1_%=: r0 = 0; \
358 exit; \
359 " :
360 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
361 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
362 : __clobber_all);
363 }
364
365 SEC("xdp")
366 __description("XDP pkt read, pkt_end < pkt_data', corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)367 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
368 __naked void data_corner_case_good_access_2(void)
369 {
370 asm volatile (" \
371 r2 = *(u32*)(r1 + %[xdp_md_data]); \
372 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
373 r1 = r2; \
374 r1 += 8; \
375 if r3 < r1 goto l0_%=; \
376 r0 = *(u64*)(r1 - 8); \
377 l0_%=: r0 = 0; \
378 exit; \
379 " :
380 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
381 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
382 : __clobber_all);
383 }
384
385 SEC("xdp")
386 __description("XDP pkt read, pkt_end < pkt_data', bad access 1")
387 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)388 __flag(BPF_F_ANY_ALIGNMENT)
389 __naked void pkt_data_bad_access_1_1(void)
390 {
391 asm volatile (" \
392 r2 = *(u32*)(r1 + %[xdp_md_data]); \
393 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
394 r1 = r2; \
395 r1 += 8; \
396 if r3 < r1 goto l0_%=; \
397 r0 = *(u64*)(r1 - 4); \
398 l0_%=: r0 = 0; \
399 exit; \
400 " :
401 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
402 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
403 : __clobber_all);
404 }
405
406 SEC("xdp")
407 __description("XDP pkt read, pkt_end < pkt_data', bad access 2")
408 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)409 __flag(BPF_F_ANY_ALIGNMENT)
410 __naked void pkt_data_bad_access_2_2(void)
411 {
412 asm volatile (" \
413 r2 = *(u32*)(r1 + %[xdp_md_data]); \
414 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
415 r1 = r2; \
416 r1 += 8; \
417 if r3 < r1 goto l0_%=; \
418 l0_%=: r0 = *(u64*)(r1 - 8); \
419 r0 = 0; \
420 exit; \
421 " :
422 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
423 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
424 : __clobber_all);
425 }
426
427 SEC("xdp")
428 __description("XDP pkt read, pkt_end < pkt_data', corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)429 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
430 __naked void corner_case_1_good_access_4(void)
431 {
432 asm volatile (" \
433 r2 = *(u32*)(r1 + %[xdp_md_data]); \
434 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
435 r1 = r2; \
436 r1 += 9; \
437 if r3 < r1 goto l0_%=; \
438 r0 = *(u64*)(r1 - 9); \
439 l0_%=: r0 = 0; \
440 exit; \
441 " :
442 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
443 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
444 : __clobber_all);
445 }
446
447 SEC("xdp")
448 __description("XDP pkt read, pkt_end < pkt_data', corner case -1, bad access")
449 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)450 __flag(BPF_F_ANY_ALIGNMENT)
451 __naked void corner_case_1_bad_access_4(void)
452 {
453 asm volatile (" \
454 r2 = *(u32*)(r1 + %[xdp_md_data]); \
455 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
456 r1 = r2; \
457 r1 += 7; \
458 if r3 < r1 goto l0_%=; \
459 r0 = *(u64*)(r1 - 7); \
460 l0_%=: r0 = 0; \
461 exit; \
462 " :
463 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
464 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
465 : __clobber_all);
466 }
467
468 SEC("xdp")
469 __description("XDP pkt read, pkt_data' >= pkt_end, good access")
__flag(BPF_F_ANY_ALIGNMENT)470 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
471 __naked void data_pkt_end_good_access_2(void)
472 {
473 asm volatile (" \
474 r2 = *(u32*)(r1 + %[xdp_md_data]); \
475 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
476 r1 = r2; \
477 r1 += 8; \
478 if r1 >= r3 goto l0_%=; \
479 r0 = *(u32*)(r1 - 5); \
480 l0_%=: r0 = 0; \
481 exit; \
482 " :
483 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
484 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
485 : __clobber_all);
486 }
487
488 SEC("xdp")
489 __description("XDP pkt read, pkt_data' >= pkt_end, corner case -1, bad access")
490 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)491 __flag(BPF_F_ANY_ALIGNMENT)
492 __naked void corner_case_1_bad_access_5(void)
493 {
494 asm volatile (" \
495 r2 = *(u32*)(r1 + %[xdp_md_data]); \
496 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
497 r1 = r2; \
498 r1 += 6; \
499 if r1 >= r3 goto l0_%=; \
500 r0 = *(u64*)(r1 - 6); \
501 l0_%=: r0 = 0; \
502 exit; \
503 " :
504 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
505 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
506 : __clobber_all);
507 }
508
509 SEC("xdp")
510 __description("XDP pkt read, pkt_data' >= pkt_end, bad access 2")
511 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)512 __flag(BPF_F_ANY_ALIGNMENT)
513 __naked void pkt_end_bad_access_2_3(void)
514 {
515 asm volatile (" \
516 r2 = *(u32*)(r1 + %[xdp_md_data]); \
517 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
518 r1 = r2; \
519 r1 += 8; \
520 if r1 >= r3 goto l0_%=; \
521 l0_%=: r0 = *(u32*)(r1 - 5); \
522 r0 = 0; \
523 exit; \
524 " :
525 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
526 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
527 : __clobber_all);
528 }
529
530 SEC("xdp")
531 __description("XDP pkt read, pkt_data' >= pkt_end, corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)532 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
533 __naked void end_corner_case_good_access_3(void)
534 {
535 asm volatile (" \
536 r2 = *(u32*)(r1 + %[xdp_md_data]); \
537 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
538 r1 = r2; \
539 r1 += 7; \
540 if r1 >= r3 goto l0_%=; \
541 r0 = *(u64*)(r1 - 7); \
542 l0_%=: r0 = 0; \
543 exit; \
544 " :
545 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
546 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
547 : __clobber_all);
548 }
549
550 SEC("xdp")
551 __description("XDP pkt read, pkt_data' >= pkt_end, corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)552 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
553 __naked void corner_case_1_good_access_5(void)
554 {
555 asm volatile (" \
556 r2 = *(u32*)(r1 + %[xdp_md_data]); \
557 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
558 r1 = r2; \
559 r1 += 8; \
560 if r1 >= r3 goto l0_%=; \
561 r0 = *(u64*)(r1 - 8); \
562 l0_%=: r0 = 0; \
563 exit; \
564 " :
565 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
566 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
567 : __clobber_all);
568 }
569
570 SEC("xdp")
571 __description("XDP pkt read, pkt_end >= pkt_data', corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)572 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
573 __naked void data_corner_case_good_access_3(void)
574 {
575 asm volatile (" \
576 r2 = *(u32*)(r1 + %[xdp_md_data]); \
577 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
578 r1 = r2; \
579 r1 += 8; \
580 if r3 >= r1 goto l0_%=; \
581 goto l1_%=; \
582 l0_%=: r0 = *(u64*)(r1 - 8); \
583 l1_%=: r0 = 0; \
584 exit; \
585 " :
586 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
587 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
588 : __clobber_all);
589 }
590
591 SEC("xdp")
592 __description("XDP pkt read, pkt_end >= pkt_data', bad access 1")
593 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)594 __flag(BPF_F_ANY_ALIGNMENT)
595 __naked void pkt_data_bad_access_1_2(void)
596 {
597 asm volatile (" \
598 r2 = *(u32*)(r1 + %[xdp_md_data]); \
599 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
600 r1 = r2; \
601 r1 += 8; \
602 if r3 >= r1 goto l0_%=; \
603 goto l1_%=; \
604 l0_%=: r0 = *(u64*)(r1 - 4); \
605 l1_%=: r0 = 0; \
606 exit; \
607 " :
608 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
609 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
610 : __clobber_all);
611 }
612
613 SEC("xdp")
614 __description("XDP pkt read, pkt_end >= pkt_data', bad access 2")
615 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)616 __flag(BPF_F_ANY_ALIGNMENT)
617 __naked void pkt_data_bad_access_2_3(void)
618 {
619 asm volatile (" \
620 r2 = *(u32*)(r1 + %[xdp_md_data]); \
621 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
622 r1 = r2; \
623 r1 += 8; \
624 if r3 >= r1 goto l0_%=; \
625 r0 = *(u64*)(r1 - 8); \
626 l0_%=: r0 = 0; \
627 exit; \
628 " :
629 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
630 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
631 : __clobber_all);
632 }
633
634 SEC("xdp")
635 __description("XDP pkt read, pkt_end >= pkt_data', corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)636 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
637 __naked void corner_case_1_good_access_6(void)
638 {
639 asm volatile (" \
640 r2 = *(u32*)(r1 + %[xdp_md_data]); \
641 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
642 r1 = r2; \
643 r1 += 9; \
644 if r3 >= r1 goto l0_%=; \
645 goto l1_%=; \
646 l0_%=: r0 = *(u64*)(r1 - 9); \
647 l1_%=: r0 = 0; \
648 exit; \
649 " :
650 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
651 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
652 : __clobber_all);
653 }
654
655 SEC("xdp")
656 __description("XDP pkt read, pkt_end >= pkt_data', corner case -1, bad access")
657 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)658 __flag(BPF_F_ANY_ALIGNMENT)
659 __naked void corner_case_1_bad_access_6(void)
660 {
661 asm volatile (" \
662 r2 = *(u32*)(r1 + %[xdp_md_data]); \
663 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
664 r1 = r2; \
665 r1 += 7; \
666 if r3 >= r1 goto l0_%=; \
667 goto l1_%=; \
668 l0_%=: r0 = *(u64*)(r1 - 7); \
669 l1_%=: r0 = 0; \
670 exit; \
671 " :
672 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
673 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
674 : __clobber_all);
675 }
676
677 SEC("xdp")
678 __description("XDP pkt read, pkt_data' <= pkt_end, corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)679 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
680 __naked void end_corner_case_good_access_4(void)
681 {
682 asm volatile (" \
683 r2 = *(u32*)(r1 + %[xdp_md_data]); \
684 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
685 r1 = r2; \
686 r1 += 8; \
687 if r1 <= r3 goto l0_%=; \
688 goto l1_%=; \
689 l0_%=: r0 = *(u64*)(r1 - 8); \
690 l1_%=: r0 = 0; \
691 exit; \
692 " :
693 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
694 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
695 : __clobber_all);
696 }
697
698 SEC("xdp")
699 __description("XDP pkt read, pkt_data' <= pkt_end, bad access 1")
700 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)701 __flag(BPF_F_ANY_ALIGNMENT)
702 __naked void pkt_end_bad_access_1_2(void)
703 {
704 asm volatile (" \
705 r2 = *(u32*)(r1 + %[xdp_md_data]); \
706 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
707 r1 = r2; \
708 r1 += 8; \
709 if r1 <= r3 goto l0_%=; \
710 goto l1_%=; \
711 l0_%=: r0 = *(u64*)(r1 - 4); \
712 l1_%=: r0 = 0; \
713 exit; \
714 " :
715 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
716 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
717 : __clobber_all);
718 }
719
720 SEC("xdp")
721 __description("XDP pkt read, pkt_data' <= pkt_end, bad access 2")
722 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)723 __flag(BPF_F_ANY_ALIGNMENT)
724 __naked void pkt_end_bad_access_2_4(void)
725 {
726 asm volatile (" \
727 r2 = *(u32*)(r1 + %[xdp_md_data]); \
728 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
729 r1 = r2; \
730 r1 += 8; \
731 if r1 <= r3 goto l0_%=; \
732 r0 = *(u64*)(r1 - 8); \
733 l0_%=: r0 = 0; \
734 exit; \
735 " :
736 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
737 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
738 : __clobber_all);
739 }
740
741 SEC("xdp")
742 __description("XDP pkt read, pkt_data' <= pkt_end, corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)743 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
744 __naked void corner_case_1_good_access_7(void)
745 {
746 asm volatile (" \
747 r2 = *(u32*)(r1 + %[xdp_md_data]); \
748 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
749 r1 = r2; \
750 r1 += 9; \
751 if r1 <= r3 goto l0_%=; \
752 goto l1_%=; \
753 l0_%=: r0 = *(u64*)(r1 - 9); \
754 l1_%=: r0 = 0; \
755 exit; \
756 " :
757 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
758 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
759 : __clobber_all);
760 }
761
762 SEC("xdp")
763 __description("XDP pkt read, pkt_data' <= pkt_end, corner case -1, bad access")
764 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)765 __flag(BPF_F_ANY_ALIGNMENT)
766 __naked void corner_case_1_bad_access_7(void)
767 {
768 asm volatile (" \
769 r2 = *(u32*)(r1 + %[xdp_md_data]); \
770 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
771 r1 = r2; \
772 r1 += 7; \
773 if r1 <= r3 goto l0_%=; \
774 goto l1_%=; \
775 l0_%=: r0 = *(u64*)(r1 - 7); \
776 l1_%=: r0 = 0; \
777 exit; \
778 " :
779 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
780 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
781 : __clobber_all);
782 }
783
784 SEC("xdp")
785 __description("XDP pkt read, pkt_end <= pkt_data', good access")
__flag(BPF_F_ANY_ALIGNMENT)786 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
787 __naked void end_pkt_data_good_access_2(void)
788 {
789 asm volatile (" \
790 r2 = *(u32*)(r1 + %[xdp_md_data]); \
791 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
792 r1 = r2; \
793 r1 += 8; \
794 if r3 <= r1 goto l0_%=; \
795 r0 = *(u32*)(r1 - 5); \
796 l0_%=: r0 = 0; \
797 exit; \
798 " :
799 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
800 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
801 : __clobber_all);
802 }
803
804 SEC("xdp")
805 __description("XDP pkt read, pkt_end <= pkt_data', corner case -1, bad access")
806 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)807 __flag(BPF_F_ANY_ALIGNMENT)
808 __naked void corner_case_1_bad_access_8(void)
809 {
810 asm volatile (" \
811 r2 = *(u32*)(r1 + %[xdp_md_data]); \
812 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
813 r1 = r2; \
814 r1 += 6; \
815 if r3 <= r1 goto l0_%=; \
816 r0 = *(u64*)(r1 - 6); \
817 l0_%=: r0 = 0; \
818 exit; \
819 " :
820 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
821 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
822 : __clobber_all);
823 }
824
825 SEC("xdp")
826 __description("XDP pkt read, pkt_end <= pkt_data', bad access 2")
827 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)828 __flag(BPF_F_ANY_ALIGNMENT)
829 __naked void pkt_data_bad_access_2_4(void)
830 {
831 asm volatile (" \
832 r2 = *(u32*)(r1 + %[xdp_md_data]); \
833 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
834 r1 = r2; \
835 r1 += 8; \
836 if r3 <= r1 goto l0_%=; \
837 l0_%=: r0 = *(u32*)(r1 - 5); \
838 r0 = 0; \
839 exit; \
840 " :
841 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
842 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
843 : __clobber_all);
844 }
845
846 SEC("xdp")
847 __description("XDP pkt read, pkt_end <= pkt_data', corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)848 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
849 __naked void data_corner_case_good_access_4(void)
850 {
851 asm volatile (" \
852 r2 = *(u32*)(r1 + %[xdp_md_data]); \
853 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
854 r1 = r2; \
855 r1 += 7; \
856 if r3 <= r1 goto l0_%=; \
857 r0 = *(u64*)(r1 - 7); \
858 l0_%=: r0 = 0; \
859 exit; \
860 " :
861 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
862 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
863 : __clobber_all);
864 }
865
866 SEC("xdp")
867 __description("XDP pkt read, pkt_end <= pkt_data', corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)868 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
869 __naked void corner_case_1_good_access_8(void)
870 {
871 asm volatile (" \
872 r2 = *(u32*)(r1 + %[xdp_md_data]); \
873 r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
874 r1 = r2; \
875 r1 += 8; \
876 if r3 <= r1 goto l0_%=; \
877 r0 = *(u64*)(r1 - 8); \
878 l0_%=: r0 = 0; \
879 exit; \
880 " :
881 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
882 __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
883 : __clobber_all);
884 }
885
886 SEC("xdp")
887 __description("XDP pkt read, pkt_meta' > pkt_data, corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)888 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
889 __naked void data_corner_case_good_access_5(void)
890 {
891 asm volatile (" \
892 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
893 r3 = *(u32*)(r1 + %[xdp_md_data]); \
894 r1 = r2; \
895 r1 += 8; \
896 if r1 > r3 goto l0_%=; \
897 r0 = *(u64*)(r1 - 8); \
898 l0_%=: r0 = 0; \
899 exit; \
900 " :
901 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
902 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
903 : __clobber_all);
904 }
905
906 SEC("xdp")
907 __description("XDP pkt read, pkt_meta' > pkt_data, bad access 1")
908 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)909 __flag(BPF_F_ANY_ALIGNMENT)
910 __naked void pkt_data_bad_access_1_3(void)
911 {
912 asm volatile (" \
913 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
914 r3 = *(u32*)(r1 + %[xdp_md_data]); \
915 r1 = r2; \
916 r1 += 8; \
917 if r1 > r3 goto l0_%=; \
918 r0 = *(u64*)(r1 - 4); \
919 l0_%=: r0 = 0; \
920 exit; \
921 " :
922 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
923 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
924 : __clobber_all);
925 }
926
927 SEC("xdp")
928 __description("XDP pkt read, pkt_meta' > pkt_data, bad access 2")
929 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)930 __flag(BPF_F_ANY_ALIGNMENT)
931 __naked void pkt_data_bad_access_2_5(void)
932 {
933 asm volatile (" \
934 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
935 r3 = *(u32*)(r1 + %[xdp_md_data]); \
936 r1 = r2; \
937 r1 += 8; \
938 if r1 > r3 goto l0_%=; \
939 l0_%=: r0 = *(u64*)(r1 - 8); \
940 r0 = 0; \
941 exit; \
942 " :
943 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
944 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
945 : __clobber_all);
946 }
947
948 SEC("xdp")
949 __description("XDP pkt read, pkt_meta' > pkt_data, corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)950 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
951 __naked void corner_case_1_good_access_9(void)
952 {
953 asm volatile (" \
954 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
955 r3 = *(u32*)(r1 + %[xdp_md_data]); \
956 r1 = r2; \
957 r1 += 9; \
958 if r1 > r3 goto l0_%=; \
959 r0 = *(u64*)(r1 - 9); \
960 l0_%=: r0 = 0; \
961 exit; \
962 " :
963 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
964 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
965 : __clobber_all);
966 }
967
968 SEC("xdp")
969 __description("XDP pkt read, pkt_meta' > pkt_data, corner case -1, bad access")
970 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)971 __flag(BPF_F_ANY_ALIGNMENT)
972 __naked void corner_case_1_bad_access_9(void)
973 {
974 asm volatile (" \
975 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
976 r3 = *(u32*)(r1 + %[xdp_md_data]); \
977 r1 = r2; \
978 r1 += 7; \
979 if r1 > r3 goto l0_%=; \
980 r0 = *(u64*)(r1 - 7); \
981 l0_%=: r0 = 0; \
982 exit; \
983 " :
984 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
985 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
986 : __clobber_all);
987 }
988
989 SEC("xdp")
990 __description("XDP pkt read, pkt_data > pkt_meta', good access")
__flag(BPF_F_ANY_ALIGNMENT)991 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
992 __naked void data_pkt_meta_good_access_1(void)
993 {
994 asm volatile (" \
995 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
996 r3 = *(u32*)(r1 + %[xdp_md_data]); \
997 r1 = r2; \
998 r1 += 8; \
999 if r3 > r1 goto l0_%=; \
1000 goto l1_%=; \
1001 l0_%=: r0 = *(u32*)(r1 - 5); \
1002 l1_%=: r0 = 0; \
1003 exit; \
1004 " :
1005 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1006 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1007 : __clobber_all);
1008 }
1009
1010 SEC("xdp")
1011 __description("XDP pkt read, pkt_data > pkt_meta', corner case -1, bad access")
1012 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1013 __flag(BPF_F_ANY_ALIGNMENT)
1014 __naked void corner_case_1_bad_access_10(void)
1015 {
1016 asm volatile (" \
1017 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1018 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1019 r1 = r2; \
1020 r1 += 6; \
1021 if r3 > r1 goto l0_%=; \
1022 goto l1_%=; \
1023 l0_%=: r0 = *(u64*)(r1 - 6); \
1024 l1_%=: r0 = 0; \
1025 exit; \
1026 " :
1027 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1028 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1029 : __clobber_all);
1030 }
1031
1032 SEC("xdp")
1033 __description("XDP pkt read, pkt_data > pkt_meta', bad access 2")
1034 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1035 __flag(BPF_F_ANY_ALIGNMENT)
1036 __naked void pkt_meta_bad_access_2_1(void)
1037 {
1038 asm volatile (" \
1039 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1040 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1041 r1 = r2; \
1042 r1 += 8; \
1043 if r3 > r1 goto l0_%=; \
1044 r0 = *(u64*)(r1 - 8); \
1045 l0_%=: r0 = 0; \
1046 exit; \
1047 " :
1048 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1049 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1050 : __clobber_all);
1051 }
1052
1053 SEC("xdp")
1054 __description("XDP pkt read, pkt_data > pkt_meta', corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)1055 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1056 __naked void meta_corner_case_good_access_1(void)
1057 {
1058 asm volatile (" \
1059 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1060 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1061 r1 = r2; \
1062 r1 += 7; \
1063 if r3 > r1 goto l0_%=; \
1064 goto l1_%=; \
1065 l0_%=: r0 = *(u64*)(r1 - 7); \
1066 l1_%=: r0 = 0; \
1067 exit; \
1068 " :
1069 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1070 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1071 : __clobber_all);
1072 }
1073
1074 SEC("xdp")
1075 __description("XDP pkt read, pkt_data > pkt_meta', corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)1076 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1077 __naked void corner_case_1_good_access_10(void)
1078 {
1079 asm volatile (" \
1080 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1081 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1082 r1 = r2; \
1083 r1 += 8; \
1084 if r3 > r1 goto l0_%=; \
1085 goto l1_%=; \
1086 l0_%=: r0 = *(u64*)(r1 - 8); \
1087 l1_%=: r0 = 0; \
1088 exit; \
1089 " :
1090 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1091 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1092 : __clobber_all);
1093 }
1094
1095 SEC("xdp")
1096 __description("XDP pkt read, pkt_meta' < pkt_data, good access")
__flag(BPF_F_ANY_ALIGNMENT)1097 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1098 __naked void meta_pkt_data_good_access_1(void)
1099 {
1100 asm volatile (" \
1101 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1102 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1103 r1 = r2; \
1104 r1 += 8; \
1105 if r1 < r3 goto l0_%=; \
1106 goto l1_%=; \
1107 l0_%=: r0 = *(u32*)(r1 - 5); \
1108 l1_%=: r0 = 0; \
1109 exit; \
1110 " :
1111 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1112 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1113 : __clobber_all);
1114 }
1115
1116 SEC("xdp")
1117 __description("XDP pkt read, pkt_meta' < pkt_data, corner case -1, bad access")
1118 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1119 __flag(BPF_F_ANY_ALIGNMENT)
1120 __naked void corner_case_1_bad_access_11(void)
1121 {
1122 asm volatile (" \
1123 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1124 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1125 r1 = r2; \
1126 r1 += 6; \
1127 if r1 < r3 goto l0_%=; \
1128 goto l1_%=; \
1129 l0_%=: r0 = *(u64*)(r1 - 6); \
1130 l1_%=: r0 = 0; \
1131 exit; \
1132 " :
1133 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1134 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1135 : __clobber_all);
1136 }
1137
1138 SEC("xdp")
1139 __description("XDP pkt read, pkt_meta' < pkt_data, bad access 2")
1140 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1141 __flag(BPF_F_ANY_ALIGNMENT)
1142 __naked void pkt_data_bad_access_2_6(void)
1143 {
1144 asm volatile (" \
1145 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1146 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1147 r1 = r2; \
1148 r1 += 8; \
1149 if r1 < r3 goto l0_%=; \
1150 r0 = *(u64*)(r1 - 8); \
1151 l0_%=: r0 = 0; \
1152 exit; \
1153 " :
1154 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1155 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1156 : __clobber_all);
1157 }
1158
1159 SEC("xdp")
1160 __description("XDP pkt read, pkt_meta' < pkt_data, corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)1161 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1162 __naked void data_corner_case_good_access_6(void)
1163 {
1164 asm volatile (" \
1165 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1166 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1167 r1 = r2; \
1168 r1 += 7; \
1169 if r1 < r3 goto l0_%=; \
1170 goto l1_%=; \
1171 l0_%=: r0 = *(u64*)(r1 - 7); \
1172 l1_%=: r0 = 0; \
1173 exit; \
1174 " :
1175 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1176 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1177 : __clobber_all);
1178 }
1179
1180 SEC("xdp")
1181 __description("XDP pkt read, pkt_meta' < pkt_data, corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)1182 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1183 __naked void corner_case_1_good_access_11(void)
1184 {
1185 asm volatile (" \
1186 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1187 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1188 r1 = r2; \
1189 r1 += 8; \
1190 if r1 < r3 goto l0_%=; \
1191 goto l1_%=; \
1192 l0_%=: r0 = *(u64*)(r1 - 8); \
1193 l1_%=: r0 = 0; \
1194 exit; \
1195 " :
1196 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1197 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1198 : __clobber_all);
1199 }
1200
1201 SEC("xdp")
1202 __description("XDP pkt read, pkt_data < pkt_meta', corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)1203 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1204 __naked void meta_corner_case_good_access_2(void)
1205 {
1206 asm volatile (" \
1207 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1208 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1209 r1 = r2; \
1210 r1 += 8; \
1211 if r3 < r1 goto l0_%=; \
1212 r0 = *(u64*)(r1 - 8); \
1213 l0_%=: r0 = 0; \
1214 exit; \
1215 " :
1216 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1217 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1218 : __clobber_all);
1219 }
1220
1221 SEC("xdp")
1222 __description("XDP pkt read, pkt_data < pkt_meta', bad access 1")
1223 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1224 __flag(BPF_F_ANY_ALIGNMENT)
1225 __naked void pkt_meta_bad_access_1_1(void)
1226 {
1227 asm volatile (" \
1228 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1229 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1230 r1 = r2; \
1231 r1 += 8; \
1232 if r3 < r1 goto l0_%=; \
1233 r0 = *(u64*)(r1 - 4); \
1234 l0_%=: r0 = 0; \
1235 exit; \
1236 " :
1237 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1238 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1239 : __clobber_all);
1240 }
1241
1242 SEC("xdp")
1243 __description("XDP pkt read, pkt_data < pkt_meta', bad access 2")
1244 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1245 __flag(BPF_F_ANY_ALIGNMENT)
1246 __naked void pkt_meta_bad_access_2_2(void)
1247 {
1248 asm volatile (" \
1249 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1250 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1251 r1 = r2; \
1252 r1 += 8; \
1253 if r3 < r1 goto l0_%=; \
1254 l0_%=: r0 = *(u64*)(r1 - 8); \
1255 r0 = 0; \
1256 exit; \
1257 " :
1258 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1259 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1260 : __clobber_all);
1261 }
1262
1263 SEC("xdp")
1264 __description("XDP pkt read, pkt_data < pkt_meta', corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)1265 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1266 __naked void corner_case_1_good_access_12(void)
1267 {
1268 asm volatile (" \
1269 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1270 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1271 r1 = r2; \
1272 r1 += 9; \
1273 if r3 < r1 goto l0_%=; \
1274 r0 = *(u64*)(r1 - 9); \
1275 l0_%=: r0 = 0; \
1276 exit; \
1277 " :
1278 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1279 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1280 : __clobber_all);
1281 }
1282
1283 SEC("xdp")
1284 __description("XDP pkt read, pkt_data < pkt_meta', corner case -1, bad access")
1285 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1286 __flag(BPF_F_ANY_ALIGNMENT)
1287 __naked void corner_case_1_bad_access_12(void)
1288 {
1289 asm volatile (" \
1290 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1291 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1292 r1 = r2; \
1293 r1 += 7; \
1294 if r3 < r1 goto l0_%=; \
1295 r0 = *(u64*)(r1 - 7); \
1296 l0_%=: r0 = 0; \
1297 exit; \
1298 " :
1299 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1300 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1301 : __clobber_all);
1302 }
1303
1304 SEC("xdp")
1305 __description("XDP pkt read, pkt_meta' >= pkt_data, good access")
__flag(BPF_F_ANY_ALIGNMENT)1306 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1307 __naked void meta_pkt_data_good_access_2(void)
1308 {
1309 asm volatile (" \
1310 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1311 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1312 r1 = r2; \
1313 r1 += 8; \
1314 if r1 >= r3 goto l0_%=; \
1315 r0 = *(u32*)(r1 - 5); \
1316 l0_%=: r0 = 0; \
1317 exit; \
1318 " :
1319 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1320 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1321 : __clobber_all);
1322 }
1323
1324 SEC("xdp")
1325 __description("XDP pkt read, pkt_meta' >= pkt_data, corner case -1, bad access")
1326 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1327 __flag(BPF_F_ANY_ALIGNMENT)
1328 __naked void corner_case_1_bad_access_13(void)
1329 {
1330 asm volatile (" \
1331 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1332 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1333 r1 = r2; \
1334 r1 += 6; \
1335 if r1 >= r3 goto l0_%=; \
1336 r0 = *(u64*)(r1 - 6); \
1337 l0_%=: r0 = 0; \
1338 exit; \
1339 " :
1340 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1341 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1342 : __clobber_all);
1343 }
1344
1345 SEC("xdp")
1346 __description("XDP pkt read, pkt_meta' >= pkt_data, bad access 2")
1347 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1348 __flag(BPF_F_ANY_ALIGNMENT)
1349 __naked void pkt_data_bad_access_2_7(void)
1350 {
1351 asm volatile (" \
1352 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1353 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1354 r1 = r2; \
1355 r1 += 8; \
1356 if r1 >= r3 goto l0_%=; \
1357 l0_%=: r0 = *(u32*)(r1 - 5); \
1358 r0 = 0; \
1359 exit; \
1360 " :
1361 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1362 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1363 : __clobber_all);
1364 }
1365
1366 SEC("xdp")
1367 __description("XDP pkt read, pkt_meta' >= pkt_data, corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)1368 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1369 __naked void data_corner_case_good_access_7(void)
1370 {
1371 asm volatile (" \
1372 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1373 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1374 r1 = r2; \
1375 r1 += 7; \
1376 if r1 >= r3 goto l0_%=; \
1377 r0 = *(u64*)(r1 - 7); \
1378 l0_%=: r0 = 0; \
1379 exit; \
1380 " :
1381 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1382 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1383 : __clobber_all);
1384 }
1385
1386 SEC("xdp")
1387 __description("XDP pkt read, pkt_meta' >= pkt_data, corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)1388 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1389 __naked void corner_case_1_good_access_13(void)
1390 {
1391 asm volatile (" \
1392 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1393 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1394 r1 = r2; \
1395 r1 += 8; \
1396 if r1 >= r3 goto l0_%=; \
1397 r0 = *(u64*)(r1 - 8); \
1398 l0_%=: r0 = 0; \
1399 exit; \
1400 " :
1401 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1402 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1403 : __clobber_all);
1404 }
1405
1406 SEC("xdp")
1407 __description("XDP pkt read, pkt_data >= pkt_meta', corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)1408 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1409 __naked void meta_corner_case_good_access_3(void)
1410 {
1411 asm volatile (" \
1412 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1413 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1414 r1 = r2; \
1415 r1 += 8; \
1416 if r3 >= r1 goto l0_%=; \
1417 goto l1_%=; \
1418 l0_%=: r0 = *(u64*)(r1 - 8); \
1419 l1_%=: r0 = 0; \
1420 exit; \
1421 " :
1422 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1423 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1424 : __clobber_all);
1425 }
1426
1427 SEC("xdp")
1428 __description("XDP pkt read, pkt_data >= pkt_meta', bad access 1")
1429 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1430 __flag(BPF_F_ANY_ALIGNMENT)
1431 __naked void pkt_meta_bad_access_1_2(void)
1432 {
1433 asm volatile (" \
1434 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1435 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1436 r1 = r2; \
1437 r1 += 8; \
1438 if r3 >= r1 goto l0_%=; \
1439 goto l1_%=; \
1440 l0_%=: r0 = *(u64*)(r1 - 4); \
1441 l1_%=: r0 = 0; \
1442 exit; \
1443 " :
1444 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1445 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1446 : __clobber_all);
1447 }
1448
1449 SEC("xdp")
1450 __description("XDP pkt read, pkt_data >= pkt_meta', bad access 2")
1451 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1452 __flag(BPF_F_ANY_ALIGNMENT)
1453 __naked void pkt_meta_bad_access_2_3(void)
1454 {
1455 asm volatile (" \
1456 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1457 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1458 r1 = r2; \
1459 r1 += 8; \
1460 if r3 >= r1 goto l0_%=; \
1461 r0 = *(u64*)(r1 - 8); \
1462 l0_%=: r0 = 0; \
1463 exit; \
1464 " :
1465 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1466 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1467 : __clobber_all);
1468 }
1469
1470 SEC("xdp")
1471 __description("XDP pkt read, pkt_data >= pkt_meta', corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)1472 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1473 __naked void corner_case_1_good_access_14(void)
1474 {
1475 asm volatile (" \
1476 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1477 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1478 r1 = r2; \
1479 r1 += 9; \
1480 if r3 >= r1 goto l0_%=; \
1481 goto l1_%=; \
1482 l0_%=: r0 = *(u64*)(r1 - 9); \
1483 l1_%=: r0 = 0; \
1484 exit; \
1485 " :
1486 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1487 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1488 : __clobber_all);
1489 }
1490
1491 SEC("xdp")
1492 __description("XDP pkt read, pkt_data >= pkt_meta', corner case -1, bad access")
1493 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1494 __flag(BPF_F_ANY_ALIGNMENT)
1495 __naked void corner_case_1_bad_access_14(void)
1496 {
1497 asm volatile (" \
1498 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1499 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1500 r1 = r2; \
1501 r1 += 7; \
1502 if r3 >= r1 goto l0_%=; \
1503 goto l1_%=; \
1504 l0_%=: r0 = *(u64*)(r1 - 7); \
1505 l1_%=: r0 = 0; \
1506 exit; \
1507 " :
1508 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1509 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1510 : __clobber_all);
1511 }
1512
1513 SEC("xdp")
1514 __description("XDP pkt read, pkt_meta' <= pkt_data, corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)1515 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1516 __naked void data_corner_case_good_access_8(void)
1517 {
1518 asm volatile (" \
1519 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1520 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1521 r1 = r2; \
1522 r1 += 8; \
1523 if r1 <= r3 goto l0_%=; \
1524 goto l1_%=; \
1525 l0_%=: r0 = *(u64*)(r1 - 8); \
1526 l1_%=: r0 = 0; \
1527 exit; \
1528 " :
1529 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1530 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1531 : __clobber_all);
1532 }
1533
1534 SEC("xdp")
1535 __description("XDP pkt read, pkt_meta' <= pkt_data, bad access 1")
1536 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1537 __flag(BPF_F_ANY_ALIGNMENT)
1538 __naked void pkt_data_bad_access_1_4(void)
1539 {
1540 asm volatile (" \
1541 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1542 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1543 r1 = r2; \
1544 r1 += 8; \
1545 if r1 <= r3 goto l0_%=; \
1546 goto l1_%=; \
1547 l0_%=: r0 = *(u64*)(r1 - 4); \
1548 l1_%=: r0 = 0; \
1549 exit; \
1550 " :
1551 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1552 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1553 : __clobber_all);
1554 }
1555
1556 SEC("xdp")
1557 __description("XDP pkt read, pkt_meta' <= pkt_data, bad access 2")
1558 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1559 __flag(BPF_F_ANY_ALIGNMENT)
1560 __naked void pkt_data_bad_access_2_8(void)
1561 {
1562 asm volatile (" \
1563 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1564 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1565 r1 = r2; \
1566 r1 += 8; \
1567 if r1 <= r3 goto l0_%=; \
1568 r0 = *(u64*)(r1 - 8); \
1569 l0_%=: r0 = 0; \
1570 exit; \
1571 " :
1572 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1573 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1574 : __clobber_all);
1575 }
1576
1577 SEC("xdp")
1578 __description("XDP pkt read, pkt_meta' <= pkt_data, corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)1579 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1580 __naked void corner_case_1_good_access_15(void)
1581 {
1582 asm volatile (" \
1583 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1584 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1585 r1 = r2; \
1586 r1 += 9; \
1587 if r1 <= r3 goto l0_%=; \
1588 goto l1_%=; \
1589 l0_%=: r0 = *(u64*)(r1 - 9); \
1590 l1_%=: r0 = 0; \
1591 exit; \
1592 " :
1593 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1594 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1595 : __clobber_all);
1596 }
1597
1598 SEC("xdp")
1599 __description("XDP pkt read, pkt_meta' <= pkt_data, corner case -1, bad access")
1600 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1601 __flag(BPF_F_ANY_ALIGNMENT)
1602 __naked void corner_case_1_bad_access_15(void)
1603 {
1604 asm volatile (" \
1605 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1606 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1607 r1 = r2; \
1608 r1 += 7; \
1609 if r1 <= r3 goto l0_%=; \
1610 goto l1_%=; \
1611 l0_%=: r0 = *(u64*)(r1 - 7); \
1612 l1_%=: r0 = 0; \
1613 exit; \
1614 " :
1615 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1616 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1617 : __clobber_all);
1618 }
1619
1620 SEC("xdp")
1621 __description("XDP pkt read, pkt_data <= pkt_meta', good access")
__flag(BPF_F_ANY_ALIGNMENT)1622 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1623 __naked void data_pkt_meta_good_access_2(void)
1624 {
1625 asm volatile (" \
1626 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1627 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1628 r1 = r2; \
1629 r1 += 8; \
1630 if r3 <= r1 goto l0_%=; \
1631 r0 = *(u32*)(r1 - 5); \
1632 l0_%=: r0 = 0; \
1633 exit; \
1634 " :
1635 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1636 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1637 : __clobber_all);
1638 }
1639
1640 SEC("xdp")
1641 __description("XDP pkt read, pkt_data <= pkt_meta', corner case -1, bad access")
1642 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1643 __flag(BPF_F_ANY_ALIGNMENT)
1644 __naked void corner_case_1_bad_access_16(void)
1645 {
1646 asm volatile (" \
1647 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1648 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1649 r1 = r2; \
1650 r1 += 6; \
1651 if r3 <= r1 goto l0_%=; \
1652 r0 = *(u64*)(r1 - 6); \
1653 l0_%=: r0 = 0; \
1654 exit; \
1655 " :
1656 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1657 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1658 : __clobber_all);
1659 }
1660
1661 SEC("xdp")
1662 __description("XDP pkt read, pkt_data <= pkt_meta', bad access 2")
1663 __failure __msg("R1 offset is outside of the packet")
__flag(BPF_F_ANY_ALIGNMENT)1664 __flag(BPF_F_ANY_ALIGNMENT)
1665 __naked void pkt_meta_bad_access_2_4(void)
1666 {
1667 asm volatile (" \
1668 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1669 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1670 r1 = r2; \
1671 r1 += 8; \
1672 if r3 <= r1 goto l0_%=; \
1673 l0_%=: r0 = *(u32*)(r1 - 5); \
1674 r0 = 0; \
1675 exit; \
1676 " :
1677 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1678 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1679 : __clobber_all);
1680 }
1681
1682 SEC("xdp")
1683 __description("XDP pkt read, pkt_data <= pkt_meta', corner case, good access")
__flag(BPF_F_ANY_ALIGNMENT)1684 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1685 __naked void meta_corner_case_good_access_4(void)
1686 {
1687 asm volatile (" \
1688 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1689 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1690 r1 = r2; \
1691 r1 += 7; \
1692 if r3 <= r1 goto l0_%=; \
1693 r0 = *(u64*)(r1 - 7); \
1694 l0_%=: r0 = 0; \
1695 exit; \
1696 " :
1697 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1698 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1699 : __clobber_all);
1700 }
1701
1702 SEC("xdp")
1703 __description("XDP pkt read, pkt_data <= pkt_meta', corner case +1, good access")
__flag(BPF_F_ANY_ALIGNMENT)1704 __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1705 __naked void corner_case_1_good_access_16(void)
1706 {
1707 asm volatile (" \
1708 r2 = *(u32*)(r1 + %[xdp_md_data_meta]); \
1709 r3 = *(u32*)(r1 + %[xdp_md_data]); \
1710 r1 = r2; \
1711 r1 += 8; \
1712 if r3 <= r1 goto l0_%=; \
1713 r0 = *(u64*)(r1 - 8); \
1714 l0_%=: r0 = 0; \
1715 exit; \
1716 " :
1717 : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
1718 __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
1719 : __clobber_all);
1720 }
1721
1722 char _license[] SEC("license") = "GPL";
1723