1 /*
2 * Testsuite for BPF interpreter and BPF JIT compiler
3 *
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/filter.h>
21 #include <linux/bpf.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/if_vlan.h>
25 #include <linux/random.h>
26 #include <linux/highmem.h>
27
28 /* General test specific settings */
29 #define MAX_SUBTESTS 3
30 #define MAX_TESTRUNS 10000
31 #define MAX_DATA 128
32 #define MAX_INSNS 512
33 #define MAX_K 0xffffFFFF
34
35 /* Few constants used to init test 'skb' */
36 #define SKB_TYPE 3
37 #define SKB_MARK 0x1234aaaa
38 #define SKB_HASH 0x1234aaab
39 #define SKB_QUEUE_MAP 123
40 #define SKB_VLAN_TCI 0xffff
41 #define SKB_DEV_IFINDEX 577
42 #define SKB_DEV_TYPE 588
43
44 /* Redefine REGs to make tests less verbose */
45 #define R0 BPF_REG_0
46 #define R1 BPF_REG_1
47 #define R2 BPF_REG_2
48 #define R3 BPF_REG_3
49 #define R4 BPF_REG_4
50 #define R5 BPF_REG_5
51 #define R6 BPF_REG_6
52 #define R7 BPF_REG_7
53 #define R8 BPF_REG_8
54 #define R9 BPF_REG_9
55 #define R10 BPF_REG_10
56
57 /* Flags that can be passed to test cases */
58 #define FLAG_NO_DATA BIT(0)
59 #define FLAG_EXPECTED_FAIL BIT(1)
60 #define FLAG_SKB_FRAG BIT(2)
61
62 enum {
63 CLASSIC = BIT(6), /* Old BPF instructions only. */
64 INTERNAL = BIT(7), /* Extended instruction set. */
65 };
66
67 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
68
69 struct bpf_test {
70 const char *descr;
71 union {
72 struct sock_filter insns[MAX_INSNS];
73 struct bpf_insn insns_int[MAX_INSNS];
74 struct {
75 void *insns;
76 unsigned int len;
77 } ptr;
78 } u;
79 __u8 aux;
80 __u8 data[MAX_DATA];
81 struct {
82 int data_size;
83 __u32 result;
84 } test[MAX_SUBTESTS];
85 int (*fill_helper)(struct bpf_test *self);
86 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
87 __u8 frag_data[MAX_DATA];
88 };
89
90 /* Large test cases need separate allocation and fill handler. */
91
bpf_fill_maxinsns1(struct bpf_test * self)92 static int bpf_fill_maxinsns1(struct bpf_test *self)
93 {
94 unsigned int len = BPF_MAXINSNS;
95 struct sock_filter *insn;
96 __u32 k = ~0;
97 int i;
98
99 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
100 if (!insn)
101 return -ENOMEM;
102
103 for (i = 0; i < len; i++, k--)
104 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
105
106 self->u.ptr.insns = insn;
107 self->u.ptr.len = len;
108
109 return 0;
110 }
111
bpf_fill_maxinsns2(struct bpf_test * self)112 static int bpf_fill_maxinsns2(struct bpf_test *self)
113 {
114 unsigned int len = BPF_MAXINSNS;
115 struct sock_filter *insn;
116 int i;
117
118 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
119 if (!insn)
120 return -ENOMEM;
121
122 for (i = 0; i < len; i++)
123 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
124
125 self->u.ptr.insns = insn;
126 self->u.ptr.len = len;
127
128 return 0;
129 }
130
bpf_fill_maxinsns3(struct bpf_test * self)131 static int bpf_fill_maxinsns3(struct bpf_test *self)
132 {
133 unsigned int len = BPF_MAXINSNS;
134 struct sock_filter *insn;
135 struct rnd_state rnd;
136 int i;
137
138 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
139 if (!insn)
140 return -ENOMEM;
141
142 prandom_seed_state(&rnd, 3141592653589793238ULL);
143
144 for (i = 0; i < len - 1; i++) {
145 __u32 k = prandom_u32_state(&rnd);
146
147 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
148 }
149
150 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
151
152 self->u.ptr.insns = insn;
153 self->u.ptr.len = len;
154
155 return 0;
156 }
157
bpf_fill_maxinsns4(struct bpf_test * self)158 static int bpf_fill_maxinsns4(struct bpf_test *self)
159 {
160 unsigned int len = BPF_MAXINSNS + 1;
161 struct sock_filter *insn;
162 int i;
163
164 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
165 if (!insn)
166 return -ENOMEM;
167
168 for (i = 0; i < len; i++)
169 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
170
171 self->u.ptr.insns = insn;
172 self->u.ptr.len = len;
173
174 return 0;
175 }
176
bpf_fill_maxinsns5(struct bpf_test * self)177 static int bpf_fill_maxinsns5(struct bpf_test *self)
178 {
179 unsigned int len = BPF_MAXINSNS;
180 struct sock_filter *insn;
181 int i;
182
183 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
184 if (!insn)
185 return -ENOMEM;
186
187 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
188
189 for (i = 1; i < len - 1; i++)
190 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
191
192 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
193
194 self->u.ptr.insns = insn;
195 self->u.ptr.len = len;
196
197 return 0;
198 }
199
bpf_fill_maxinsns6(struct bpf_test * self)200 static int bpf_fill_maxinsns6(struct bpf_test *self)
201 {
202 unsigned int len = BPF_MAXINSNS;
203 struct sock_filter *insn;
204 int i;
205
206 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
207 if (!insn)
208 return -ENOMEM;
209
210 for (i = 0; i < len - 1; i++)
211 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
212 SKF_AD_VLAN_TAG_PRESENT);
213
214 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
215
216 self->u.ptr.insns = insn;
217 self->u.ptr.len = len;
218
219 return 0;
220 }
221
bpf_fill_maxinsns7(struct bpf_test * self)222 static int bpf_fill_maxinsns7(struct bpf_test *self)
223 {
224 unsigned int len = BPF_MAXINSNS;
225 struct sock_filter *insn;
226 int i;
227
228 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
229 if (!insn)
230 return -ENOMEM;
231
232 for (i = 0; i < len - 4; i++)
233 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
234 SKF_AD_CPU);
235
236 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
237 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
238 SKF_AD_CPU);
239 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
240 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
241
242 self->u.ptr.insns = insn;
243 self->u.ptr.len = len;
244
245 return 0;
246 }
247
bpf_fill_maxinsns8(struct bpf_test * self)248 static int bpf_fill_maxinsns8(struct bpf_test *self)
249 {
250 unsigned int len = BPF_MAXINSNS;
251 struct sock_filter *insn;
252 int i, jmp_off = len - 3;
253
254 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
255 if (!insn)
256 return -ENOMEM;
257
258 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
259
260 for (i = 1; i < len - 1; i++)
261 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
262
263 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
264
265 self->u.ptr.insns = insn;
266 self->u.ptr.len = len;
267
268 return 0;
269 }
270
bpf_fill_maxinsns9(struct bpf_test * self)271 static int bpf_fill_maxinsns9(struct bpf_test *self)
272 {
273 unsigned int len = BPF_MAXINSNS;
274 struct bpf_insn *insn;
275 int i;
276
277 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
278 if (!insn)
279 return -ENOMEM;
280
281 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
282 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
283 insn[2] = BPF_EXIT_INSN();
284
285 for (i = 3; i < len - 2; i++)
286 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
287
288 insn[len - 2] = BPF_EXIT_INSN();
289 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
290
291 self->u.ptr.insns = insn;
292 self->u.ptr.len = len;
293
294 return 0;
295 }
296
bpf_fill_maxinsns10(struct bpf_test * self)297 static int bpf_fill_maxinsns10(struct bpf_test *self)
298 {
299 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
300 struct bpf_insn *insn;
301 int i;
302
303 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
304 if (!insn)
305 return -ENOMEM;
306
307 for (i = 0; i < hlen / 2; i++)
308 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
309 for (i = hlen - 1; i > hlen / 2; i--)
310 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
311
312 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
313 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
314 insn[hlen + 1] = BPF_EXIT_INSN();
315
316 self->u.ptr.insns = insn;
317 self->u.ptr.len = len;
318
319 return 0;
320 }
321
__bpf_fill_ja(struct bpf_test * self,unsigned int len,unsigned int plen)322 static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
323 unsigned int plen)
324 {
325 struct sock_filter *insn;
326 unsigned int rlen;
327 int i, j;
328
329 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
330 if (!insn)
331 return -ENOMEM;
332
333 rlen = (len % plen) - 1;
334
335 for (i = 0; i + plen < len; i += plen)
336 for (j = 0; j < plen; j++)
337 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
338 plen - 1 - j, 0, 0);
339 for (j = 0; j < rlen; j++)
340 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
341 0, 0);
342
343 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
344
345 self->u.ptr.insns = insn;
346 self->u.ptr.len = len;
347
348 return 0;
349 }
350
bpf_fill_maxinsns11(struct bpf_test * self)351 static int bpf_fill_maxinsns11(struct bpf_test *self)
352 {
353 /* Hits 70 passes on x86_64, so cannot get JITed there. */
354 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
355 }
356
bpf_fill_ja(struct bpf_test * self)357 static int bpf_fill_ja(struct bpf_test *self)
358 {
359 /* Hits exactly 11 passes on x86_64 JIT. */
360 return __bpf_fill_ja(self, 12, 9);
361 }
362
bpf_fill_ld_abs_get_processor_id(struct bpf_test * self)363 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
364 {
365 unsigned int len = BPF_MAXINSNS;
366 struct sock_filter *insn;
367 int i;
368
369 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
370 if (!insn)
371 return -ENOMEM;
372
373 for (i = 0; i < len - 1; i += 2) {
374 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
375 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
376 SKF_AD_OFF + SKF_AD_CPU);
377 }
378
379 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
380
381 self->u.ptr.insns = insn;
382 self->u.ptr.len = len;
383
384 return 0;
385 }
386
387 #define PUSH_CNT 68
388 /* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
bpf_fill_ld_abs_vlan_push_pop(struct bpf_test * self)389 static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
390 {
391 unsigned int len = BPF_MAXINSNS;
392 struct bpf_insn *insn;
393 int i = 0, j, k = 0;
394
395 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
396 if (!insn)
397 return -ENOMEM;
398
399 insn[i++] = BPF_MOV64_REG(R6, R1);
400 loop:
401 for (j = 0; j < PUSH_CNT; j++) {
402 insn[i++] = BPF_LD_ABS(BPF_B, 0);
403 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
404 i++;
405 insn[i++] = BPF_MOV64_REG(R1, R6);
406 insn[i++] = BPF_MOV64_IMM(R2, 1);
407 insn[i++] = BPF_MOV64_IMM(R3, 2);
408 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
409 bpf_skb_vlan_push_proto.func - __bpf_call_base);
410 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
411 i++;
412 }
413
414 for (j = 0; j < PUSH_CNT; j++) {
415 insn[i++] = BPF_LD_ABS(BPF_B, 0);
416 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
417 i++;
418 insn[i++] = BPF_MOV64_REG(R1, R6);
419 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
420 bpf_skb_vlan_pop_proto.func - __bpf_call_base);
421 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
422 i++;
423 }
424 if (++k < 5)
425 goto loop;
426
427 for (; i < len - 1; i++)
428 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xbef);
429
430 insn[len - 1] = BPF_EXIT_INSN();
431
432 self->u.ptr.insns = insn;
433 self->u.ptr.len = len;
434
435 return 0;
436 }
437
438 static struct bpf_test tests[] = {
439 {
440 "TAX",
441 .u.insns = {
442 BPF_STMT(BPF_LD | BPF_IMM, 1),
443 BPF_STMT(BPF_MISC | BPF_TAX, 0),
444 BPF_STMT(BPF_LD | BPF_IMM, 2),
445 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
446 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
447 BPF_STMT(BPF_MISC | BPF_TAX, 0),
448 BPF_STMT(BPF_LD | BPF_LEN, 0),
449 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
450 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
451 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
452 BPF_STMT(BPF_RET | BPF_A, 0)
453 },
454 CLASSIC,
455 { 10, 20, 30, 40, 50 },
456 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
457 },
458 {
459 "TXA",
460 .u.insns = {
461 BPF_STMT(BPF_LDX | BPF_LEN, 0),
462 BPF_STMT(BPF_MISC | BPF_TXA, 0),
463 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
464 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
465 },
466 CLASSIC,
467 { 10, 20, 30, 40, 50 },
468 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
469 },
470 {
471 "ADD_SUB_MUL_K",
472 .u.insns = {
473 BPF_STMT(BPF_LD | BPF_IMM, 1),
474 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
475 BPF_STMT(BPF_LDX | BPF_IMM, 3),
476 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
477 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
478 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
479 BPF_STMT(BPF_RET | BPF_A, 0)
480 },
481 CLASSIC | FLAG_NO_DATA,
482 { },
483 { { 0, 0xfffffffd } }
484 },
485 {
486 "DIV_MOD_KX",
487 .u.insns = {
488 BPF_STMT(BPF_LD | BPF_IMM, 8),
489 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
490 BPF_STMT(BPF_MISC | BPF_TAX, 0),
491 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
492 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
493 BPF_STMT(BPF_MISC | BPF_TAX, 0),
494 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
495 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
496 BPF_STMT(BPF_MISC | BPF_TAX, 0),
497 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
498 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
499 BPF_STMT(BPF_MISC | BPF_TAX, 0),
500 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
501 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
502 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
503 BPF_STMT(BPF_RET | BPF_A, 0)
504 },
505 CLASSIC | FLAG_NO_DATA,
506 { },
507 { { 0, 0x20000000 } }
508 },
509 {
510 "AND_OR_LSH_K",
511 .u.insns = {
512 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
513 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
514 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
515 BPF_STMT(BPF_MISC | BPF_TAX, 0),
516 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
517 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
518 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
519 BPF_STMT(BPF_RET | BPF_A, 0)
520 },
521 CLASSIC | FLAG_NO_DATA,
522 { },
523 { { 0, 0x800000ff }, { 1, 0x800000ff } },
524 },
525 {
526 "LD_IMM_0",
527 .u.insns = {
528 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
529 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
530 BPF_STMT(BPF_RET | BPF_K, 0),
531 BPF_STMT(BPF_RET | BPF_K, 1),
532 },
533 CLASSIC,
534 { },
535 { { 1, 1 } },
536 },
537 {
538 "LD_IND",
539 .u.insns = {
540 BPF_STMT(BPF_LDX | BPF_LEN, 0),
541 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
542 BPF_STMT(BPF_RET | BPF_K, 1)
543 },
544 CLASSIC,
545 { },
546 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
547 },
548 {
549 "LD_ABS",
550 .u.insns = {
551 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
552 BPF_STMT(BPF_RET | BPF_K, 1)
553 },
554 CLASSIC,
555 { },
556 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
557 },
558 {
559 "LD_ABS_LL",
560 .u.insns = {
561 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
562 BPF_STMT(BPF_MISC | BPF_TAX, 0),
563 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
564 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
565 BPF_STMT(BPF_RET | BPF_A, 0)
566 },
567 CLASSIC,
568 { 1, 2, 3 },
569 { { 1, 0 }, { 2, 3 } },
570 },
571 {
572 "LD_IND_LL",
573 .u.insns = {
574 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
575 BPF_STMT(BPF_LDX | BPF_LEN, 0),
576 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
577 BPF_STMT(BPF_MISC | BPF_TAX, 0),
578 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
579 BPF_STMT(BPF_RET | BPF_A, 0)
580 },
581 CLASSIC,
582 { 1, 2, 3, 0xff },
583 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
584 },
585 {
586 "LD_ABS_NET",
587 .u.insns = {
588 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
589 BPF_STMT(BPF_MISC | BPF_TAX, 0),
590 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
591 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
592 BPF_STMT(BPF_RET | BPF_A, 0)
593 },
594 CLASSIC,
595 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
596 { { 15, 0 }, { 16, 3 } },
597 },
598 {
599 "LD_IND_NET",
600 .u.insns = {
601 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
602 BPF_STMT(BPF_LDX | BPF_LEN, 0),
603 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
604 BPF_STMT(BPF_MISC | BPF_TAX, 0),
605 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
606 BPF_STMT(BPF_RET | BPF_A, 0)
607 },
608 CLASSIC,
609 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
610 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
611 },
612 {
613 "LD_PKTTYPE",
614 .u.insns = {
615 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
616 SKF_AD_OFF + SKF_AD_PKTTYPE),
617 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
618 BPF_STMT(BPF_RET | BPF_K, 1),
619 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
620 SKF_AD_OFF + SKF_AD_PKTTYPE),
621 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
622 BPF_STMT(BPF_RET | BPF_K, 1),
623 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
624 SKF_AD_OFF + SKF_AD_PKTTYPE),
625 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
626 BPF_STMT(BPF_RET | BPF_K, 1),
627 BPF_STMT(BPF_RET | BPF_A, 0)
628 },
629 CLASSIC,
630 { },
631 { { 1, 3 }, { 10, 3 } },
632 },
633 {
634 "LD_MARK",
635 .u.insns = {
636 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
637 SKF_AD_OFF + SKF_AD_MARK),
638 BPF_STMT(BPF_RET | BPF_A, 0)
639 },
640 CLASSIC,
641 { },
642 { { 1, SKB_MARK}, { 10, SKB_MARK} },
643 },
644 {
645 "LD_RXHASH",
646 .u.insns = {
647 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
648 SKF_AD_OFF + SKF_AD_RXHASH),
649 BPF_STMT(BPF_RET | BPF_A, 0)
650 },
651 CLASSIC,
652 { },
653 { { 1, SKB_HASH}, { 10, SKB_HASH} },
654 },
655 {
656 "LD_QUEUE",
657 .u.insns = {
658 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
659 SKF_AD_OFF + SKF_AD_QUEUE),
660 BPF_STMT(BPF_RET | BPF_A, 0)
661 },
662 CLASSIC,
663 { },
664 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
665 },
666 {
667 "LD_PROTOCOL",
668 .u.insns = {
669 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
670 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
671 BPF_STMT(BPF_RET | BPF_K, 0),
672 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
673 SKF_AD_OFF + SKF_AD_PROTOCOL),
674 BPF_STMT(BPF_MISC | BPF_TAX, 0),
675 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
676 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
677 BPF_STMT(BPF_RET | BPF_K, 0),
678 BPF_STMT(BPF_MISC | BPF_TXA, 0),
679 BPF_STMT(BPF_RET | BPF_A, 0)
680 },
681 CLASSIC,
682 { 10, 20, 30 },
683 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
684 },
685 {
686 "LD_VLAN_TAG",
687 .u.insns = {
688 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
689 SKF_AD_OFF + SKF_AD_VLAN_TAG),
690 BPF_STMT(BPF_RET | BPF_A, 0)
691 },
692 CLASSIC,
693 { },
694 {
695 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
696 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
697 },
698 },
699 {
700 "LD_VLAN_TAG_PRESENT",
701 .u.insns = {
702 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
703 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
704 BPF_STMT(BPF_RET | BPF_A, 0)
705 },
706 CLASSIC,
707 { },
708 {
709 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
710 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
711 },
712 },
713 {
714 "LD_IFINDEX",
715 .u.insns = {
716 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
717 SKF_AD_OFF + SKF_AD_IFINDEX),
718 BPF_STMT(BPF_RET | BPF_A, 0)
719 },
720 CLASSIC,
721 { },
722 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
723 },
724 {
725 "LD_HATYPE",
726 .u.insns = {
727 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
728 SKF_AD_OFF + SKF_AD_HATYPE),
729 BPF_STMT(BPF_RET | BPF_A, 0)
730 },
731 CLASSIC,
732 { },
733 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
734 },
735 {
736 "LD_CPU",
737 .u.insns = {
738 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
739 SKF_AD_OFF + SKF_AD_CPU),
740 BPF_STMT(BPF_MISC | BPF_TAX, 0),
741 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
742 SKF_AD_OFF + SKF_AD_CPU),
743 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
744 BPF_STMT(BPF_RET | BPF_A, 0)
745 },
746 CLASSIC,
747 { },
748 { { 1, 0 }, { 10, 0 } },
749 },
750 {
751 "LD_NLATTR",
752 .u.insns = {
753 BPF_STMT(BPF_LDX | BPF_IMM, 2),
754 BPF_STMT(BPF_MISC | BPF_TXA, 0),
755 BPF_STMT(BPF_LDX | BPF_IMM, 3),
756 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
757 SKF_AD_OFF + SKF_AD_NLATTR),
758 BPF_STMT(BPF_RET | BPF_A, 0)
759 },
760 CLASSIC,
761 #ifdef __BIG_ENDIAN
762 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
763 #else
764 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
765 #endif
766 { { 4, 0 }, { 20, 6 } },
767 },
768 {
769 "LD_NLATTR_NEST",
770 .u.insns = {
771 BPF_STMT(BPF_LD | BPF_IMM, 2),
772 BPF_STMT(BPF_LDX | BPF_IMM, 3),
773 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
774 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
775 BPF_STMT(BPF_LD | BPF_IMM, 2),
776 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
777 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
778 BPF_STMT(BPF_LD | BPF_IMM, 2),
779 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
780 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
781 BPF_STMT(BPF_LD | BPF_IMM, 2),
782 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
783 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
784 BPF_STMT(BPF_LD | BPF_IMM, 2),
785 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
786 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
787 BPF_STMT(BPF_LD | BPF_IMM, 2),
788 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
789 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
790 BPF_STMT(BPF_LD | BPF_IMM, 2),
791 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
792 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
793 BPF_STMT(BPF_LD | BPF_IMM, 2),
794 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
795 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
796 BPF_STMT(BPF_RET | BPF_A, 0)
797 },
798 CLASSIC,
799 #ifdef __BIG_ENDIAN
800 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
801 #else
802 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
803 #endif
804 { { 4, 0 }, { 20, 10 } },
805 },
806 {
807 "LD_PAYLOAD_OFF",
808 .u.insns = {
809 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
810 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
811 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
812 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
813 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
814 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
815 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
816 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
817 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
818 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
819 BPF_STMT(BPF_RET | BPF_A, 0)
820 },
821 CLASSIC,
822 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
823 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
824 * id 9737, seq 1, length 64
825 */
826 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
827 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
828 0x08, 0x00,
829 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
830 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
831 { { 30, 0 }, { 100, 42 } },
832 },
833 {
834 "LD_ANC_XOR",
835 .u.insns = {
836 BPF_STMT(BPF_LD | BPF_IMM, 10),
837 BPF_STMT(BPF_LDX | BPF_IMM, 300),
838 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
839 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
840 BPF_STMT(BPF_RET | BPF_A, 0)
841 },
842 CLASSIC,
843 { },
844 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
845 },
846 {
847 "SPILL_FILL",
848 .u.insns = {
849 BPF_STMT(BPF_LDX | BPF_LEN, 0),
850 BPF_STMT(BPF_LD | BPF_IMM, 2),
851 BPF_STMT(BPF_ALU | BPF_RSH, 1),
852 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
853 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
854 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
855 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
856 BPF_STMT(BPF_STX, 15), /* M3 = len */
857 BPF_STMT(BPF_LDX | BPF_MEM, 1),
858 BPF_STMT(BPF_LD | BPF_MEM, 2),
859 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
860 BPF_STMT(BPF_LDX | BPF_MEM, 15),
861 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
862 BPF_STMT(BPF_RET | BPF_A, 0)
863 },
864 CLASSIC,
865 { },
866 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
867 },
868 {
869 "JEQ",
870 .u.insns = {
871 BPF_STMT(BPF_LDX | BPF_LEN, 0),
872 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
873 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
874 BPF_STMT(BPF_RET | BPF_K, 1),
875 BPF_STMT(BPF_RET | BPF_K, MAX_K)
876 },
877 CLASSIC,
878 { 3, 3, 3, 3, 3 },
879 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
880 },
881 {
882 "JGT",
883 .u.insns = {
884 BPF_STMT(BPF_LDX | BPF_LEN, 0),
885 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
886 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
887 BPF_STMT(BPF_RET | BPF_K, 1),
888 BPF_STMT(BPF_RET | BPF_K, MAX_K)
889 },
890 CLASSIC,
891 { 4, 4, 4, 3, 3 },
892 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
893 },
894 {
895 "JGE",
896 .u.insns = {
897 BPF_STMT(BPF_LDX | BPF_LEN, 0),
898 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
899 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
900 BPF_STMT(BPF_RET | BPF_K, 10),
901 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
902 BPF_STMT(BPF_RET | BPF_K, 20),
903 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
904 BPF_STMT(BPF_RET | BPF_K, 30),
905 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
906 BPF_STMT(BPF_RET | BPF_K, 40),
907 BPF_STMT(BPF_RET | BPF_K, MAX_K)
908 },
909 CLASSIC,
910 { 1, 2, 3, 4, 5 },
911 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
912 },
913 {
914 "JSET",
915 .u.insns = {
916 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
917 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
918 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
919 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
920 BPF_STMT(BPF_LDX | BPF_LEN, 0),
921 BPF_STMT(BPF_MISC | BPF_TXA, 0),
922 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
923 BPF_STMT(BPF_MISC | BPF_TAX, 0),
924 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
925 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
926 BPF_STMT(BPF_RET | BPF_K, 10),
927 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
928 BPF_STMT(BPF_RET | BPF_K, 20),
929 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
930 BPF_STMT(BPF_RET | BPF_K, 30),
931 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
932 BPF_STMT(BPF_RET | BPF_K, 30),
933 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
934 BPF_STMT(BPF_RET | BPF_K, 30),
935 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
936 BPF_STMT(BPF_RET | BPF_K, 30),
937 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
938 BPF_STMT(BPF_RET | BPF_K, 30),
939 BPF_STMT(BPF_RET | BPF_K, MAX_K)
940 },
941 CLASSIC,
942 { 0, 0xAA, 0x55, 1 },
943 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
944 },
945 {
946 "tcpdump port 22",
947 .u.insns = {
948 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
949 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
950 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
951 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
952 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
953 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
954 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
955 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
956 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
957 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
958 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
959 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
960 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
961 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
962 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
963 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
964 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
965 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
966 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
967 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
968 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
969 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
970 BPF_STMT(BPF_RET | BPF_K, 0xffff),
971 BPF_STMT(BPF_RET | BPF_K, 0),
972 },
973 CLASSIC,
974 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
975 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
976 * seq 1305692979:1305693027, ack 3650467037, win 65535,
977 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
978 */
979 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
980 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
981 0x08, 0x00,
982 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
983 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
984 0x0a, 0x01, 0x01, 0x95, /* ip src */
985 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
986 0xc2, 0x24,
987 0x00, 0x16 /* dst port */ },
988 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
989 },
990 {
991 "tcpdump complex",
992 .u.insns = {
993 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
994 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
995 * (len > 115 or len < 30000000000)' -d
996 */
997 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
998 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
999 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1000 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1001 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1002 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1003 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1004 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1005 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1006 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1007 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1008 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1009 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1010 BPF_STMT(BPF_ST, 1),
1011 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1012 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1013 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1014 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1015 BPF_STMT(BPF_LD | BPF_MEM, 1),
1016 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1017 BPF_STMT(BPF_ST, 5),
1018 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1019 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1020 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1021 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1022 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1023 BPF_STMT(BPF_LD | BPF_MEM, 5),
1024 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1025 BPF_STMT(BPF_LD | BPF_LEN, 0),
1026 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1027 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1028 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1029 BPF_STMT(BPF_RET | BPF_K, 0),
1030 },
1031 CLASSIC,
1032 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1033 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1034 0x08, 0x00,
1035 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1036 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1037 0x0a, 0x01, 0x01, 0x95, /* ip src */
1038 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1039 0xc2, 0x24,
1040 0x00, 0x16 /* dst port */ },
1041 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1042 },
1043 {
1044 "RET_A",
1045 .u.insns = {
1046 /* check that unitialized X and A contain zeros */
1047 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1048 BPF_STMT(BPF_RET | BPF_A, 0)
1049 },
1050 CLASSIC,
1051 { },
1052 { {1, 0}, {2, 0} },
1053 },
1054 {
1055 "INT: ADD trivial",
1056 .u.insns_int = {
1057 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1058 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1059 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1060 BPF_ALU64_REG(BPF_SUB, R1, R2),
1061 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1062 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1063 BPF_ALU64_REG(BPF_MOV, R0, R1),
1064 BPF_EXIT_INSN(),
1065 },
1066 INTERNAL,
1067 { },
1068 { { 0, 0xfffffffd } }
1069 },
1070 {
1071 "INT: MUL_X",
1072 .u.insns_int = {
1073 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1074 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1075 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1076 BPF_ALU64_REG(BPF_MUL, R1, R2),
1077 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1078 BPF_EXIT_INSN(),
1079 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1080 BPF_EXIT_INSN(),
1081 },
1082 INTERNAL,
1083 { },
1084 { { 0, 1 } }
1085 },
1086 {
1087 "INT: MUL_X2",
1088 .u.insns_int = {
1089 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1090 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1091 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1092 BPF_ALU64_REG(BPF_MUL, R1, R2),
1093 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1094 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1095 BPF_EXIT_INSN(),
1096 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1097 BPF_EXIT_INSN(),
1098 },
1099 INTERNAL,
1100 { },
1101 { { 0, 1 } }
1102 },
1103 {
1104 "INT: MUL32_X",
1105 .u.insns_int = {
1106 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1107 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1108 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1109 BPF_ALU32_REG(BPF_MUL, R1, R2),
1110 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1111 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1112 BPF_EXIT_INSN(),
1113 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1114 BPF_EXIT_INSN(),
1115 },
1116 INTERNAL,
1117 { },
1118 { { 0, 1 } }
1119 },
1120 {
1121 /* Have to test all register combinations, since
1122 * JITing of different registers will produce
1123 * different asm code.
1124 */
1125 "INT: ADD 64-bit",
1126 .u.insns_int = {
1127 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1128 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1129 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1130 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1131 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1132 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1133 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1134 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1135 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1136 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1137 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1138 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1139 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1140 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1141 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1142 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1143 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1144 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1145 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1146 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1147 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1148 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1149 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1150 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1151 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1152 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1153 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1154 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1155 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1156 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1157 BPF_ALU64_REG(BPF_ADD, R0, R0),
1158 BPF_ALU64_REG(BPF_ADD, R0, R1),
1159 BPF_ALU64_REG(BPF_ADD, R0, R2),
1160 BPF_ALU64_REG(BPF_ADD, R0, R3),
1161 BPF_ALU64_REG(BPF_ADD, R0, R4),
1162 BPF_ALU64_REG(BPF_ADD, R0, R5),
1163 BPF_ALU64_REG(BPF_ADD, R0, R6),
1164 BPF_ALU64_REG(BPF_ADD, R0, R7),
1165 BPF_ALU64_REG(BPF_ADD, R0, R8),
1166 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1167 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1168 BPF_EXIT_INSN(),
1169 BPF_ALU64_REG(BPF_ADD, R1, R0),
1170 BPF_ALU64_REG(BPF_ADD, R1, R1),
1171 BPF_ALU64_REG(BPF_ADD, R1, R2),
1172 BPF_ALU64_REG(BPF_ADD, R1, R3),
1173 BPF_ALU64_REG(BPF_ADD, R1, R4),
1174 BPF_ALU64_REG(BPF_ADD, R1, R5),
1175 BPF_ALU64_REG(BPF_ADD, R1, R6),
1176 BPF_ALU64_REG(BPF_ADD, R1, R7),
1177 BPF_ALU64_REG(BPF_ADD, R1, R8),
1178 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1179 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1180 BPF_EXIT_INSN(),
1181 BPF_ALU64_REG(BPF_ADD, R2, R0),
1182 BPF_ALU64_REG(BPF_ADD, R2, R1),
1183 BPF_ALU64_REG(BPF_ADD, R2, R2),
1184 BPF_ALU64_REG(BPF_ADD, R2, R3),
1185 BPF_ALU64_REG(BPF_ADD, R2, R4),
1186 BPF_ALU64_REG(BPF_ADD, R2, R5),
1187 BPF_ALU64_REG(BPF_ADD, R2, R6),
1188 BPF_ALU64_REG(BPF_ADD, R2, R7),
1189 BPF_ALU64_REG(BPF_ADD, R2, R8),
1190 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1191 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1192 BPF_EXIT_INSN(),
1193 BPF_ALU64_REG(BPF_ADD, R3, R0),
1194 BPF_ALU64_REG(BPF_ADD, R3, R1),
1195 BPF_ALU64_REG(BPF_ADD, R3, R2),
1196 BPF_ALU64_REG(BPF_ADD, R3, R3),
1197 BPF_ALU64_REG(BPF_ADD, R3, R4),
1198 BPF_ALU64_REG(BPF_ADD, R3, R5),
1199 BPF_ALU64_REG(BPF_ADD, R3, R6),
1200 BPF_ALU64_REG(BPF_ADD, R3, R7),
1201 BPF_ALU64_REG(BPF_ADD, R3, R8),
1202 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1203 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1204 BPF_EXIT_INSN(),
1205 BPF_ALU64_REG(BPF_ADD, R4, R0),
1206 BPF_ALU64_REG(BPF_ADD, R4, R1),
1207 BPF_ALU64_REG(BPF_ADD, R4, R2),
1208 BPF_ALU64_REG(BPF_ADD, R4, R3),
1209 BPF_ALU64_REG(BPF_ADD, R4, R4),
1210 BPF_ALU64_REG(BPF_ADD, R4, R5),
1211 BPF_ALU64_REG(BPF_ADD, R4, R6),
1212 BPF_ALU64_REG(BPF_ADD, R4, R7),
1213 BPF_ALU64_REG(BPF_ADD, R4, R8),
1214 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1215 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1216 BPF_EXIT_INSN(),
1217 BPF_ALU64_REG(BPF_ADD, R5, R0),
1218 BPF_ALU64_REG(BPF_ADD, R5, R1),
1219 BPF_ALU64_REG(BPF_ADD, R5, R2),
1220 BPF_ALU64_REG(BPF_ADD, R5, R3),
1221 BPF_ALU64_REG(BPF_ADD, R5, R4),
1222 BPF_ALU64_REG(BPF_ADD, R5, R5),
1223 BPF_ALU64_REG(BPF_ADD, R5, R6),
1224 BPF_ALU64_REG(BPF_ADD, R5, R7),
1225 BPF_ALU64_REG(BPF_ADD, R5, R8),
1226 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1227 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1228 BPF_EXIT_INSN(),
1229 BPF_ALU64_REG(BPF_ADD, R6, R0),
1230 BPF_ALU64_REG(BPF_ADD, R6, R1),
1231 BPF_ALU64_REG(BPF_ADD, R6, R2),
1232 BPF_ALU64_REG(BPF_ADD, R6, R3),
1233 BPF_ALU64_REG(BPF_ADD, R6, R4),
1234 BPF_ALU64_REG(BPF_ADD, R6, R5),
1235 BPF_ALU64_REG(BPF_ADD, R6, R6),
1236 BPF_ALU64_REG(BPF_ADD, R6, R7),
1237 BPF_ALU64_REG(BPF_ADD, R6, R8),
1238 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1239 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1240 BPF_EXIT_INSN(),
1241 BPF_ALU64_REG(BPF_ADD, R7, R0),
1242 BPF_ALU64_REG(BPF_ADD, R7, R1),
1243 BPF_ALU64_REG(BPF_ADD, R7, R2),
1244 BPF_ALU64_REG(BPF_ADD, R7, R3),
1245 BPF_ALU64_REG(BPF_ADD, R7, R4),
1246 BPF_ALU64_REG(BPF_ADD, R7, R5),
1247 BPF_ALU64_REG(BPF_ADD, R7, R6),
1248 BPF_ALU64_REG(BPF_ADD, R7, R7),
1249 BPF_ALU64_REG(BPF_ADD, R7, R8),
1250 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1251 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1252 BPF_EXIT_INSN(),
1253 BPF_ALU64_REG(BPF_ADD, R8, R0),
1254 BPF_ALU64_REG(BPF_ADD, R8, R1),
1255 BPF_ALU64_REG(BPF_ADD, R8, R2),
1256 BPF_ALU64_REG(BPF_ADD, R8, R3),
1257 BPF_ALU64_REG(BPF_ADD, R8, R4),
1258 BPF_ALU64_REG(BPF_ADD, R8, R5),
1259 BPF_ALU64_REG(BPF_ADD, R8, R6),
1260 BPF_ALU64_REG(BPF_ADD, R8, R7),
1261 BPF_ALU64_REG(BPF_ADD, R8, R8),
1262 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1263 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1264 BPF_EXIT_INSN(),
1265 BPF_ALU64_REG(BPF_ADD, R9, R0),
1266 BPF_ALU64_REG(BPF_ADD, R9, R1),
1267 BPF_ALU64_REG(BPF_ADD, R9, R2),
1268 BPF_ALU64_REG(BPF_ADD, R9, R3),
1269 BPF_ALU64_REG(BPF_ADD, R9, R4),
1270 BPF_ALU64_REG(BPF_ADD, R9, R5),
1271 BPF_ALU64_REG(BPF_ADD, R9, R6),
1272 BPF_ALU64_REG(BPF_ADD, R9, R7),
1273 BPF_ALU64_REG(BPF_ADD, R9, R8),
1274 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1275 BPF_ALU64_REG(BPF_MOV, R0, R9),
1276 BPF_EXIT_INSN(),
1277 },
1278 INTERNAL,
1279 { },
1280 { { 0, 2957380 } }
1281 },
1282 {
1283 "INT: ADD 32-bit",
1284 .u.insns_int = {
1285 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1286 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1287 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1288 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1289 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1290 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1291 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1292 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1293 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1294 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1295 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1296 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1297 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1298 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1299 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1300 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1301 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1302 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1303 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1304 BPF_ALU32_REG(BPF_ADD, R0, R1),
1305 BPF_ALU32_REG(BPF_ADD, R0, R2),
1306 BPF_ALU32_REG(BPF_ADD, R0, R3),
1307 BPF_ALU32_REG(BPF_ADD, R0, R4),
1308 BPF_ALU32_REG(BPF_ADD, R0, R5),
1309 BPF_ALU32_REG(BPF_ADD, R0, R6),
1310 BPF_ALU32_REG(BPF_ADD, R0, R7),
1311 BPF_ALU32_REG(BPF_ADD, R0, R8),
1312 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1313 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1314 BPF_EXIT_INSN(),
1315 BPF_ALU32_REG(BPF_ADD, R1, R0),
1316 BPF_ALU32_REG(BPF_ADD, R1, R1),
1317 BPF_ALU32_REG(BPF_ADD, R1, R2),
1318 BPF_ALU32_REG(BPF_ADD, R1, R3),
1319 BPF_ALU32_REG(BPF_ADD, R1, R4),
1320 BPF_ALU32_REG(BPF_ADD, R1, R5),
1321 BPF_ALU32_REG(BPF_ADD, R1, R6),
1322 BPF_ALU32_REG(BPF_ADD, R1, R7),
1323 BPF_ALU32_REG(BPF_ADD, R1, R8),
1324 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1325 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1326 BPF_EXIT_INSN(),
1327 BPF_ALU32_REG(BPF_ADD, R2, R0),
1328 BPF_ALU32_REG(BPF_ADD, R2, R1),
1329 BPF_ALU32_REG(BPF_ADD, R2, R2),
1330 BPF_ALU32_REG(BPF_ADD, R2, R3),
1331 BPF_ALU32_REG(BPF_ADD, R2, R4),
1332 BPF_ALU32_REG(BPF_ADD, R2, R5),
1333 BPF_ALU32_REG(BPF_ADD, R2, R6),
1334 BPF_ALU32_REG(BPF_ADD, R2, R7),
1335 BPF_ALU32_REG(BPF_ADD, R2, R8),
1336 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1337 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1338 BPF_EXIT_INSN(),
1339 BPF_ALU32_REG(BPF_ADD, R3, R0),
1340 BPF_ALU32_REG(BPF_ADD, R3, R1),
1341 BPF_ALU32_REG(BPF_ADD, R3, R2),
1342 BPF_ALU32_REG(BPF_ADD, R3, R3),
1343 BPF_ALU32_REG(BPF_ADD, R3, R4),
1344 BPF_ALU32_REG(BPF_ADD, R3, R5),
1345 BPF_ALU32_REG(BPF_ADD, R3, R6),
1346 BPF_ALU32_REG(BPF_ADD, R3, R7),
1347 BPF_ALU32_REG(BPF_ADD, R3, R8),
1348 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1349 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1350 BPF_EXIT_INSN(),
1351 BPF_ALU32_REG(BPF_ADD, R4, R0),
1352 BPF_ALU32_REG(BPF_ADD, R4, R1),
1353 BPF_ALU32_REG(BPF_ADD, R4, R2),
1354 BPF_ALU32_REG(BPF_ADD, R4, R3),
1355 BPF_ALU32_REG(BPF_ADD, R4, R4),
1356 BPF_ALU32_REG(BPF_ADD, R4, R5),
1357 BPF_ALU32_REG(BPF_ADD, R4, R6),
1358 BPF_ALU32_REG(BPF_ADD, R4, R7),
1359 BPF_ALU32_REG(BPF_ADD, R4, R8),
1360 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1361 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1362 BPF_EXIT_INSN(),
1363 BPF_ALU32_REG(BPF_ADD, R5, R0),
1364 BPF_ALU32_REG(BPF_ADD, R5, R1),
1365 BPF_ALU32_REG(BPF_ADD, R5, R2),
1366 BPF_ALU32_REG(BPF_ADD, R5, R3),
1367 BPF_ALU32_REG(BPF_ADD, R5, R4),
1368 BPF_ALU32_REG(BPF_ADD, R5, R5),
1369 BPF_ALU32_REG(BPF_ADD, R5, R6),
1370 BPF_ALU32_REG(BPF_ADD, R5, R7),
1371 BPF_ALU32_REG(BPF_ADD, R5, R8),
1372 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1373 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1374 BPF_EXIT_INSN(),
1375 BPF_ALU32_REG(BPF_ADD, R6, R0),
1376 BPF_ALU32_REG(BPF_ADD, R6, R1),
1377 BPF_ALU32_REG(BPF_ADD, R6, R2),
1378 BPF_ALU32_REG(BPF_ADD, R6, R3),
1379 BPF_ALU32_REG(BPF_ADD, R6, R4),
1380 BPF_ALU32_REG(BPF_ADD, R6, R5),
1381 BPF_ALU32_REG(BPF_ADD, R6, R6),
1382 BPF_ALU32_REG(BPF_ADD, R6, R7),
1383 BPF_ALU32_REG(BPF_ADD, R6, R8),
1384 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1385 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1386 BPF_EXIT_INSN(),
1387 BPF_ALU32_REG(BPF_ADD, R7, R0),
1388 BPF_ALU32_REG(BPF_ADD, R7, R1),
1389 BPF_ALU32_REG(BPF_ADD, R7, R2),
1390 BPF_ALU32_REG(BPF_ADD, R7, R3),
1391 BPF_ALU32_REG(BPF_ADD, R7, R4),
1392 BPF_ALU32_REG(BPF_ADD, R7, R5),
1393 BPF_ALU32_REG(BPF_ADD, R7, R6),
1394 BPF_ALU32_REG(BPF_ADD, R7, R7),
1395 BPF_ALU32_REG(BPF_ADD, R7, R8),
1396 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1397 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1398 BPF_EXIT_INSN(),
1399 BPF_ALU32_REG(BPF_ADD, R8, R0),
1400 BPF_ALU32_REG(BPF_ADD, R8, R1),
1401 BPF_ALU32_REG(BPF_ADD, R8, R2),
1402 BPF_ALU32_REG(BPF_ADD, R8, R3),
1403 BPF_ALU32_REG(BPF_ADD, R8, R4),
1404 BPF_ALU32_REG(BPF_ADD, R8, R5),
1405 BPF_ALU32_REG(BPF_ADD, R8, R6),
1406 BPF_ALU32_REG(BPF_ADD, R8, R7),
1407 BPF_ALU32_REG(BPF_ADD, R8, R8),
1408 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1409 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1410 BPF_EXIT_INSN(),
1411 BPF_ALU32_REG(BPF_ADD, R9, R0),
1412 BPF_ALU32_REG(BPF_ADD, R9, R1),
1413 BPF_ALU32_REG(BPF_ADD, R9, R2),
1414 BPF_ALU32_REG(BPF_ADD, R9, R3),
1415 BPF_ALU32_REG(BPF_ADD, R9, R4),
1416 BPF_ALU32_REG(BPF_ADD, R9, R5),
1417 BPF_ALU32_REG(BPF_ADD, R9, R6),
1418 BPF_ALU32_REG(BPF_ADD, R9, R7),
1419 BPF_ALU32_REG(BPF_ADD, R9, R8),
1420 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1421 BPF_ALU32_REG(BPF_MOV, R0, R9),
1422 BPF_EXIT_INSN(),
1423 },
1424 INTERNAL,
1425 { },
1426 { { 0, 2957380 } }
1427 },
1428 { /* Mainly checking JIT here. */
1429 "INT: SUB",
1430 .u.insns_int = {
1431 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1432 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1433 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1434 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1435 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1436 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1437 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1438 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1439 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1440 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1441 BPF_ALU64_REG(BPF_SUB, R0, R0),
1442 BPF_ALU64_REG(BPF_SUB, R0, R1),
1443 BPF_ALU64_REG(BPF_SUB, R0, R2),
1444 BPF_ALU64_REG(BPF_SUB, R0, R3),
1445 BPF_ALU64_REG(BPF_SUB, R0, R4),
1446 BPF_ALU64_REG(BPF_SUB, R0, R5),
1447 BPF_ALU64_REG(BPF_SUB, R0, R6),
1448 BPF_ALU64_REG(BPF_SUB, R0, R7),
1449 BPF_ALU64_REG(BPF_SUB, R0, R8),
1450 BPF_ALU64_REG(BPF_SUB, R0, R9),
1451 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1452 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1453 BPF_EXIT_INSN(),
1454 BPF_ALU64_REG(BPF_SUB, R1, R0),
1455 BPF_ALU64_REG(BPF_SUB, R1, R2),
1456 BPF_ALU64_REG(BPF_SUB, R1, R3),
1457 BPF_ALU64_REG(BPF_SUB, R1, R4),
1458 BPF_ALU64_REG(BPF_SUB, R1, R5),
1459 BPF_ALU64_REG(BPF_SUB, R1, R6),
1460 BPF_ALU64_REG(BPF_SUB, R1, R7),
1461 BPF_ALU64_REG(BPF_SUB, R1, R8),
1462 BPF_ALU64_REG(BPF_SUB, R1, R9),
1463 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1464 BPF_ALU64_REG(BPF_SUB, R2, R0),
1465 BPF_ALU64_REG(BPF_SUB, R2, R1),
1466 BPF_ALU64_REG(BPF_SUB, R2, R3),
1467 BPF_ALU64_REG(BPF_SUB, R2, R4),
1468 BPF_ALU64_REG(BPF_SUB, R2, R5),
1469 BPF_ALU64_REG(BPF_SUB, R2, R6),
1470 BPF_ALU64_REG(BPF_SUB, R2, R7),
1471 BPF_ALU64_REG(BPF_SUB, R2, R8),
1472 BPF_ALU64_REG(BPF_SUB, R2, R9),
1473 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1474 BPF_ALU64_REG(BPF_SUB, R3, R0),
1475 BPF_ALU64_REG(BPF_SUB, R3, R1),
1476 BPF_ALU64_REG(BPF_SUB, R3, R2),
1477 BPF_ALU64_REG(BPF_SUB, R3, R4),
1478 BPF_ALU64_REG(BPF_SUB, R3, R5),
1479 BPF_ALU64_REG(BPF_SUB, R3, R6),
1480 BPF_ALU64_REG(BPF_SUB, R3, R7),
1481 BPF_ALU64_REG(BPF_SUB, R3, R8),
1482 BPF_ALU64_REG(BPF_SUB, R3, R9),
1483 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1484 BPF_ALU64_REG(BPF_SUB, R4, R0),
1485 BPF_ALU64_REG(BPF_SUB, R4, R1),
1486 BPF_ALU64_REG(BPF_SUB, R4, R2),
1487 BPF_ALU64_REG(BPF_SUB, R4, R3),
1488 BPF_ALU64_REG(BPF_SUB, R4, R5),
1489 BPF_ALU64_REG(BPF_SUB, R4, R6),
1490 BPF_ALU64_REG(BPF_SUB, R4, R7),
1491 BPF_ALU64_REG(BPF_SUB, R4, R8),
1492 BPF_ALU64_REG(BPF_SUB, R4, R9),
1493 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1494 BPF_ALU64_REG(BPF_SUB, R5, R0),
1495 BPF_ALU64_REG(BPF_SUB, R5, R1),
1496 BPF_ALU64_REG(BPF_SUB, R5, R2),
1497 BPF_ALU64_REG(BPF_SUB, R5, R3),
1498 BPF_ALU64_REG(BPF_SUB, R5, R4),
1499 BPF_ALU64_REG(BPF_SUB, R5, R6),
1500 BPF_ALU64_REG(BPF_SUB, R5, R7),
1501 BPF_ALU64_REG(BPF_SUB, R5, R8),
1502 BPF_ALU64_REG(BPF_SUB, R5, R9),
1503 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1504 BPF_ALU64_REG(BPF_SUB, R6, R0),
1505 BPF_ALU64_REG(BPF_SUB, R6, R1),
1506 BPF_ALU64_REG(BPF_SUB, R6, R2),
1507 BPF_ALU64_REG(BPF_SUB, R6, R3),
1508 BPF_ALU64_REG(BPF_SUB, R6, R4),
1509 BPF_ALU64_REG(BPF_SUB, R6, R5),
1510 BPF_ALU64_REG(BPF_SUB, R6, R7),
1511 BPF_ALU64_REG(BPF_SUB, R6, R8),
1512 BPF_ALU64_REG(BPF_SUB, R6, R9),
1513 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1514 BPF_ALU64_REG(BPF_SUB, R7, R0),
1515 BPF_ALU64_REG(BPF_SUB, R7, R1),
1516 BPF_ALU64_REG(BPF_SUB, R7, R2),
1517 BPF_ALU64_REG(BPF_SUB, R7, R3),
1518 BPF_ALU64_REG(BPF_SUB, R7, R4),
1519 BPF_ALU64_REG(BPF_SUB, R7, R5),
1520 BPF_ALU64_REG(BPF_SUB, R7, R6),
1521 BPF_ALU64_REG(BPF_SUB, R7, R8),
1522 BPF_ALU64_REG(BPF_SUB, R7, R9),
1523 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1524 BPF_ALU64_REG(BPF_SUB, R8, R0),
1525 BPF_ALU64_REG(BPF_SUB, R8, R1),
1526 BPF_ALU64_REG(BPF_SUB, R8, R2),
1527 BPF_ALU64_REG(BPF_SUB, R8, R3),
1528 BPF_ALU64_REG(BPF_SUB, R8, R4),
1529 BPF_ALU64_REG(BPF_SUB, R8, R5),
1530 BPF_ALU64_REG(BPF_SUB, R8, R6),
1531 BPF_ALU64_REG(BPF_SUB, R8, R7),
1532 BPF_ALU64_REG(BPF_SUB, R8, R9),
1533 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1534 BPF_ALU64_REG(BPF_SUB, R9, R0),
1535 BPF_ALU64_REG(BPF_SUB, R9, R1),
1536 BPF_ALU64_REG(BPF_SUB, R9, R2),
1537 BPF_ALU64_REG(BPF_SUB, R9, R3),
1538 BPF_ALU64_REG(BPF_SUB, R9, R4),
1539 BPF_ALU64_REG(BPF_SUB, R9, R5),
1540 BPF_ALU64_REG(BPF_SUB, R9, R6),
1541 BPF_ALU64_REG(BPF_SUB, R9, R7),
1542 BPF_ALU64_REG(BPF_SUB, R9, R8),
1543 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1544 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1545 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1546 BPF_ALU64_REG(BPF_SUB, R0, R1),
1547 BPF_ALU64_REG(BPF_SUB, R0, R2),
1548 BPF_ALU64_REG(BPF_SUB, R0, R3),
1549 BPF_ALU64_REG(BPF_SUB, R0, R4),
1550 BPF_ALU64_REG(BPF_SUB, R0, R5),
1551 BPF_ALU64_REG(BPF_SUB, R0, R6),
1552 BPF_ALU64_REG(BPF_SUB, R0, R7),
1553 BPF_ALU64_REG(BPF_SUB, R0, R8),
1554 BPF_ALU64_REG(BPF_SUB, R0, R9),
1555 BPF_EXIT_INSN(),
1556 },
1557 INTERNAL,
1558 { },
1559 { { 0, 11 } }
1560 },
1561 { /* Mainly checking JIT here. */
1562 "INT: XOR",
1563 .u.insns_int = {
1564 BPF_ALU64_REG(BPF_SUB, R0, R0),
1565 BPF_ALU64_REG(BPF_XOR, R1, R1),
1566 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1567 BPF_EXIT_INSN(),
1568 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1569 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1570 BPF_ALU64_REG(BPF_SUB, R1, R1),
1571 BPF_ALU64_REG(BPF_XOR, R2, R2),
1572 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1573 BPF_EXIT_INSN(),
1574 BPF_ALU64_REG(BPF_SUB, R2, R2),
1575 BPF_ALU64_REG(BPF_XOR, R3, R3),
1576 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1577 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1578 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1579 BPF_EXIT_INSN(),
1580 BPF_ALU64_REG(BPF_SUB, R3, R3),
1581 BPF_ALU64_REG(BPF_XOR, R4, R4),
1582 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1583 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1584 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1585 BPF_EXIT_INSN(),
1586 BPF_ALU64_REG(BPF_SUB, R4, R4),
1587 BPF_ALU64_REG(BPF_XOR, R5, R5),
1588 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1589 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1590 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1591 BPF_EXIT_INSN(),
1592 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1593 BPF_ALU64_REG(BPF_SUB, R5, R5),
1594 BPF_ALU64_REG(BPF_XOR, R6, R6),
1595 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1596 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1597 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1598 BPF_EXIT_INSN(),
1599 BPF_ALU64_REG(BPF_SUB, R6, R6),
1600 BPF_ALU64_REG(BPF_XOR, R7, R7),
1601 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1602 BPF_EXIT_INSN(),
1603 BPF_ALU64_REG(BPF_SUB, R7, R7),
1604 BPF_ALU64_REG(BPF_XOR, R8, R8),
1605 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1606 BPF_EXIT_INSN(),
1607 BPF_ALU64_REG(BPF_SUB, R8, R8),
1608 BPF_ALU64_REG(BPF_XOR, R9, R9),
1609 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1610 BPF_EXIT_INSN(),
1611 BPF_ALU64_REG(BPF_SUB, R9, R9),
1612 BPF_ALU64_REG(BPF_XOR, R0, R0),
1613 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1614 BPF_EXIT_INSN(),
1615 BPF_ALU64_REG(BPF_SUB, R1, R1),
1616 BPF_ALU64_REG(BPF_XOR, R0, R0),
1617 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1618 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1619 BPF_EXIT_INSN(),
1620 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1621 BPF_EXIT_INSN(),
1622 },
1623 INTERNAL,
1624 { },
1625 { { 0, 1 } }
1626 },
1627 { /* Mainly checking JIT here. */
1628 "INT: MUL",
1629 .u.insns_int = {
1630 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1631 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1632 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1633 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1634 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1635 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1636 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1637 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1638 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1639 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1640 BPF_ALU64_REG(BPF_MUL, R0, R0),
1641 BPF_ALU64_REG(BPF_MUL, R0, R1),
1642 BPF_ALU64_REG(BPF_MUL, R0, R2),
1643 BPF_ALU64_REG(BPF_MUL, R0, R3),
1644 BPF_ALU64_REG(BPF_MUL, R0, R4),
1645 BPF_ALU64_REG(BPF_MUL, R0, R5),
1646 BPF_ALU64_REG(BPF_MUL, R0, R6),
1647 BPF_ALU64_REG(BPF_MUL, R0, R7),
1648 BPF_ALU64_REG(BPF_MUL, R0, R8),
1649 BPF_ALU64_REG(BPF_MUL, R0, R9),
1650 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1651 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1652 BPF_EXIT_INSN(),
1653 BPF_ALU64_REG(BPF_MUL, R1, R0),
1654 BPF_ALU64_REG(BPF_MUL, R1, R2),
1655 BPF_ALU64_REG(BPF_MUL, R1, R3),
1656 BPF_ALU64_REG(BPF_MUL, R1, R4),
1657 BPF_ALU64_REG(BPF_MUL, R1, R5),
1658 BPF_ALU64_REG(BPF_MUL, R1, R6),
1659 BPF_ALU64_REG(BPF_MUL, R1, R7),
1660 BPF_ALU64_REG(BPF_MUL, R1, R8),
1661 BPF_ALU64_REG(BPF_MUL, R1, R9),
1662 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1663 BPF_ALU64_REG(BPF_MOV, R2, R1),
1664 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1665 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1666 BPF_EXIT_INSN(),
1667 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1668 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1669 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1670 BPF_EXIT_INSN(),
1671 BPF_ALU64_REG(BPF_MUL, R2, R0),
1672 BPF_ALU64_REG(BPF_MUL, R2, R1),
1673 BPF_ALU64_REG(BPF_MUL, R2, R3),
1674 BPF_ALU64_REG(BPF_MUL, R2, R4),
1675 BPF_ALU64_REG(BPF_MUL, R2, R5),
1676 BPF_ALU64_REG(BPF_MUL, R2, R6),
1677 BPF_ALU64_REG(BPF_MUL, R2, R7),
1678 BPF_ALU64_REG(BPF_MUL, R2, R8),
1679 BPF_ALU64_REG(BPF_MUL, R2, R9),
1680 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1681 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1682 BPF_ALU64_REG(BPF_MOV, R0, R2),
1683 BPF_EXIT_INSN(),
1684 },
1685 INTERNAL,
1686 { },
1687 { { 0, 0x35d97ef2 } }
1688 },
1689 {
1690 "INT: ALU MIX",
1691 .u.insns_int = {
1692 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1693 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1694 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1695 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1696 BPF_ALU64_REG(BPF_DIV, R0, R2),
1697 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1698 BPF_EXIT_INSN(),
1699 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1700 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1701 BPF_EXIT_INSN(),
1702 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1703 BPF_EXIT_INSN(),
1704 },
1705 INTERNAL,
1706 { },
1707 { { 0, -1 } }
1708 },
1709 {
1710 "INT: shifts by register",
1711 .u.insns_int = {
1712 BPF_MOV64_IMM(R0, -1234),
1713 BPF_MOV64_IMM(R1, 1),
1714 BPF_ALU32_REG(BPF_RSH, R0, R1),
1715 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1716 BPF_EXIT_INSN(),
1717 BPF_MOV64_IMM(R2, 1),
1718 BPF_ALU64_REG(BPF_LSH, R0, R2),
1719 BPF_MOV32_IMM(R4, -1234),
1720 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1721 BPF_EXIT_INSN(),
1722 BPF_ALU64_IMM(BPF_AND, R4, 63),
1723 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1724 BPF_MOV64_IMM(R3, 47),
1725 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1726 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1727 BPF_EXIT_INSN(),
1728 BPF_MOV64_IMM(R2, 1),
1729 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1730 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1731 BPF_EXIT_INSN(),
1732 BPF_MOV64_IMM(R4, 4),
1733 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1734 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1735 BPF_EXIT_INSN(),
1736 BPF_MOV64_IMM(R4, 5),
1737 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1738 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1739 BPF_EXIT_INSN(),
1740 BPF_MOV64_IMM(R0, -1),
1741 BPF_EXIT_INSN(),
1742 },
1743 INTERNAL,
1744 { },
1745 { { 0, -1 } }
1746 },
1747 {
1748 "INT: DIV + ABS",
1749 .u.insns_int = {
1750 BPF_ALU64_REG(BPF_MOV, R6, R1),
1751 BPF_LD_ABS(BPF_B, 3),
1752 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1753 BPF_ALU32_REG(BPF_DIV, R0, R2),
1754 BPF_ALU64_REG(BPF_MOV, R8, R0),
1755 BPF_LD_ABS(BPF_B, 4),
1756 BPF_ALU64_REG(BPF_ADD, R8, R0),
1757 BPF_LD_IND(BPF_B, R8, -70),
1758 BPF_EXIT_INSN(),
1759 },
1760 INTERNAL,
1761 { 10, 20, 30, 40, 50 },
1762 { { 4, 0 }, { 5, 10 } }
1763 },
1764 {
1765 "INT: DIV by zero",
1766 .u.insns_int = {
1767 BPF_ALU64_REG(BPF_MOV, R6, R1),
1768 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1769 BPF_LD_ABS(BPF_B, 3),
1770 BPF_ALU32_REG(BPF_DIV, R0, R7),
1771 BPF_EXIT_INSN(),
1772 },
1773 INTERNAL,
1774 { 10, 20, 30, 40, 50 },
1775 { { 3, 0 }, { 4, 0 } }
1776 },
1777 {
1778 "check: missing ret",
1779 .u.insns = {
1780 BPF_STMT(BPF_LD | BPF_IMM, 1),
1781 },
1782 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1783 { },
1784 { },
1785 .fill_helper = NULL,
1786 .expected_errcode = -EINVAL,
1787 },
1788 {
1789 "check: div_k_0",
1790 .u.insns = {
1791 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1792 BPF_STMT(BPF_RET | BPF_K, 0)
1793 },
1794 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1795 { },
1796 { },
1797 .fill_helper = NULL,
1798 .expected_errcode = -EINVAL,
1799 },
1800 {
1801 "check: unknown insn",
1802 .u.insns = {
1803 /* seccomp insn, rejected in socket filter */
1804 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1805 BPF_STMT(BPF_RET | BPF_K, 0)
1806 },
1807 CLASSIC | FLAG_EXPECTED_FAIL,
1808 { },
1809 { },
1810 .fill_helper = NULL,
1811 .expected_errcode = -EINVAL,
1812 },
1813 {
1814 "check: out of range spill/fill",
1815 .u.insns = {
1816 BPF_STMT(BPF_STX, 16),
1817 BPF_STMT(BPF_RET | BPF_K, 0)
1818 },
1819 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1820 { },
1821 { },
1822 .fill_helper = NULL,
1823 .expected_errcode = -EINVAL,
1824 },
1825 {
1826 "JUMPS + HOLES",
1827 .u.insns = {
1828 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1829 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1830 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1831 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1832 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1833 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1834 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1835 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1836 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1837 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1838 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1839 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1840 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1841 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1842 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1843 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1844 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1845 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1846 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1847 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1848 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1849 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1850 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1851 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1852 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1853 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1854 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1855 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1856 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1857 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1858 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1859 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1860 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1861 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1862 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1863 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1864 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1865 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1866 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1867 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1868 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1869 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1870 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1871 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1872 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1873 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1874 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1875 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1876 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1877 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1878 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1879 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1880 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1881 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1882 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1883 BPF_STMT(BPF_RET | BPF_A, 0),
1884 BPF_STMT(BPF_RET | BPF_A, 0),
1885 },
1886 CLASSIC,
1887 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
1888 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
1889 0x08, 0x00,
1890 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
1891 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
1892 0xc0, 0xa8, 0x33, 0x01,
1893 0xc0, 0xa8, 0x33, 0x02,
1894 0xbb, 0xb6,
1895 0xa9, 0xfa,
1896 0x00, 0x14, 0x00, 0x00,
1897 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1898 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1899 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1900 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1901 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1902 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1903 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1904 0xcc, 0xcc, 0xcc, 0xcc },
1905 { { 88, 0x001b } }
1906 },
1907 {
1908 "check: RET X",
1909 .u.insns = {
1910 BPF_STMT(BPF_RET | BPF_X, 0),
1911 },
1912 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1913 { },
1914 { },
1915 .fill_helper = NULL,
1916 .expected_errcode = -EINVAL,
1917 },
1918 {
1919 "check: LDX + RET X",
1920 .u.insns = {
1921 BPF_STMT(BPF_LDX | BPF_IMM, 42),
1922 BPF_STMT(BPF_RET | BPF_X, 0),
1923 },
1924 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1925 { },
1926 { },
1927 .fill_helper = NULL,
1928 .expected_errcode = -EINVAL,
1929 },
1930 { /* Mainly checking JIT here. */
1931 "M[]: alt STX + LDX",
1932 .u.insns = {
1933 BPF_STMT(BPF_LDX | BPF_IMM, 100),
1934 BPF_STMT(BPF_STX, 0),
1935 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1936 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1937 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1938 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1939 BPF_STMT(BPF_STX, 1),
1940 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1941 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1942 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1943 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1944 BPF_STMT(BPF_STX, 2),
1945 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1946 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1947 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1948 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1949 BPF_STMT(BPF_STX, 3),
1950 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1951 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1952 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1953 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1954 BPF_STMT(BPF_STX, 4),
1955 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1956 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1957 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1958 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1959 BPF_STMT(BPF_STX, 5),
1960 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1961 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1962 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1963 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1964 BPF_STMT(BPF_STX, 6),
1965 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1966 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1967 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1968 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1969 BPF_STMT(BPF_STX, 7),
1970 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1971 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1972 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1973 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1974 BPF_STMT(BPF_STX, 8),
1975 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1976 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1977 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1978 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1979 BPF_STMT(BPF_STX, 9),
1980 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1981 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1982 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1983 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1984 BPF_STMT(BPF_STX, 10),
1985 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1986 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1987 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1988 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1989 BPF_STMT(BPF_STX, 11),
1990 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1991 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1992 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1993 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1994 BPF_STMT(BPF_STX, 12),
1995 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1996 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1997 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1998 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1999 BPF_STMT(BPF_STX, 13),
2000 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2001 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2002 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2003 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2004 BPF_STMT(BPF_STX, 14),
2005 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2006 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2007 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2008 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2009 BPF_STMT(BPF_STX, 15),
2010 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2011 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2012 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2013 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2014 BPF_STMT(BPF_RET | BPF_A, 0),
2015 },
2016 CLASSIC | FLAG_NO_DATA,
2017 { },
2018 { { 0, 116 } },
2019 },
2020 { /* Mainly checking JIT here. */
2021 "M[]: full STX + full LDX",
2022 .u.insns = {
2023 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2024 BPF_STMT(BPF_STX, 0),
2025 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2026 BPF_STMT(BPF_STX, 1),
2027 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2028 BPF_STMT(BPF_STX, 2),
2029 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2030 BPF_STMT(BPF_STX, 3),
2031 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2032 BPF_STMT(BPF_STX, 4),
2033 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2034 BPF_STMT(BPF_STX, 5),
2035 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2036 BPF_STMT(BPF_STX, 6),
2037 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2038 BPF_STMT(BPF_STX, 7),
2039 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2040 BPF_STMT(BPF_STX, 8),
2041 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2042 BPF_STMT(BPF_STX, 9),
2043 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2044 BPF_STMT(BPF_STX, 10),
2045 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2046 BPF_STMT(BPF_STX, 11),
2047 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2048 BPF_STMT(BPF_STX, 12),
2049 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2050 BPF_STMT(BPF_STX, 13),
2051 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2052 BPF_STMT(BPF_STX, 14),
2053 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2054 BPF_STMT(BPF_STX, 15),
2055 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2056 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2057 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2058 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2059 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2060 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2061 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2062 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2063 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2064 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2065 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2066 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2067 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2068 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2069 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2070 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2071 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2072 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2073 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2074 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2075 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2076 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2077 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2078 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2079 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2080 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2081 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2082 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2083 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2084 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2085 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2086 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2087 BPF_STMT(BPF_RET | BPF_A, 0),
2088 },
2089 CLASSIC | FLAG_NO_DATA,
2090 { },
2091 { { 0, 0x2a5a5e5 } },
2092 },
2093 {
2094 "check: SKF_AD_MAX",
2095 .u.insns = {
2096 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2097 SKF_AD_OFF + SKF_AD_MAX),
2098 BPF_STMT(BPF_RET | BPF_A, 0),
2099 },
2100 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2101 { },
2102 { },
2103 .fill_helper = NULL,
2104 .expected_errcode = -EINVAL,
2105 },
2106 { /* Passes checker but fails during runtime. */
2107 "LD [SKF_AD_OFF-1]",
2108 .u.insns = {
2109 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2110 SKF_AD_OFF - 1),
2111 BPF_STMT(BPF_RET | BPF_K, 1),
2112 },
2113 CLASSIC,
2114 { },
2115 { { 1, 0 } },
2116 },
2117 {
2118 "load 64-bit immediate",
2119 .u.insns_int = {
2120 BPF_LD_IMM64(R1, 0x567800001234LL),
2121 BPF_MOV64_REG(R2, R1),
2122 BPF_MOV64_REG(R3, R2),
2123 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2124 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2125 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2126 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2127 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2128 BPF_EXIT_INSN(),
2129 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2130 BPF_EXIT_INSN(),
2131 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2132 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
2133 BPF_EXIT_INSN(),
2134 },
2135 INTERNAL,
2136 { },
2137 { { 0, 1 } }
2138 },
2139 {
2140 "nmap reduced",
2141 .u.insns_int = {
2142 BPF_MOV64_REG(R6, R1),
2143 BPF_LD_ABS(BPF_H, 12),
2144 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
2145 BPF_LD_ABS(BPF_H, 12),
2146 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
2147 BPF_MOV32_IMM(R0, 18),
2148 BPF_STX_MEM(BPF_W, R10, R0, -64),
2149 BPF_LDX_MEM(BPF_W, R7, R10, -64),
2150 BPF_LD_IND(BPF_W, R7, 14),
2151 BPF_STX_MEM(BPF_W, R10, R0, -60),
2152 BPF_MOV32_IMM(R0, 280971478),
2153 BPF_STX_MEM(BPF_W, R10, R0, -56),
2154 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2155 BPF_LDX_MEM(BPF_W, R0, R10, -60),
2156 BPF_ALU32_REG(BPF_SUB, R0, R7),
2157 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
2158 BPF_LD_ABS(BPF_H, 12),
2159 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
2160 BPF_MOV32_IMM(R0, 22),
2161 BPF_STX_MEM(BPF_W, R10, R0, -56),
2162 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2163 BPF_LD_IND(BPF_H, R7, 14),
2164 BPF_STX_MEM(BPF_W, R10, R0, -52),
2165 BPF_MOV32_IMM(R0, 17366),
2166 BPF_STX_MEM(BPF_W, R10, R0, -48),
2167 BPF_LDX_MEM(BPF_W, R7, R10, -48),
2168 BPF_LDX_MEM(BPF_W, R0, R10, -52),
2169 BPF_ALU32_REG(BPF_SUB, R0, R7),
2170 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
2171 BPF_MOV32_IMM(R0, 256),
2172 BPF_EXIT_INSN(),
2173 BPF_MOV32_IMM(R0, 0),
2174 BPF_EXIT_INSN(),
2175 },
2176 INTERNAL,
2177 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2178 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2179 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2180 { { 38, 256 } }
2181 },
2182 /* BPF_ALU | BPF_MOV | BPF_X */
2183 {
2184 "ALU_MOV_X: dst = 2",
2185 .u.insns_int = {
2186 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2187 BPF_ALU32_REG(BPF_MOV, R0, R1),
2188 BPF_EXIT_INSN(),
2189 },
2190 INTERNAL,
2191 { },
2192 { { 0, 2 } },
2193 },
2194 {
2195 "ALU_MOV_X: dst = 4294967295",
2196 .u.insns_int = {
2197 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2198 BPF_ALU32_REG(BPF_MOV, R0, R1),
2199 BPF_EXIT_INSN(),
2200 },
2201 INTERNAL,
2202 { },
2203 { { 0, 4294967295U } },
2204 },
2205 {
2206 "ALU64_MOV_X: dst = 2",
2207 .u.insns_int = {
2208 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2209 BPF_ALU64_REG(BPF_MOV, R0, R1),
2210 BPF_EXIT_INSN(),
2211 },
2212 INTERNAL,
2213 { },
2214 { { 0, 2 } },
2215 },
2216 {
2217 "ALU64_MOV_X: dst = 4294967295",
2218 .u.insns_int = {
2219 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2220 BPF_ALU64_REG(BPF_MOV, R0, R1),
2221 BPF_EXIT_INSN(),
2222 },
2223 INTERNAL,
2224 { },
2225 { { 0, 4294967295U } },
2226 },
2227 /* BPF_ALU | BPF_MOV | BPF_K */
2228 {
2229 "ALU_MOV_K: dst = 2",
2230 .u.insns_int = {
2231 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2232 BPF_EXIT_INSN(),
2233 },
2234 INTERNAL,
2235 { },
2236 { { 0, 2 } },
2237 },
2238 {
2239 "ALU_MOV_K: dst = 4294967295",
2240 .u.insns_int = {
2241 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
2242 BPF_EXIT_INSN(),
2243 },
2244 INTERNAL,
2245 { },
2246 { { 0, 4294967295U } },
2247 },
2248 {
2249 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2250 .u.insns_int = {
2251 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2252 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
2253 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2254 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2255 BPF_MOV32_IMM(R0, 2),
2256 BPF_EXIT_INSN(),
2257 BPF_MOV32_IMM(R0, 1),
2258 BPF_EXIT_INSN(),
2259 },
2260 INTERNAL,
2261 { },
2262 { { 0, 0x1 } },
2263 },
2264 {
2265 "ALU64_MOV_K: dst = 2",
2266 .u.insns_int = {
2267 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2268 BPF_EXIT_INSN(),
2269 },
2270 INTERNAL,
2271 { },
2272 { { 0, 2 } },
2273 },
2274 {
2275 "ALU64_MOV_K: dst = 2147483647",
2276 .u.insns_int = {
2277 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2278 BPF_EXIT_INSN(),
2279 },
2280 INTERNAL,
2281 { },
2282 { { 0, 2147483647 } },
2283 },
2284 {
2285 "ALU64_OR_K: dst = 0x0",
2286 .u.insns_int = {
2287 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2288 BPF_LD_IMM64(R3, 0x0),
2289 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2290 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2291 BPF_MOV32_IMM(R0, 2),
2292 BPF_EXIT_INSN(),
2293 BPF_MOV32_IMM(R0, 1),
2294 BPF_EXIT_INSN(),
2295 },
2296 INTERNAL,
2297 { },
2298 { { 0, 0x1 } },
2299 },
2300 {
2301 "ALU64_MOV_K: dst = -1",
2302 .u.insns_int = {
2303 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2304 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2305 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2306 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2307 BPF_MOV32_IMM(R0, 2),
2308 BPF_EXIT_INSN(),
2309 BPF_MOV32_IMM(R0, 1),
2310 BPF_EXIT_INSN(),
2311 },
2312 INTERNAL,
2313 { },
2314 { { 0, 0x1 } },
2315 },
2316 /* BPF_ALU | BPF_ADD | BPF_X */
2317 {
2318 "ALU_ADD_X: 1 + 2 = 3",
2319 .u.insns_int = {
2320 BPF_LD_IMM64(R0, 1),
2321 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2322 BPF_ALU32_REG(BPF_ADD, R0, R1),
2323 BPF_EXIT_INSN(),
2324 },
2325 INTERNAL,
2326 { },
2327 { { 0, 3 } },
2328 },
2329 {
2330 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2331 .u.insns_int = {
2332 BPF_LD_IMM64(R0, 1),
2333 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2334 BPF_ALU32_REG(BPF_ADD, R0, R1),
2335 BPF_EXIT_INSN(),
2336 },
2337 INTERNAL,
2338 { },
2339 { { 0, 4294967295U } },
2340 },
2341 {
2342 "ALU64_ADD_X: 1 + 2 = 3",
2343 .u.insns_int = {
2344 BPF_LD_IMM64(R0, 1),
2345 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2346 BPF_ALU64_REG(BPF_ADD, R0, R1),
2347 BPF_EXIT_INSN(),
2348 },
2349 INTERNAL,
2350 { },
2351 { { 0, 3 } },
2352 },
2353 {
2354 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2355 .u.insns_int = {
2356 BPF_LD_IMM64(R0, 1),
2357 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2358 BPF_ALU64_REG(BPF_ADD, R0, R1),
2359 BPF_EXIT_INSN(),
2360 },
2361 INTERNAL,
2362 { },
2363 { { 0, 4294967295U } },
2364 },
2365 /* BPF_ALU | BPF_ADD | BPF_K */
2366 {
2367 "ALU_ADD_K: 1 + 2 = 3",
2368 .u.insns_int = {
2369 BPF_LD_IMM64(R0, 1),
2370 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2371 BPF_EXIT_INSN(),
2372 },
2373 INTERNAL,
2374 { },
2375 { { 0, 3 } },
2376 },
2377 {
2378 "ALU_ADD_K: 3 + 0 = 3",
2379 .u.insns_int = {
2380 BPF_LD_IMM64(R0, 3),
2381 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2382 BPF_EXIT_INSN(),
2383 },
2384 INTERNAL,
2385 { },
2386 { { 0, 3 } },
2387 },
2388 {
2389 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2390 .u.insns_int = {
2391 BPF_LD_IMM64(R0, 1),
2392 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
2393 BPF_EXIT_INSN(),
2394 },
2395 INTERNAL,
2396 { },
2397 { { 0, 4294967295U } },
2398 },
2399 {
2400 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2401 .u.insns_int = {
2402 BPF_LD_IMM64(R2, 0x0),
2403 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2404 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2405 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2406 BPF_MOV32_IMM(R0, 2),
2407 BPF_EXIT_INSN(),
2408 BPF_MOV32_IMM(R0, 1),
2409 BPF_EXIT_INSN(),
2410 },
2411 INTERNAL,
2412 { },
2413 { { 0, 0x1 } },
2414 },
2415 {
2416 "ALU64_ADD_K: 1 + 2 = 3",
2417 .u.insns_int = {
2418 BPF_LD_IMM64(R0, 1),
2419 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2420 BPF_EXIT_INSN(),
2421 },
2422 INTERNAL,
2423 { },
2424 { { 0, 3 } },
2425 },
2426 {
2427 "ALU64_ADD_K: 3 + 0 = 3",
2428 .u.insns_int = {
2429 BPF_LD_IMM64(R0, 3),
2430 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2431 BPF_EXIT_INSN(),
2432 },
2433 INTERNAL,
2434 { },
2435 { { 0, 3 } },
2436 },
2437 {
2438 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2439 .u.insns_int = {
2440 BPF_LD_IMM64(R0, 1),
2441 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2442 BPF_EXIT_INSN(),
2443 },
2444 INTERNAL,
2445 { },
2446 { { 0, 2147483647 } },
2447 },
2448 {
2449 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2450 .u.insns_int = {
2451 BPF_LD_IMM64(R0, 2147483646),
2452 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2453 BPF_EXIT_INSN(),
2454 },
2455 INTERNAL,
2456 { },
2457 { { 0, -1 } },
2458 },
2459 {
2460 "ALU64_ADD_K: 1 + 0 = 1",
2461 .u.insns_int = {
2462 BPF_LD_IMM64(R2, 0x1),
2463 BPF_LD_IMM64(R3, 0x1),
2464 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2465 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2466 BPF_MOV32_IMM(R0, 2),
2467 BPF_EXIT_INSN(),
2468 BPF_MOV32_IMM(R0, 1),
2469 BPF_EXIT_INSN(),
2470 },
2471 INTERNAL,
2472 { },
2473 { { 0, 0x1 } },
2474 },
2475 {
2476 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2477 .u.insns_int = {
2478 BPF_LD_IMM64(R2, 0x0),
2479 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2480 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2481 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2482 BPF_MOV32_IMM(R0, 2),
2483 BPF_EXIT_INSN(),
2484 BPF_MOV32_IMM(R0, 1),
2485 BPF_EXIT_INSN(),
2486 },
2487 INTERNAL,
2488 { },
2489 { { 0, 0x1 } },
2490 },
2491 /* BPF_ALU | BPF_SUB | BPF_X */
2492 {
2493 "ALU_SUB_X: 3 - 1 = 2",
2494 .u.insns_int = {
2495 BPF_LD_IMM64(R0, 3),
2496 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2497 BPF_ALU32_REG(BPF_SUB, R0, R1),
2498 BPF_EXIT_INSN(),
2499 },
2500 INTERNAL,
2501 { },
2502 { { 0, 2 } },
2503 },
2504 {
2505 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2506 .u.insns_int = {
2507 BPF_LD_IMM64(R0, 4294967295U),
2508 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2509 BPF_ALU32_REG(BPF_SUB, R0, R1),
2510 BPF_EXIT_INSN(),
2511 },
2512 INTERNAL,
2513 { },
2514 { { 0, 1 } },
2515 },
2516 {
2517 "ALU64_SUB_X: 3 - 1 = 2",
2518 .u.insns_int = {
2519 BPF_LD_IMM64(R0, 3),
2520 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2521 BPF_ALU64_REG(BPF_SUB, R0, R1),
2522 BPF_EXIT_INSN(),
2523 },
2524 INTERNAL,
2525 { },
2526 { { 0, 2 } },
2527 },
2528 {
2529 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2530 .u.insns_int = {
2531 BPF_LD_IMM64(R0, 4294967295U),
2532 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
2533 BPF_ALU64_REG(BPF_SUB, R0, R1),
2534 BPF_EXIT_INSN(),
2535 },
2536 INTERNAL,
2537 { },
2538 { { 0, 1 } },
2539 },
2540 /* BPF_ALU | BPF_SUB | BPF_K */
2541 {
2542 "ALU_SUB_K: 3 - 1 = 2",
2543 .u.insns_int = {
2544 BPF_LD_IMM64(R0, 3),
2545 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2546 BPF_EXIT_INSN(),
2547 },
2548 INTERNAL,
2549 { },
2550 { { 0, 2 } },
2551 },
2552 {
2553 "ALU_SUB_K: 3 - 0 = 3",
2554 .u.insns_int = {
2555 BPF_LD_IMM64(R0, 3),
2556 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2557 BPF_EXIT_INSN(),
2558 },
2559 INTERNAL,
2560 { },
2561 { { 0, 3 } },
2562 },
2563 {
2564 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2565 .u.insns_int = {
2566 BPF_LD_IMM64(R0, 4294967295U),
2567 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
2568 BPF_EXIT_INSN(),
2569 },
2570 INTERNAL,
2571 { },
2572 { { 0, 1 } },
2573 },
2574 {
2575 "ALU64_SUB_K: 3 - 1 = 2",
2576 .u.insns_int = {
2577 BPF_LD_IMM64(R0, 3),
2578 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2579 BPF_EXIT_INSN(),
2580 },
2581 INTERNAL,
2582 { },
2583 { { 0, 2 } },
2584 },
2585 {
2586 "ALU64_SUB_K: 3 - 0 = 3",
2587 .u.insns_int = {
2588 BPF_LD_IMM64(R0, 3),
2589 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2590 BPF_EXIT_INSN(),
2591 },
2592 INTERNAL,
2593 { },
2594 { { 0, 3 } },
2595 },
2596 {
2597 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2598 .u.insns_int = {
2599 BPF_LD_IMM64(R0, 4294967294U),
2600 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
2601 BPF_EXIT_INSN(),
2602 },
2603 INTERNAL,
2604 { },
2605 { { 0, -1 } },
2606 },
2607 {
2608 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2609 .u.insns_int = {
2610 BPF_LD_IMM64(R0, 2147483646),
2611 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2612 BPF_EXIT_INSN(),
2613 },
2614 INTERNAL,
2615 { },
2616 { { 0, -1 } },
2617 },
2618 /* BPF_ALU | BPF_MUL | BPF_X */
2619 {
2620 "ALU_MUL_X: 2 * 3 = 6",
2621 .u.insns_int = {
2622 BPF_LD_IMM64(R0, 2),
2623 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2624 BPF_ALU32_REG(BPF_MUL, R0, R1),
2625 BPF_EXIT_INSN(),
2626 },
2627 INTERNAL,
2628 { },
2629 { { 0, 6 } },
2630 },
2631 {
2632 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2633 .u.insns_int = {
2634 BPF_LD_IMM64(R0, 2),
2635 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2636 BPF_ALU32_REG(BPF_MUL, R0, R1),
2637 BPF_EXIT_INSN(),
2638 },
2639 INTERNAL,
2640 { },
2641 { { 0, 0xFFFFFFF0 } },
2642 },
2643 {
2644 "ALU_MUL_X: -1 * -1 = 1",
2645 .u.insns_int = {
2646 BPF_LD_IMM64(R0, -1),
2647 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2648 BPF_ALU32_REG(BPF_MUL, R0, R1),
2649 BPF_EXIT_INSN(),
2650 },
2651 INTERNAL,
2652 { },
2653 { { 0, 1 } },
2654 },
2655 {
2656 "ALU64_MUL_X: 2 * 3 = 6",
2657 .u.insns_int = {
2658 BPF_LD_IMM64(R0, 2),
2659 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2660 BPF_ALU64_REG(BPF_MUL, R0, R1),
2661 BPF_EXIT_INSN(),
2662 },
2663 INTERNAL,
2664 { },
2665 { { 0, 6 } },
2666 },
2667 {
2668 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2669 .u.insns_int = {
2670 BPF_LD_IMM64(R0, 1),
2671 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2672 BPF_ALU64_REG(BPF_MUL, R0, R1),
2673 BPF_EXIT_INSN(),
2674 },
2675 INTERNAL,
2676 { },
2677 { { 0, 2147483647 } },
2678 },
2679 /* BPF_ALU | BPF_MUL | BPF_K */
2680 {
2681 "ALU_MUL_K: 2 * 3 = 6",
2682 .u.insns_int = {
2683 BPF_LD_IMM64(R0, 2),
2684 BPF_ALU32_IMM(BPF_MUL, R0, 3),
2685 BPF_EXIT_INSN(),
2686 },
2687 INTERNAL,
2688 { },
2689 { { 0, 6 } },
2690 },
2691 {
2692 "ALU_MUL_K: 3 * 1 = 3",
2693 .u.insns_int = {
2694 BPF_LD_IMM64(R0, 3),
2695 BPF_ALU32_IMM(BPF_MUL, R0, 1),
2696 BPF_EXIT_INSN(),
2697 },
2698 INTERNAL,
2699 { },
2700 { { 0, 3 } },
2701 },
2702 {
2703 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2704 .u.insns_int = {
2705 BPF_LD_IMM64(R0, 2),
2706 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
2707 BPF_EXIT_INSN(),
2708 },
2709 INTERNAL,
2710 { },
2711 { { 0, 0xFFFFFFF0 } },
2712 },
2713 {
2714 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
2715 .u.insns_int = {
2716 BPF_LD_IMM64(R2, 0x1),
2717 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2718 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
2719 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2720 BPF_MOV32_IMM(R0, 2),
2721 BPF_EXIT_INSN(),
2722 BPF_MOV32_IMM(R0, 1),
2723 BPF_EXIT_INSN(),
2724 },
2725 INTERNAL,
2726 { },
2727 { { 0, 0x1 } },
2728 },
2729 {
2730 "ALU64_MUL_K: 2 * 3 = 6",
2731 .u.insns_int = {
2732 BPF_LD_IMM64(R0, 2),
2733 BPF_ALU64_IMM(BPF_MUL, R0, 3),
2734 BPF_EXIT_INSN(),
2735 },
2736 INTERNAL,
2737 { },
2738 { { 0, 6 } },
2739 },
2740 {
2741 "ALU64_MUL_K: 3 * 1 = 3",
2742 .u.insns_int = {
2743 BPF_LD_IMM64(R0, 3),
2744 BPF_ALU64_IMM(BPF_MUL, R0, 1),
2745 BPF_EXIT_INSN(),
2746 },
2747 INTERNAL,
2748 { },
2749 { { 0, 3 } },
2750 },
2751 {
2752 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
2753 .u.insns_int = {
2754 BPF_LD_IMM64(R0, 1),
2755 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
2756 BPF_EXIT_INSN(),
2757 },
2758 INTERNAL,
2759 { },
2760 { { 0, 2147483647 } },
2761 },
2762 {
2763 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
2764 .u.insns_int = {
2765 BPF_LD_IMM64(R0, 1),
2766 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
2767 BPF_EXIT_INSN(),
2768 },
2769 INTERNAL,
2770 { },
2771 { { 0, -2147483647 } },
2772 },
2773 {
2774 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
2775 .u.insns_int = {
2776 BPF_LD_IMM64(R2, 0x1),
2777 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
2778 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
2779 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2780 BPF_MOV32_IMM(R0, 2),
2781 BPF_EXIT_INSN(),
2782 BPF_MOV32_IMM(R0, 1),
2783 BPF_EXIT_INSN(),
2784 },
2785 INTERNAL,
2786 { },
2787 { { 0, 0x1 } },
2788 },
2789 /* BPF_ALU | BPF_DIV | BPF_X */
2790 {
2791 "ALU_DIV_X: 6 / 2 = 3",
2792 .u.insns_int = {
2793 BPF_LD_IMM64(R0, 6),
2794 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2795 BPF_ALU32_REG(BPF_DIV, R0, R1),
2796 BPF_EXIT_INSN(),
2797 },
2798 INTERNAL,
2799 { },
2800 { { 0, 3 } },
2801 },
2802 {
2803 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
2804 .u.insns_int = {
2805 BPF_LD_IMM64(R0, 4294967295U),
2806 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
2807 BPF_ALU32_REG(BPF_DIV, R0, R1),
2808 BPF_EXIT_INSN(),
2809 },
2810 INTERNAL,
2811 { },
2812 { { 0, 1 } },
2813 },
2814 {
2815 "ALU64_DIV_X: 6 / 2 = 3",
2816 .u.insns_int = {
2817 BPF_LD_IMM64(R0, 6),
2818 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2819 BPF_ALU64_REG(BPF_DIV, R0, R1),
2820 BPF_EXIT_INSN(),
2821 },
2822 INTERNAL,
2823 { },
2824 { { 0, 3 } },
2825 },
2826 {
2827 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
2828 .u.insns_int = {
2829 BPF_LD_IMM64(R0, 2147483647),
2830 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2831 BPF_ALU64_REG(BPF_DIV, R0, R1),
2832 BPF_EXIT_INSN(),
2833 },
2834 INTERNAL,
2835 { },
2836 { { 0, 1 } },
2837 },
2838 {
2839 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2840 .u.insns_int = {
2841 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2842 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
2843 BPF_LD_IMM64(R3, 0x0000000000000001LL),
2844 BPF_ALU64_REG(BPF_DIV, R2, R4),
2845 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2846 BPF_MOV32_IMM(R0, 2),
2847 BPF_EXIT_INSN(),
2848 BPF_MOV32_IMM(R0, 1),
2849 BPF_EXIT_INSN(),
2850 },
2851 INTERNAL,
2852 { },
2853 { { 0, 0x1 } },
2854 },
2855 /* BPF_ALU | BPF_DIV | BPF_K */
2856 {
2857 "ALU_DIV_K: 6 / 2 = 3",
2858 .u.insns_int = {
2859 BPF_LD_IMM64(R0, 6),
2860 BPF_ALU32_IMM(BPF_DIV, R0, 2),
2861 BPF_EXIT_INSN(),
2862 },
2863 INTERNAL,
2864 { },
2865 { { 0, 3 } },
2866 },
2867 {
2868 "ALU_DIV_K: 3 / 1 = 3",
2869 .u.insns_int = {
2870 BPF_LD_IMM64(R0, 3),
2871 BPF_ALU32_IMM(BPF_DIV, R0, 1),
2872 BPF_EXIT_INSN(),
2873 },
2874 INTERNAL,
2875 { },
2876 { { 0, 3 } },
2877 },
2878 {
2879 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
2880 .u.insns_int = {
2881 BPF_LD_IMM64(R0, 4294967295U),
2882 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
2883 BPF_EXIT_INSN(),
2884 },
2885 INTERNAL,
2886 { },
2887 { { 0, 1 } },
2888 },
2889 {
2890 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
2891 .u.insns_int = {
2892 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2893 BPF_LD_IMM64(R3, 0x1UL),
2894 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
2895 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2896 BPF_MOV32_IMM(R0, 2),
2897 BPF_EXIT_INSN(),
2898 BPF_MOV32_IMM(R0, 1),
2899 BPF_EXIT_INSN(),
2900 },
2901 INTERNAL,
2902 { },
2903 { { 0, 0x1 } },
2904 },
2905 {
2906 "ALU64_DIV_K: 6 / 2 = 3",
2907 .u.insns_int = {
2908 BPF_LD_IMM64(R0, 6),
2909 BPF_ALU64_IMM(BPF_DIV, R0, 2),
2910 BPF_EXIT_INSN(),
2911 },
2912 INTERNAL,
2913 { },
2914 { { 0, 3 } },
2915 },
2916 {
2917 "ALU64_DIV_K: 3 / 1 = 3",
2918 .u.insns_int = {
2919 BPF_LD_IMM64(R0, 3),
2920 BPF_ALU64_IMM(BPF_DIV, R0, 1),
2921 BPF_EXIT_INSN(),
2922 },
2923 INTERNAL,
2924 { },
2925 { { 0, 3 } },
2926 },
2927 {
2928 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
2929 .u.insns_int = {
2930 BPF_LD_IMM64(R0, 2147483647),
2931 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
2932 BPF_EXIT_INSN(),
2933 },
2934 INTERNAL,
2935 { },
2936 { { 0, 1 } },
2937 },
2938 {
2939 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
2940 .u.insns_int = {
2941 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
2942 BPF_LD_IMM64(R3, 0x0000000000000001LL),
2943 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
2944 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2945 BPF_MOV32_IMM(R0, 2),
2946 BPF_EXIT_INSN(),
2947 BPF_MOV32_IMM(R0, 1),
2948 BPF_EXIT_INSN(),
2949 },
2950 INTERNAL,
2951 { },
2952 { { 0, 0x1 } },
2953 },
2954 /* BPF_ALU | BPF_MOD | BPF_X */
2955 {
2956 "ALU_MOD_X: 3 % 2 = 1",
2957 .u.insns_int = {
2958 BPF_LD_IMM64(R0, 3),
2959 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2960 BPF_ALU32_REG(BPF_MOD, R0, R1),
2961 BPF_EXIT_INSN(),
2962 },
2963 INTERNAL,
2964 { },
2965 { { 0, 1 } },
2966 },
2967 {
2968 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
2969 .u.insns_int = {
2970 BPF_LD_IMM64(R0, 4294967295U),
2971 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
2972 BPF_ALU32_REG(BPF_MOD, R0, R1),
2973 BPF_EXIT_INSN(),
2974 },
2975 INTERNAL,
2976 { },
2977 { { 0, 2 } },
2978 },
2979 {
2980 "ALU64_MOD_X: 3 % 2 = 1",
2981 .u.insns_int = {
2982 BPF_LD_IMM64(R0, 3),
2983 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2984 BPF_ALU64_REG(BPF_MOD, R0, R1),
2985 BPF_EXIT_INSN(),
2986 },
2987 INTERNAL,
2988 { },
2989 { { 0, 1 } },
2990 },
2991 {
2992 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
2993 .u.insns_int = {
2994 BPF_LD_IMM64(R0, 2147483647),
2995 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
2996 BPF_ALU64_REG(BPF_MOD, R0, R1),
2997 BPF_EXIT_INSN(),
2998 },
2999 INTERNAL,
3000 { },
3001 { { 0, 2 } },
3002 },
3003 /* BPF_ALU | BPF_MOD | BPF_K */
3004 {
3005 "ALU_MOD_K: 3 % 2 = 1",
3006 .u.insns_int = {
3007 BPF_LD_IMM64(R0, 3),
3008 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3009 BPF_EXIT_INSN(),
3010 },
3011 INTERNAL,
3012 { },
3013 { { 0, 1 } },
3014 },
3015 {
3016 "ALU_MOD_K: 3 % 1 = 0",
3017 .u.insns_int = {
3018 BPF_LD_IMM64(R0, 3),
3019 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3020 BPF_EXIT_INSN(),
3021 },
3022 INTERNAL,
3023 { },
3024 { { 0, 0 } },
3025 },
3026 {
3027 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3028 .u.insns_int = {
3029 BPF_LD_IMM64(R0, 4294967295U),
3030 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
3031 BPF_EXIT_INSN(),
3032 },
3033 INTERNAL,
3034 { },
3035 { { 0, 2 } },
3036 },
3037 {
3038 "ALU64_MOD_K: 3 % 2 = 1",
3039 .u.insns_int = {
3040 BPF_LD_IMM64(R0, 3),
3041 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3042 BPF_EXIT_INSN(),
3043 },
3044 INTERNAL,
3045 { },
3046 { { 0, 1 } },
3047 },
3048 {
3049 "ALU64_MOD_K: 3 % 1 = 0",
3050 .u.insns_int = {
3051 BPF_LD_IMM64(R0, 3),
3052 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3053 BPF_EXIT_INSN(),
3054 },
3055 INTERNAL,
3056 { },
3057 { { 0, 0 } },
3058 },
3059 {
3060 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3061 .u.insns_int = {
3062 BPF_LD_IMM64(R0, 2147483647),
3063 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3064 BPF_EXIT_INSN(),
3065 },
3066 INTERNAL,
3067 { },
3068 { { 0, 2 } },
3069 },
3070 /* BPF_ALU | BPF_AND | BPF_X */
3071 {
3072 "ALU_AND_X: 3 & 2 = 2",
3073 .u.insns_int = {
3074 BPF_LD_IMM64(R0, 3),
3075 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3076 BPF_ALU32_REG(BPF_AND, R0, R1),
3077 BPF_EXIT_INSN(),
3078 },
3079 INTERNAL,
3080 { },
3081 { { 0, 2 } },
3082 },
3083 {
3084 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3085 .u.insns_int = {
3086 BPF_LD_IMM64(R0, 0xffffffff),
3087 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3088 BPF_ALU32_REG(BPF_AND, R0, R1),
3089 BPF_EXIT_INSN(),
3090 },
3091 INTERNAL,
3092 { },
3093 { { 0, 0xffffffff } },
3094 },
3095 {
3096 "ALU64_AND_X: 3 & 2 = 2",
3097 .u.insns_int = {
3098 BPF_LD_IMM64(R0, 3),
3099 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3100 BPF_ALU64_REG(BPF_AND, R0, R1),
3101 BPF_EXIT_INSN(),
3102 },
3103 INTERNAL,
3104 { },
3105 { { 0, 2 } },
3106 },
3107 {
3108 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3109 .u.insns_int = {
3110 BPF_LD_IMM64(R0, 0xffffffff),
3111 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3112 BPF_ALU64_REG(BPF_AND, R0, R1),
3113 BPF_EXIT_INSN(),
3114 },
3115 INTERNAL,
3116 { },
3117 { { 0, 0xffffffff } },
3118 },
3119 /* BPF_ALU | BPF_AND | BPF_K */
3120 {
3121 "ALU_AND_K: 3 & 2 = 2",
3122 .u.insns_int = {
3123 BPF_LD_IMM64(R0, 3),
3124 BPF_ALU32_IMM(BPF_AND, R0, 2),
3125 BPF_EXIT_INSN(),
3126 },
3127 INTERNAL,
3128 { },
3129 { { 0, 2 } },
3130 },
3131 {
3132 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3133 .u.insns_int = {
3134 BPF_LD_IMM64(R0, 0xffffffff),
3135 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3136 BPF_EXIT_INSN(),
3137 },
3138 INTERNAL,
3139 { },
3140 { { 0, 0xffffffff } },
3141 },
3142 {
3143 "ALU64_AND_K: 3 & 2 = 2",
3144 .u.insns_int = {
3145 BPF_LD_IMM64(R0, 3),
3146 BPF_ALU64_IMM(BPF_AND, R0, 2),
3147 BPF_EXIT_INSN(),
3148 },
3149 INTERNAL,
3150 { },
3151 { { 0, 2 } },
3152 },
3153 {
3154 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3155 .u.insns_int = {
3156 BPF_LD_IMM64(R0, 0xffffffff),
3157 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3158 BPF_EXIT_INSN(),
3159 },
3160 INTERNAL,
3161 { },
3162 { { 0, 0xffffffff } },
3163 },
3164 {
3165 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3166 .u.insns_int = {
3167 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3168 BPF_LD_IMM64(R3, 0x0000000000000000LL),
3169 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3170 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3171 BPF_MOV32_IMM(R0, 2),
3172 BPF_EXIT_INSN(),
3173 BPF_MOV32_IMM(R0, 1),
3174 BPF_EXIT_INSN(),
3175 },
3176 INTERNAL,
3177 { },
3178 { { 0, 0x1 } },
3179 },
3180 {
3181 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3182 .u.insns_int = {
3183 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3184 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3185 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3186 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3187 BPF_MOV32_IMM(R0, 2),
3188 BPF_EXIT_INSN(),
3189 BPF_MOV32_IMM(R0, 1),
3190 BPF_EXIT_INSN(),
3191 },
3192 INTERNAL,
3193 { },
3194 { { 0, 0x1 } },
3195 },
3196 {
3197 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3198 .u.insns_int = {
3199 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3200 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3201 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3202 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3203 BPF_MOV32_IMM(R0, 2),
3204 BPF_EXIT_INSN(),
3205 BPF_MOV32_IMM(R0, 1),
3206 BPF_EXIT_INSN(),
3207 },
3208 INTERNAL,
3209 { },
3210 { { 0, 0x1 } },
3211 },
3212 /* BPF_ALU | BPF_OR | BPF_X */
3213 {
3214 "ALU_OR_X: 1 | 2 = 3",
3215 .u.insns_int = {
3216 BPF_LD_IMM64(R0, 1),
3217 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3218 BPF_ALU32_REG(BPF_OR, R0, R1),
3219 BPF_EXIT_INSN(),
3220 },
3221 INTERNAL,
3222 { },
3223 { { 0, 3 } },
3224 },
3225 {
3226 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3227 .u.insns_int = {
3228 BPF_LD_IMM64(R0, 0),
3229 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3230 BPF_ALU32_REG(BPF_OR, R0, R1),
3231 BPF_EXIT_INSN(),
3232 },
3233 INTERNAL,
3234 { },
3235 { { 0, 0xffffffff } },
3236 },
3237 {
3238 "ALU64_OR_X: 1 | 2 = 3",
3239 .u.insns_int = {
3240 BPF_LD_IMM64(R0, 1),
3241 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3242 BPF_ALU64_REG(BPF_OR, R0, R1),
3243 BPF_EXIT_INSN(),
3244 },
3245 INTERNAL,
3246 { },
3247 { { 0, 3 } },
3248 },
3249 {
3250 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3251 .u.insns_int = {
3252 BPF_LD_IMM64(R0, 0),
3253 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3254 BPF_ALU64_REG(BPF_OR, R0, R1),
3255 BPF_EXIT_INSN(),
3256 },
3257 INTERNAL,
3258 { },
3259 { { 0, 0xffffffff } },
3260 },
3261 /* BPF_ALU | BPF_OR | BPF_K */
3262 {
3263 "ALU_OR_K: 1 | 2 = 3",
3264 .u.insns_int = {
3265 BPF_LD_IMM64(R0, 1),
3266 BPF_ALU32_IMM(BPF_OR, R0, 2),
3267 BPF_EXIT_INSN(),
3268 },
3269 INTERNAL,
3270 { },
3271 { { 0, 3 } },
3272 },
3273 {
3274 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3275 .u.insns_int = {
3276 BPF_LD_IMM64(R0, 0),
3277 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3278 BPF_EXIT_INSN(),
3279 },
3280 INTERNAL,
3281 { },
3282 { { 0, 0xffffffff } },
3283 },
3284 {
3285 "ALU64_OR_K: 1 | 2 = 3",
3286 .u.insns_int = {
3287 BPF_LD_IMM64(R0, 1),
3288 BPF_ALU64_IMM(BPF_OR, R0, 2),
3289 BPF_EXIT_INSN(),
3290 },
3291 INTERNAL,
3292 { },
3293 { { 0, 3 } },
3294 },
3295 {
3296 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3297 .u.insns_int = {
3298 BPF_LD_IMM64(R0, 0),
3299 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3300 BPF_EXIT_INSN(),
3301 },
3302 INTERNAL,
3303 { },
3304 { { 0, 0xffffffff } },
3305 },
3306 {
3307 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3308 .u.insns_int = {
3309 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3310 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3311 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3312 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3313 BPF_MOV32_IMM(R0, 2),
3314 BPF_EXIT_INSN(),
3315 BPF_MOV32_IMM(R0, 1),
3316 BPF_EXIT_INSN(),
3317 },
3318 INTERNAL,
3319 { },
3320 { { 0, 0x1 } },
3321 },
3322 {
3323 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3324 .u.insns_int = {
3325 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3326 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3327 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3328 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3329 BPF_MOV32_IMM(R0, 2),
3330 BPF_EXIT_INSN(),
3331 BPF_MOV32_IMM(R0, 1),
3332 BPF_EXIT_INSN(),
3333 },
3334 INTERNAL,
3335 { },
3336 { { 0, 0x1 } },
3337 },
3338 {
3339 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3340 .u.insns_int = {
3341 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3342 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3343 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3344 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3345 BPF_MOV32_IMM(R0, 2),
3346 BPF_EXIT_INSN(),
3347 BPF_MOV32_IMM(R0, 1),
3348 BPF_EXIT_INSN(),
3349 },
3350 INTERNAL,
3351 { },
3352 { { 0, 0x1 } },
3353 },
3354 /* BPF_ALU | BPF_XOR | BPF_X */
3355 {
3356 "ALU_XOR_X: 5 ^ 6 = 3",
3357 .u.insns_int = {
3358 BPF_LD_IMM64(R0, 5),
3359 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3360 BPF_ALU32_REG(BPF_XOR, R0, R1),
3361 BPF_EXIT_INSN(),
3362 },
3363 INTERNAL,
3364 { },
3365 { { 0, 3 } },
3366 },
3367 {
3368 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3369 .u.insns_int = {
3370 BPF_LD_IMM64(R0, 1),
3371 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3372 BPF_ALU32_REG(BPF_XOR, R0, R1),
3373 BPF_EXIT_INSN(),
3374 },
3375 INTERNAL,
3376 { },
3377 { { 0, 0xfffffffe } },
3378 },
3379 {
3380 "ALU64_XOR_X: 5 ^ 6 = 3",
3381 .u.insns_int = {
3382 BPF_LD_IMM64(R0, 5),
3383 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3384 BPF_ALU64_REG(BPF_XOR, R0, R1),
3385 BPF_EXIT_INSN(),
3386 },
3387 INTERNAL,
3388 { },
3389 { { 0, 3 } },
3390 },
3391 {
3392 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3393 .u.insns_int = {
3394 BPF_LD_IMM64(R0, 1),
3395 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3396 BPF_ALU64_REG(BPF_XOR, R0, R1),
3397 BPF_EXIT_INSN(),
3398 },
3399 INTERNAL,
3400 { },
3401 { { 0, 0xfffffffe } },
3402 },
3403 /* BPF_ALU | BPF_XOR | BPF_K */
3404 {
3405 "ALU_XOR_K: 5 ^ 6 = 3",
3406 .u.insns_int = {
3407 BPF_LD_IMM64(R0, 5),
3408 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3409 BPF_EXIT_INSN(),
3410 },
3411 INTERNAL,
3412 { },
3413 { { 0, 3 } },
3414 },
3415 {
3416 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3417 .u.insns_int = {
3418 BPF_LD_IMM64(R0, 1),
3419 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3420 BPF_EXIT_INSN(),
3421 },
3422 INTERNAL,
3423 { },
3424 { { 0, 0xfffffffe } },
3425 },
3426 {
3427 "ALU64_XOR_K: 5 ^ 6 = 3",
3428 .u.insns_int = {
3429 BPF_LD_IMM64(R0, 5),
3430 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3431 BPF_EXIT_INSN(),
3432 },
3433 INTERNAL,
3434 { },
3435 { { 0, 3 } },
3436 },
3437 {
3438 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3439 .u.insns_int = {
3440 BPF_LD_IMM64(R0, 1),
3441 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3442 BPF_EXIT_INSN(),
3443 },
3444 INTERNAL,
3445 { },
3446 { { 0, 0xfffffffe } },
3447 },
3448 {
3449 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3450 .u.insns_int = {
3451 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3452 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
3453 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3454 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3455 BPF_MOV32_IMM(R0, 2),
3456 BPF_EXIT_INSN(),
3457 BPF_MOV32_IMM(R0, 1),
3458 BPF_EXIT_INSN(),
3459 },
3460 INTERNAL,
3461 { },
3462 { { 0, 0x1 } },
3463 },
3464 {
3465 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3466 .u.insns_int = {
3467 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3468 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
3469 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3470 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3471 BPF_MOV32_IMM(R0, 2),
3472 BPF_EXIT_INSN(),
3473 BPF_MOV32_IMM(R0, 1),
3474 BPF_EXIT_INSN(),
3475 },
3476 INTERNAL,
3477 { },
3478 { { 0, 0x1 } },
3479 },
3480 {
3481 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3482 .u.insns_int = {
3483 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3484 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3485 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3486 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3487 BPF_MOV32_IMM(R0, 2),
3488 BPF_EXIT_INSN(),
3489 BPF_MOV32_IMM(R0, 1),
3490 BPF_EXIT_INSN(),
3491 },
3492 INTERNAL,
3493 { },
3494 { { 0, 0x1 } },
3495 },
3496 /* BPF_ALU | BPF_LSH | BPF_X */
3497 {
3498 "ALU_LSH_X: 1 << 1 = 2",
3499 .u.insns_int = {
3500 BPF_LD_IMM64(R0, 1),
3501 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3502 BPF_ALU32_REG(BPF_LSH, R0, R1),
3503 BPF_EXIT_INSN(),
3504 },
3505 INTERNAL,
3506 { },
3507 { { 0, 2 } },
3508 },
3509 {
3510 "ALU_LSH_X: 1 << 31 = 0x80000000",
3511 .u.insns_int = {
3512 BPF_LD_IMM64(R0, 1),
3513 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3514 BPF_ALU32_REG(BPF_LSH, R0, R1),
3515 BPF_EXIT_INSN(),
3516 },
3517 INTERNAL,
3518 { },
3519 { { 0, 0x80000000 } },
3520 },
3521 {
3522 "ALU64_LSH_X: 1 << 1 = 2",
3523 .u.insns_int = {
3524 BPF_LD_IMM64(R0, 1),
3525 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3526 BPF_ALU64_REG(BPF_LSH, R0, R1),
3527 BPF_EXIT_INSN(),
3528 },
3529 INTERNAL,
3530 { },
3531 { { 0, 2 } },
3532 },
3533 {
3534 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3535 .u.insns_int = {
3536 BPF_LD_IMM64(R0, 1),
3537 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3538 BPF_ALU64_REG(BPF_LSH, R0, R1),
3539 BPF_EXIT_INSN(),
3540 },
3541 INTERNAL,
3542 { },
3543 { { 0, 0x80000000 } },
3544 },
3545 /* BPF_ALU | BPF_LSH | BPF_K */
3546 {
3547 "ALU_LSH_K: 1 << 1 = 2",
3548 .u.insns_int = {
3549 BPF_LD_IMM64(R0, 1),
3550 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3551 BPF_EXIT_INSN(),
3552 },
3553 INTERNAL,
3554 { },
3555 { { 0, 2 } },
3556 },
3557 {
3558 "ALU_LSH_K: 1 << 31 = 0x80000000",
3559 .u.insns_int = {
3560 BPF_LD_IMM64(R0, 1),
3561 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3562 BPF_EXIT_INSN(),
3563 },
3564 INTERNAL,
3565 { },
3566 { { 0, 0x80000000 } },
3567 },
3568 {
3569 "ALU64_LSH_K: 1 << 1 = 2",
3570 .u.insns_int = {
3571 BPF_LD_IMM64(R0, 1),
3572 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3573 BPF_EXIT_INSN(),
3574 },
3575 INTERNAL,
3576 { },
3577 { { 0, 2 } },
3578 },
3579 {
3580 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3581 .u.insns_int = {
3582 BPF_LD_IMM64(R0, 1),
3583 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3584 BPF_EXIT_INSN(),
3585 },
3586 INTERNAL,
3587 { },
3588 { { 0, 0x80000000 } },
3589 },
3590 /* BPF_ALU | BPF_RSH | BPF_X */
3591 {
3592 "ALU_RSH_X: 2 >> 1 = 1",
3593 .u.insns_int = {
3594 BPF_LD_IMM64(R0, 2),
3595 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3596 BPF_ALU32_REG(BPF_RSH, R0, R1),
3597 BPF_EXIT_INSN(),
3598 },
3599 INTERNAL,
3600 { },
3601 { { 0, 1 } },
3602 },
3603 {
3604 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3605 .u.insns_int = {
3606 BPF_LD_IMM64(R0, 0x80000000),
3607 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3608 BPF_ALU32_REG(BPF_RSH, R0, R1),
3609 BPF_EXIT_INSN(),
3610 },
3611 INTERNAL,
3612 { },
3613 { { 0, 1 } },
3614 },
3615 {
3616 "ALU64_RSH_X: 2 >> 1 = 1",
3617 .u.insns_int = {
3618 BPF_LD_IMM64(R0, 2),
3619 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3620 BPF_ALU64_REG(BPF_RSH, R0, R1),
3621 BPF_EXIT_INSN(),
3622 },
3623 INTERNAL,
3624 { },
3625 { { 0, 1 } },
3626 },
3627 {
3628 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3629 .u.insns_int = {
3630 BPF_LD_IMM64(R0, 0x80000000),
3631 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3632 BPF_ALU64_REG(BPF_RSH, R0, R1),
3633 BPF_EXIT_INSN(),
3634 },
3635 INTERNAL,
3636 { },
3637 { { 0, 1 } },
3638 },
3639 /* BPF_ALU | BPF_RSH | BPF_K */
3640 {
3641 "ALU_RSH_K: 2 >> 1 = 1",
3642 .u.insns_int = {
3643 BPF_LD_IMM64(R0, 2),
3644 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3645 BPF_EXIT_INSN(),
3646 },
3647 INTERNAL,
3648 { },
3649 { { 0, 1 } },
3650 },
3651 {
3652 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3653 .u.insns_int = {
3654 BPF_LD_IMM64(R0, 0x80000000),
3655 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3656 BPF_EXIT_INSN(),
3657 },
3658 INTERNAL,
3659 { },
3660 { { 0, 1 } },
3661 },
3662 {
3663 "ALU64_RSH_K: 2 >> 1 = 1",
3664 .u.insns_int = {
3665 BPF_LD_IMM64(R0, 2),
3666 BPF_ALU64_IMM(BPF_RSH, R0, 1),
3667 BPF_EXIT_INSN(),
3668 },
3669 INTERNAL,
3670 { },
3671 { { 0, 1 } },
3672 },
3673 {
3674 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3675 .u.insns_int = {
3676 BPF_LD_IMM64(R0, 0x80000000),
3677 BPF_ALU64_IMM(BPF_RSH, R0, 31),
3678 BPF_EXIT_INSN(),
3679 },
3680 INTERNAL,
3681 { },
3682 { { 0, 1 } },
3683 },
3684 /* BPF_ALU | BPF_ARSH | BPF_X */
3685 {
3686 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3687 .u.insns_int = {
3688 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3689 BPF_ALU32_IMM(BPF_MOV, R1, 40),
3690 BPF_ALU64_REG(BPF_ARSH, R0, R1),
3691 BPF_EXIT_INSN(),
3692 },
3693 INTERNAL,
3694 { },
3695 { { 0, 0xffff00ff } },
3696 },
3697 /* BPF_ALU | BPF_ARSH | BPF_K */
3698 {
3699 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3700 .u.insns_int = {
3701 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3702 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
3703 BPF_EXIT_INSN(),
3704 },
3705 INTERNAL,
3706 { },
3707 { { 0, 0xffff00ff } },
3708 },
3709 /* BPF_ALU | BPF_NEG */
3710 {
3711 "ALU_NEG: -(3) = -3",
3712 .u.insns_int = {
3713 BPF_ALU32_IMM(BPF_MOV, R0, 3),
3714 BPF_ALU32_IMM(BPF_NEG, R0, 0),
3715 BPF_EXIT_INSN(),
3716 },
3717 INTERNAL,
3718 { },
3719 { { 0, -3 } },
3720 },
3721 {
3722 "ALU_NEG: -(-3) = 3",
3723 .u.insns_int = {
3724 BPF_ALU32_IMM(BPF_MOV, R0, -3),
3725 BPF_ALU32_IMM(BPF_NEG, R0, 0),
3726 BPF_EXIT_INSN(),
3727 },
3728 INTERNAL,
3729 { },
3730 { { 0, 3 } },
3731 },
3732 {
3733 "ALU64_NEG: -(3) = -3",
3734 .u.insns_int = {
3735 BPF_LD_IMM64(R0, 3),
3736 BPF_ALU64_IMM(BPF_NEG, R0, 0),
3737 BPF_EXIT_INSN(),
3738 },
3739 INTERNAL,
3740 { },
3741 { { 0, -3 } },
3742 },
3743 {
3744 "ALU64_NEG: -(-3) = 3",
3745 .u.insns_int = {
3746 BPF_LD_IMM64(R0, -3),
3747 BPF_ALU64_IMM(BPF_NEG, R0, 0),
3748 BPF_EXIT_INSN(),
3749 },
3750 INTERNAL,
3751 { },
3752 { { 0, 3 } },
3753 },
3754 /* BPF_ALU | BPF_END | BPF_FROM_BE */
3755 {
3756 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
3757 .u.insns_int = {
3758 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3759 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
3760 BPF_EXIT_INSN(),
3761 },
3762 INTERNAL,
3763 { },
3764 { { 0, cpu_to_be16(0xcdef) } },
3765 },
3766 {
3767 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
3768 .u.insns_int = {
3769 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3770 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
3771 BPF_ALU64_REG(BPF_MOV, R1, R0),
3772 BPF_ALU64_IMM(BPF_RSH, R1, 32),
3773 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
3774 BPF_EXIT_INSN(),
3775 },
3776 INTERNAL,
3777 { },
3778 { { 0, cpu_to_be32(0x89abcdef) } },
3779 },
3780 {
3781 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
3782 .u.insns_int = {
3783 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3784 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
3785 BPF_EXIT_INSN(),
3786 },
3787 INTERNAL,
3788 { },
3789 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
3790 },
3791 /* BPF_ALU | BPF_END | BPF_FROM_LE */
3792 {
3793 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
3794 .u.insns_int = {
3795 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3796 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
3797 BPF_EXIT_INSN(),
3798 },
3799 INTERNAL,
3800 { },
3801 { { 0, cpu_to_le16(0xcdef) } },
3802 },
3803 {
3804 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
3805 .u.insns_int = {
3806 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3807 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
3808 BPF_ALU64_REG(BPF_MOV, R1, R0),
3809 BPF_ALU64_IMM(BPF_RSH, R1, 32),
3810 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
3811 BPF_EXIT_INSN(),
3812 },
3813 INTERNAL,
3814 { },
3815 { { 0, cpu_to_le32(0x89abcdef) } },
3816 },
3817 {
3818 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
3819 .u.insns_int = {
3820 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
3821 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
3822 BPF_EXIT_INSN(),
3823 },
3824 INTERNAL,
3825 { },
3826 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
3827 },
3828 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
3829 {
3830 "ST_MEM_B: Store/Load byte: max negative",
3831 .u.insns_int = {
3832 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3833 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
3834 BPF_LDX_MEM(BPF_B, R0, R10, -40),
3835 BPF_EXIT_INSN(),
3836 },
3837 INTERNAL,
3838 { },
3839 { { 0, 0xff } },
3840 },
3841 {
3842 "ST_MEM_B: Store/Load byte: max positive",
3843 .u.insns_int = {
3844 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3845 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
3846 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3847 BPF_EXIT_INSN(),
3848 },
3849 INTERNAL,
3850 { },
3851 { { 0, 0x7f } },
3852 },
3853 {
3854 "STX_MEM_B: Store/Load byte: max negative",
3855 .u.insns_int = {
3856 BPF_LD_IMM64(R0, 0),
3857 BPF_LD_IMM64(R1, 0xffLL),
3858 BPF_STX_MEM(BPF_B, R10, R1, -40),
3859 BPF_LDX_MEM(BPF_B, R0, R10, -40),
3860 BPF_EXIT_INSN(),
3861 },
3862 INTERNAL,
3863 { },
3864 { { 0, 0xff } },
3865 },
3866 {
3867 "ST_MEM_H: Store/Load half word: max negative",
3868 .u.insns_int = {
3869 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3870 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
3871 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3872 BPF_EXIT_INSN(),
3873 },
3874 INTERNAL,
3875 { },
3876 { { 0, 0xffff } },
3877 },
3878 {
3879 "ST_MEM_H: Store/Load half word: max positive",
3880 .u.insns_int = {
3881 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3882 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
3883 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3884 BPF_EXIT_INSN(),
3885 },
3886 INTERNAL,
3887 { },
3888 { { 0, 0x7fff } },
3889 },
3890 {
3891 "STX_MEM_H: Store/Load half word: max negative",
3892 .u.insns_int = {
3893 BPF_LD_IMM64(R0, 0),
3894 BPF_LD_IMM64(R1, 0xffffLL),
3895 BPF_STX_MEM(BPF_H, R10, R1, -40),
3896 BPF_LDX_MEM(BPF_H, R0, R10, -40),
3897 BPF_EXIT_INSN(),
3898 },
3899 INTERNAL,
3900 { },
3901 { { 0, 0xffff } },
3902 },
3903 {
3904 "ST_MEM_W: Store/Load word: max negative",
3905 .u.insns_int = {
3906 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3907 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
3908 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3909 BPF_EXIT_INSN(),
3910 },
3911 INTERNAL,
3912 { },
3913 { { 0, 0xffffffff } },
3914 },
3915 {
3916 "ST_MEM_W: Store/Load word: max positive",
3917 .u.insns_int = {
3918 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3919 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
3920 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3921 BPF_EXIT_INSN(),
3922 },
3923 INTERNAL,
3924 { },
3925 { { 0, 0x7fffffff } },
3926 },
3927 {
3928 "STX_MEM_W: Store/Load word: max negative",
3929 .u.insns_int = {
3930 BPF_LD_IMM64(R0, 0),
3931 BPF_LD_IMM64(R1, 0xffffffffLL),
3932 BPF_STX_MEM(BPF_W, R10, R1, -40),
3933 BPF_LDX_MEM(BPF_W, R0, R10, -40),
3934 BPF_EXIT_INSN(),
3935 },
3936 INTERNAL,
3937 { },
3938 { { 0, 0xffffffff } },
3939 },
3940 {
3941 "ST_MEM_DW: Store/Load double word: max negative",
3942 .u.insns_int = {
3943 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3944 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3945 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3946 BPF_EXIT_INSN(),
3947 },
3948 INTERNAL,
3949 { },
3950 { { 0, 0xffffffff } },
3951 },
3952 {
3953 "ST_MEM_DW: Store/Load double word: max negative 2",
3954 .u.insns_int = {
3955 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
3956 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
3957 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
3958 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
3959 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3960 BPF_MOV32_IMM(R0, 2),
3961 BPF_EXIT_INSN(),
3962 BPF_MOV32_IMM(R0, 1),
3963 BPF_EXIT_INSN(),
3964 },
3965 INTERNAL,
3966 { },
3967 { { 0, 0x1 } },
3968 },
3969 {
3970 "ST_MEM_DW: Store/Load double word: max positive",
3971 .u.insns_int = {
3972 BPF_ALU32_IMM(BPF_MOV, R0, 1),
3973 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
3974 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3975 BPF_EXIT_INSN(),
3976 },
3977 INTERNAL,
3978 { },
3979 { { 0, 0x7fffffff } },
3980 },
3981 {
3982 "STX_MEM_DW: Store/Load double word: max negative",
3983 .u.insns_int = {
3984 BPF_LD_IMM64(R0, 0),
3985 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
3986 BPF_STX_MEM(BPF_DW, R10, R1, -40),
3987 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
3988 BPF_EXIT_INSN(),
3989 },
3990 INTERNAL,
3991 { },
3992 { { 0, 0xffffffff } },
3993 },
3994 /* BPF_STX | BPF_XADD | BPF_W/DW */
3995 {
3996 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
3997 .u.insns_int = {
3998 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
3999 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4000 BPF_STX_XADD(BPF_W, R10, R0, -40),
4001 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4002 BPF_EXIT_INSN(),
4003 },
4004 INTERNAL,
4005 { },
4006 { { 0, 0x22 } },
4007 },
4008 {
4009 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4010 .u.insns_int = {
4011 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4012 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4013 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4014 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4015 BPF_EXIT_INSN(),
4016 },
4017 INTERNAL,
4018 { },
4019 { { 0, 0x22 } },
4020 },
4021 /* BPF_JMP | BPF_EXIT */
4022 {
4023 "JMP_EXIT",
4024 .u.insns_int = {
4025 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4026 BPF_EXIT_INSN(),
4027 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4028 },
4029 INTERNAL,
4030 { },
4031 { { 0, 0x4711 } },
4032 },
4033 /* BPF_JMP | BPF_JA */
4034 {
4035 "JMP_JA: Unconditional jump: if (true) return 1",
4036 .u.insns_int = {
4037 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4038 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4039 BPF_EXIT_INSN(),
4040 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4041 BPF_EXIT_INSN(),
4042 },
4043 INTERNAL,
4044 { },
4045 { { 0, 1 } },
4046 },
4047 /* BPF_JMP | BPF_JSGT | BPF_K */
4048 {
4049 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4050 .u.insns_int = {
4051 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4052 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4053 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4054 BPF_EXIT_INSN(),
4055 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4056 BPF_EXIT_INSN(),
4057 },
4058 INTERNAL,
4059 { },
4060 { { 0, 1 } },
4061 },
4062 {
4063 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4064 .u.insns_int = {
4065 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4066 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4067 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4068 BPF_EXIT_INSN(),
4069 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4070 BPF_EXIT_INSN(),
4071 },
4072 INTERNAL,
4073 { },
4074 { { 0, 1 } },
4075 },
4076 /* BPF_JMP | BPF_JSGE | BPF_K */
4077 {
4078 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4079 .u.insns_int = {
4080 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4081 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4082 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4083 BPF_EXIT_INSN(),
4084 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4085 BPF_EXIT_INSN(),
4086 },
4087 INTERNAL,
4088 { },
4089 { { 0, 1 } },
4090 },
4091 {
4092 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4093 .u.insns_int = {
4094 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4095 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4096 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4097 BPF_EXIT_INSN(),
4098 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4099 BPF_EXIT_INSN(),
4100 },
4101 INTERNAL,
4102 { },
4103 { { 0, 1 } },
4104 },
4105 /* BPF_JMP | BPF_JGT | BPF_K */
4106 {
4107 "JMP_JGT_K: if (3 > 2) return 1",
4108 .u.insns_int = {
4109 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4110 BPF_LD_IMM64(R1, 3),
4111 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4112 BPF_EXIT_INSN(),
4113 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4114 BPF_EXIT_INSN(),
4115 },
4116 INTERNAL,
4117 { },
4118 { { 0, 1 } },
4119 },
4120 /* BPF_JMP | BPF_JGE | BPF_K */
4121 {
4122 "JMP_JGE_K: if (3 >= 2) return 1",
4123 .u.insns_int = {
4124 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4125 BPF_LD_IMM64(R1, 3),
4126 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4127 BPF_EXIT_INSN(),
4128 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4129 BPF_EXIT_INSN(),
4130 },
4131 INTERNAL,
4132 { },
4133 { { 0, 1 } },
4134 },
4135 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4136 {
4137 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4138 .u.insns_int = {
4139 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4140 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4141 BPF_EXIT_INSN(),
4142 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4143 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4144 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4145 BPF_EXIT_INSN(),
4146 },
4147 INTERNAL,
4148 { },
4149 { { 0, 1 } },
4150 },
4151 {
4152 "JMP_JGE_K: if (3 >= 3) return 1",
4153 .u.insns_int = {
4154 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4155 BPF_LD_IMM64(R1, 3),
4156 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4157 BPF_EXIT_INSN(),
4158 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4159 BPF_EXIT_INSN(),
4160 },
4161 INTERNAL,
4162 { },
4163 { { 0, 1 } },
4164 },
4165 /* BPF_JMP | BPF_JNE | BPF_K */
4166 {
4167 "JMP_JNE_K: if (3 != 2) return 1",
4168 .u.insns_int = {
4169 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4170 BPF_LD_IMM64(R1, 3),
4171 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4172 BPF_EXIT_INSN(),
4173 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4174 BPF_EXIT_INSN(),
4175 },
4176 INTERNAL,
4177 { },
4178 { { 0, 1 } },
4179 },
4180 /* BPF_JMP | BPF_JEQ | BPF_K */
4181 {
4182 "JMP_JEQ_K: if (3 == 3) return 1",
4183 .u.insns_int = {
4184 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4185 BPF_LD_IMM64(R1, 3),
4186 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4187 BPF_EXIT_INSN(),
4188 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4189 BPF_EXIT_INSN(),
4190 },
4191 INTERNAL,
4192 { },
4193 { { 0, 1 } },
4194 },
4195 /* BPF_JMP | BPF_JSET | BPF_K */
4196 {
4197 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4198 .u.insns_int = {
4199 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4200 BPF_LD_IMM64(R1, 3),
4201 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4202 BPF_EXIT_INSN(),
4203 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4204 BPF_EXIT_INSN(),
4205 },
4206 INTERNAL,
4207 { },
4208 { { 0, 1 } },
4209 },
4210 {
4211 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4212 .u.insns_int = {
4213 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4214 BPF_LD_IMM64(R1, 3),
4215 BPF_JMP_IMM(BPF_JNE, R1, 0xffffffff, 1),
4216 BPF_EXIT_INSN(),
4217 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4218 BPF_EXIT_INSN(),
4219 },
4220 INTERNAL,
4221 { },
4222 { { 0, 1 } },
4223 },
4224 /* BPF_JMP | BPF_JSGT | BPF_X */
4225 {
4226 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4227 .u.insns_int = {
4228 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4229 BPF_LD_IMM64(R1, -1),
4230 BPF_LD_IMM64(R2, -2),
4231 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4232 BPF_EXIT_INSN(),
4233 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4234 BPF_EXIT_INSN(),
4235 },
4236 INTERNAL,
4237 { },
4238 { { 0, 1 } },
4239 },
4240 {
4241 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4242 .u.insns_int = {
4243 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4244 BPF_LD_IMM64(R1, -1),
4245 BPF_LD_IMM64(R2, -1),
4246 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4247 BPF_EXIT_INSN(),
4248 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4249 BPF_EXIT_INSN(),
4250 },
4251 INTERNAL,
4252 { },
4253 { { 0, 1 } },
4254 },
4255 /* BPF_JMP | BPF_JSGE | BPF_X */
4256 {
4257 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4258 .u.insns_int = {
4259 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4260 BPF_LD_IMM64(R1, -1),
4261 BPF_LD_IMM64(R2, -2),
4262 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4263 BPF_EXIT_INSN(),
4264 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4265 BPF_EXIT_INSN(),
4266 },
4267 INTERNAL,
4268 { },
4269 { { 0, 1 } },
4270 },
4271 {
4272 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4273 .u.insns_int = {
4274 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4275 BPF_LD_IMM64(R1, -1),
4276 BPF_LD_IMM64(R2, -1),
4277 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
4278 BPF_EXIT_INSN(),
4279 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4280 BPF_EXIT_INSN(),
4281 },
4282 INTERNAL,
4283 { },
4284 { { 0, 1 } },
4285 },
4286 /* BPF_JMP | BPF_JGT | BPF_X */
4287 {
4288 "JMP_JGT_X: if (3 > 2) return 1",
4289 .u.insns_int = {
4290 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4291 BPF_LD_IMM64(R1, 3),
4292 BPF_LD_IMM64(R2, 2),
4293 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4294 BPF_EXIT_INSN(),
4295 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4296 BPF_EXIT_INSN(),
4297 },
4298 INTERNAL,
4299 { },
4300 { { 0, 1 } },
4301 },
4302 /* BPF_JMP | BPF_JGE | BPF_X */
4303 {
4304 "JMP_JGE_X: if (3 >= 2) return 1",
4305 .u.insns_int = {
4306 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4307 BPF_LD_IMM64(R1, 3),
4308 BPF_LD_IMM64(R2, 2),
4309 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4310 BPF_EXIT_INSN(),
4311 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4312 BPF_EXIT_INSN(),
4313 },
4314 INTERNAL,
4315 { },
4316 { { 0, 1 } },
4317 },
4318 {
4319 "JMP_JGE_X: if (3 >= 3) return 1",
4320 .u.insns_int = {
4321 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4322 BPF_LD_IMM64(R1, 3),
4323 BPF_LD_IMM64(R2, 3),
4324 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
4325 BPF_EXIT_INSN(),
4326 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4327 BPF_EXIT_INSN(),
4328 },
4329 INTERNAL,
4330 { },
4331 { { 0, 1 } },
4332 },
4333 {
4334 /* Mainly testing JIT + imm64 here. */
4335 "JMP_JGE_X: ldimm64 test 1",
4336 .u.insns_int = {
4337 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4338 BPF_LD_IMM64(R1, 3),
4339 BPF_LD_IMM64(R2, 2),
4340 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
4341 BPF_LD_IMM64(R0, 0xffffffffffffffffUL),
4342 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeUL),
4343 BPF_EXIT_INSN(),
4344 },
4345 INTERNAL,
4346 { },
4347 { { 0, 0xeeeeeeeeU } },
4348 },
4349 {
4350 "JMP_JGE_X: ldimm64 test 2",
4351 .u.insns_int = {
4352 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4353 BPF_LD_IMM64(R1, 3),
4354 BPF_LD_IMM64(R2, 2),
4355 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
4356 BPF_LD_IMM64(R0, 0xffffffffffffffffUL),
4357 BPF_EXIT_INSN(),
4358 },
4359 INTERNAL,
4360 { },
4361 { { 0, 0xffffffffU } },
4362 },
4363 {
4364 "JMP_JGE_X: ldimm64 test 3",
4365 .u.insns_int = {
4366 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4367 BPF_LD_IMM64(R1, 3),
4368 BPF_LD_IMM64(R2, 2),
4369 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
4370 BPF_LD_IMM64(R0, 0xffffffffffffffffUL),
4371 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeUL),
4372 BPF_EXIT_INSN(),
4373 },
4374 INTERNAL,
4375 { },
4376 { { 0, 1 } },
4377 },
4378 /* BPF_JMP | BPF_JNE | BPF_X */
4379 {
4380 "JMP_JNE_X: if (3 != 2) return 1",
4381 .u.insns_int = {
4382 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4383 BPF_LD_IMM64(R1, 3),
4384 BPF_LD_IMM64(R2, 2),
4385 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4386 BPF_EXIT_INSN(),
4387 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4388 BPF_EXIT_INSN(),
4389 },
4390 INTERNAL,
4391 { },
4392 { { 0, 1 } },
4393 },
4394 /* BPF_JMP | BPF_JEQ | BPF_X */
4395 {
4396 "JMP_JEQ_X: if (3 == 3) return 1",
4397 .u.insns_int = {
4398 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4399 BPF_LD_IMM64(R1, 3),
4400 BPF_LD_IMM64(R2, 3),
4401 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
4402 BPF_EXIT_INSN(),
4403 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4404 BPF_EXIT_INSN(),
4405 },
4406 INTERNAL,
4407 { },
4408 { { 0, 1 } },
4409 },
4410 /* BPF_JMP | BPF_JSET | BPF_X */
4411 {
4412 "JMP_JSET_X: if (0x3 & 0x2) return 1",
4413 .u.insns_int = {
4414 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4415 BPF_LD_IMM64(R1, 3),
4416 BPF_LD_IMM64(R2, 2),
4417 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4418 BPF_EXIT_INSN(),
4419 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4420 BPF_EXIT_INSN(),
4421 },
4422 INTERNAL,
4423 { },
4424 { { 0, 1 } },
4425 },
4426 {
4427 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
4428 .u.insns_int = {
4429 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4430 BPF_LD_IMM64(R1, 3),
4431 BPF_LD_IMM64(R2, 0xffffffff),
4432 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
4433 BPF_EXIT_INSN(),
4434 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4435 BPF_EXIT_INSN(),
4436 },
4437 INTERNAL,
4438 { },
4439 { { 0, 1 } },
4440 },
4441 {
4442 "JMP_JA: Jump, gap, jump, ...",
4443 { },
4444 CLASSIC | FLAG_NO_DATA,
4445 { },
4446 { { 0, 0xababcbac } },
4447 .fill_helper = bpf_fill_ja,
4448 },
4449 { /* Mainly checking JIT here. */
4450 "BPF_MAXINSNS: Maximum possible literals",
4451 { },
4452 CLASSIC | FLAG_NO_DATA,
4453 { },
4454 { { 0, 0xffffffff } },
4455 .fill_helper = bpf_fill_maxinsns1,
4456 },
4457 { /* Mainly checking JIT here. */
4458 "BPF_MAXINSNS: Single literal",
4459 { },
4460 CLASSIC | FLAG_NO_DATA,
4461 { },
4462 { { 0, 0xfefefefe } },
4463 .fill_helper = bpf_fill_maxinsns2,
4464 },
4465 { /* Mainly checking JIT here. */
4466 "BPF_MAXINSNS: Run/add until end",
4467 { },
4468 CLASSIC | FLAG_NO_DATA,
4469 { },
4470 { { 0, 0x947bf368 } },
4471 .fill_helper = bpf_fill_maxinsns3,
4472 },
4473 {
4474 "BPF_MAXINSNS: Too many instructions",
4475 { },
4476 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4477 { },
4478 { },
4479 .fill_helper = bpf_fill_maxinsns4,
4480 .expected_errcode = -EINVAL,
4481 },
4482 { /* Mainly checking JIT here. */
4483 "BPF_MAXINSNS: Very long jump",
4484 { },
4485 CLASSIC | FLAG_NO_DATA,
4486 { },
4487 { { 0, 0xabababab } },
4488 .fill_helper = bpf_fill_maxinsns5,
4489 },
4490 { /* Mainly checking JIT here. */
4491 "BPF_MAXINSNS: Ctx heavy transformations",
4492 { },
4493 CLASSIC,
4494 { },
4495 {
4496 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
4497 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
4498 },
4499 .fill_helper = bpf_fill_maxinsns6,
4500 },
4501 { /* Mainly checking JIT here. */
4502 "BPF_MAXINSNS: Call heavy transformations",
4503 { },
4504 CLASSIC | FLAG_NO_DATA,
4505 { },
4506 { { 1, 0 }, { 10, 0 } },
4507 .fill_helper = bpf_fill_maxinsns7,
4508 },
4509 { /* Mainly checking JIT here. */
4510 "BPF_MAXINSNS: Jump heavy test",
4511 { },
4512 CLASSIC | FLAG_NO_DATA,
4513 { },
4514 { { 0, 0xffffffff } },
4515 .fill_helper = bpf_fill_maxinsns8,
4516 },
4517 { /* Mainly checking JIT here. */
4518 "BPF_MAXINSNS: Very long jump backwards",
4519 { },
4520 INTERNAL | FLAG_NO_DATA,
4521 { },
4522 { { 0, 0xcbababab } },
4523 .fill_helper = bpf_fill_maxinsns9,
4524 },
4525 { /* Mainly checking JIT here. */
4526 "BPF_MAXINSNS: Edge hopping nuthouse",
4527 { },
4528 INTERNAL | FLAG_NO_DATA,
4529 { },
4530 { { 0, 0xabababac } },
4531 .fill_helper = bpf_fill_maxinsns10,
4532 },
4533 {
4534 "BPF_MAXINSNS: Jump, gap, jump, ...",
4535 { },
4536 #ifdef CONFIG_BPF_JIT_ALWAYS_ON
4537 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4538 #else
4539 CLASSIC | FLAG_NO_DATA,
4540 #endif
4541 { },
4542 { { 0, 0xababcbac } },
4543 .fill_helper = bpf_fill_maxinsns11,
4544 .expected_errcode = -ENOTSUPP,
4545 },
4546 {
4547 "BPF_MAXINSNS: ld_abs+get_processor_id",
4548 { },
4549 CLASSIC,
4550 { },
4551 { { 1, 0xbee } },
4552 .fill_helper = bpf_fill_ld_abs_get_processor_id,
4553 },
4554 {
4555 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
4556 { },
4557 INTERNAL,
4558 { 0x34 },
4559 { { ETH_HLEN, 0xbef } },
4560 .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
4561 },
4562 /*
4563 * LD_IND / LD_ABS on fragmented SKBs
4564 */
4565 {
4566 "LD_IND byte frag",
4567 .u.insns = {
4568 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4569 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
4570 BPF_STMT(BPF_RET | BPF_A, 0x0),
4571 },
4572 CLASSIC | FLAG_SKB_FRAG,
4573 { },
4574 { {0x40, 0x42} },
4575 .frag_data = {
4576 0x42, 0x00, 0x00, 0x00,
4577 0x43, 0x44, 0x00, 0x00,
4578 0x21, 0x07, 0x19, 0x83,
4579 },
4580 },
4581 {
4582 "LD_IND halfword frag",
4583 .u.insns = {
4584 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4585 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
4586 BPF_STMT(BPF_RET | BPF_A, 0x0),
4587 },
4588 CLASSIC | FLAG_SKB_FRAG,
4589 { },
4590 { {0x40, 0x4344} },
4591 .frag_data = {
4592 0x42, 0x00, 0x00, 0x00,
4593 0x43, 0x44, 0x00, 0x00,
4594 0x21, 0x07, 0x19, 0x83,
4595 },
4596 },
4597 {
4598 "LD_IND word frag",
4599 .u.insns = {
4600 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4601 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
4602 BPF_STMT(BPF_RET | BPF_A, 0x0),
4603 },
4604 CLASSIC | FLAG_SKB_FRAG,
4605 { },
4606 { {0x40, 0x21071983} },
4607 .frag_data = {
4608 0x42, 0x00, 0x00, 0x00,
4609 0x43, 0x44, 0x00, 0x00,
4610 0x21, 0x07, 0x19, 0x83,
4611 },
4612 },
4613 {
4614 "LD_IND halfword mixed head/frag",
4615 .u.insns = {
4616 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4617 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
4618 BPF_STMT(BPF_RET | BPF_A, 0x0),
4619 },
4620 CLASSIC | FLAG_SKB_FRAG,
4621 { [0x3e] = 0x25, [0x3f] = 0x05, },
4622 { {0x40, 0x0519} },
4623 .frag_data = { 0x19, 0x82 },
4624 },
4625 {
4626 "LD_IND word mixed head/frag",
4627 .u.insns = {
4628 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
4629 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
4630 BPF_STMT(BPF_RET | BPF_A, 0x0),
4631 },
4632 CLASSIC | FLAG_SKB_FRAG,
4633 { [0x3e] = 0x25, [0x3f] = 0x05, },
4634 { {0x40, 0x25051982} },
4635 .frag_data = { 0x19, 0x82 },
4636 },
4637 {
4638 "LD_ABS byte frag",
4639 .u.insns = {
4640 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
4641 BPF_STMT(BPF_RET | BPF_A, 0x0),
4642 },
4643 CLASSIC | FLAG_SKB_FRAG,
4644 { },
4645 { {0x40, 0x42} },
4646 .frag_data = {
4647 0x42, 0x00, 0x00, 0x00,
4648 0x43, 0x44, 0x00, 0x00,
4649 0x21, 0x07, 0x19, 0x83,
4650 },
4651 },
4652 {
4653 "LD_ABS halfword frag",
4654 .u.insns = {
4655 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
4656 BPF_STMT(BPF_RET | BPF_A, 0x0),
4657 },
4658 CLASSIC | FLAG_SKB_FRAG,
4659 { },
4660 { {0x40, 0x4344} },
4661 .frag_data = {
4662 0x42, 0x00, 0x00, 0x00,
4663 0x43, 0x44, 0x00, 0x00,
4664 0x21, 0x07, 0x19, 0x83,
4665 },
4666 },
4667 {
4668 "LD_ABS word frag",
4669 .u.insns = {
4670 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
4671 BPF_STMT(BPF_RET | BPF_A, 0x0),
4672 },
4673 CLASSIC | FLAG_SKB_FRAG,
4674 { },
4675 { {0x40, 0x21071983} },
4676 .frag_data = {
4677 0x42, 0x00, 0x00, 0x00,
4678 0x43, 0x44, 0x00, 0x00,
4679 0x21, 0x07, 0x19, 0x83,
4680 },
4681 },
4682 {
4683 "LD_ABS halfword mixed head/frag",
4684 .u.insns = {
4685 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
4686 BPF_STMT(BPF_RET | BPF_A, 0x0),
4687 },
4688 CLASSIC | FLAG_SKB_FRAG,
4689 { [0x3e] = 0x25, [0x3f] = 0x05, },
4690 { {0x40, 0x0519} },
4691 .frag_data = { 0x19, 0x82 },
4692 },
4693 {
4694 "LD_ABS word mixed head/frag",
4695 .u.insns = {
4696 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
4697 BPF_STMT(BPF_RET | BPF_A, 0x0),
4698 },
4699 CLASSIC | FLAG_SKB_FRAG,
4700 { [0x3e] = 0x25, [0x3f] = 0x05, },
4701 { {0x40, 0x25051982} },
4702 .frag_data = { 0x19, 0x82 },
4703 },
4704 /*
4705 * LD_IND / LD_ABS on non fragmented SKBs
4706 */
4707 {
4708 /*
4709 * this tests that the JIT/interpreter correctly resets X
4710 * before using it in an LD_IND instruction.
4711 */
4712 "LD_IND byte default X",
4713 .u.insns = {
4714 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
4715 BPF_STMT(BPF_RET | BPF_A, 0x0),
4716 },
4717 CLASSIC,
4718 { [0x1] = 0x42 },
4719 { {0x40, 0x42 } },
4720 },
4721 {
4722 "LD_IND byte positive offset",
4723 .u.insns = {
4724 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
4725 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
4726 BPF_STMT(BPF_RET | BPF_A, 0x0),
4727 },
4728 CLASSIC,
4729 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
4730 { {0x40, 0x82 } },
4731 },
4732 {
4733 "LD_IND byte negative offset",
4734 .u.insns = {
4735 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
4736 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
4737 BPF_STMT(BPF_RET | BPF_A, 0x0),
4738 },
4739 CLASSIC,
4740 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
4741 { {0x40, 0x05 } },
4742 },
4743 {
4744 "LD_IND halfword positive offset",
4745 .u.insns = {
4746 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4747 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
4748 BPF_STMT(BPF_RET | BPF_A, 0x0),
4749 },
4750 CLASSIC,
4751 {
4752 [0x1c] = 0xaa, [0x1d] = 0x55,
4753 [0x1e] = 0xbb, [0x1f] = 0x66,
4754 [0x20] = 0xcc, [0x21] = 0x77,
4755 [0x22] = 0xdd, [0x23] = 0x88,
4756 },
4757 { {0x40, 0xdd88 } },
4758 },
4759 {
4760 "LD_IND halfword negative offset",
4761 .u.insns = {
4762 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4763 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
4764 BPF_STMT(BPF_RET | BPF_A, 0x0),
4765 },
4766 CLASSIC,
4767 {
4768 [0x1c] = 0xaa, [0x1d] = 0x55,
4769 [0x1e] = 0xbb, [0x1f] = 0x66,
4770 [0x20] = 0xcc, [0x21] = 0x77,
4771 [0x22] = 0xdd, [0x23] = 0x88,
4772 },
4773 { {0x40, 0xbb66 } },
4774 },
4775 {
4776 "LD_IND halfword unaligned",
4777 .u.insns = {
4778 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4779 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
4780 BPF_STMT(BPF_RET | BPF_A, 0x0),
4781 },
4782 CLASSIC,
4783 {
4784 [0x1c] = 0xaa, [0x1d] = 0x55,
4785 [0x1e] = 0xbb, [0x1f] = 0x66,
4786 [0x20] = 0xcc, [0x21] = 0x77,
4787 [0x22] = 0xdd, [0x23] = 0x88,
4788 },
4789 { {0x40, 0x66cc } },
4790 },
4791 {
4792 "LD_IND word positive offset",
4793 .u.insns = {
4794 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4795 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
4796 BPF_STMT(BPF_RET | BPF_A, 0x0),
4797 },
4798 CLASSIC,
4799 {
4800 [0x1c] = 0xaa, [0x1d] = 0x55,
4801 [0x1e] = 0xbb, [0x1f] = 0x66,
4802 [0x20] = 0xcc, [0x21] = 0x77,
4803 [0x22] = 0xdd, [0x23] = 0x88,
4804 [0x24] = 0xee, [0x25] = 0x99,
4805 [0x26] = 0xff, [0x27] = 0xaa,
4806 },
4807 { {0x40, 0xee99ffaa } },
4808 },
4809 {
4810 "LD_IND word negative offset",
4811 .u.insns = {
4812 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4813 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
4814 BPF_STMT(BPF_RET | BPF_A, 0x0),
4815 },
4816 CLASSIC,
4817 {
4818 [0x1c] = 0xaa, [0x1d] = 0x55,
4819 [0x1e] = 0xbb, [0x1f] = 0x66,
4820 [0x20] = 0xcc, [0x21] = 0x77,
4821 [0x22] = 0xdd, [0x23] = 0x88,
4822 [0x24] = 0xee, [0x25] = 0x99,
4823 [0x26] = 0xff, [0x27] = 0xaa,
4824 },
4825 { {0x40, 0xaa55bb66 } },
4826 },
4827 {
4828 "LD_IND word unaligned (addr & 3 == 2)",
4829 .u.insns = {
4830 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4831 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
4832 BPF_STMT(BPF_RET | BPF_A, 0x0),
4833 },
4834 CLASSIC,
4835 {
4836 [0x1c] = 0xaa, [0x1d] = 0x55,
4837 [0x1e] = 0xbb, [0x1f] = 0x66,
4838 [0x20] = 0xcc, [0x21] = 0x77,
4839 [0x22] = 0xdd, [0x23] = 0x88,
4840 [0x24] = 0xee, [0x25] = 0x99,
4841 [0x26] = 0xff, [0x27] = 0xaa,
4842 },
4843 { {0x40, 0xbb66cc77 } },
4844 },
4845 {
4846 "LD_IND word unaligned (addr & 3 == 1)",
4847 .u.insns = {
4848 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4849 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
4850 BPF_STMT(BPF_RET | BPF_A, 0x0),
4851 },
4852 CLASSIC,
4853 {
4854 [0x1c] = 0xaa, [0x1d] = 0x55,
4855 [0x1e] = 0xbb, [0x1f] = 0x66,
4856 [0x20] = 0xcc, [0x21] = 0x77,
4857 [0x22] = 0xdd, [0x23] = 0x88,
4858 [0x24] = 0xee, [0x25] = 0x99,
4859 [0x26] = 0xff, [0x27] = 0xaa,
4860 },
4861 { {0x40, 0x55bb66cc } },
4862 },
4863 {
4864 "LD_IND word unaligned (addr & 3 == 3)",
4865 .u.insns = {
4866 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
4867 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
4868 BPF_STMT(BPF_RET | BPF_A, 0x0),
4869 },
4870 CLASSIC,
4871 {
4872 [0x1c] = 0xaa, [0x1d] = 0x55,
4873 [0x1e] = 0xbb, [0x1f] = 0x66,
4874 [0x20] = 0xcc, [0x21] = 0x77,
4875 [0x22] = 0xdd, [0x23] = 0x88,
4876 [0x24] = 0xee, [0x25] = 0x99,
4877 [0x26] = 0xff, [0x27] = 0xaa,
4878 },
4879 { {0x40, 0x66cc77dd } },
4880 },
4881 {
4882 "LD_ABS byte",
4883 .u.insns = {
4884 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
4885 BPF_STMT(BPF_RET | BPF_A, 0x0),
4886 },
4887 CLASSIC,
4888 {
4889 [0x1c] = 0xaa, [0x1d] = 0x55,
4890 [0x1e] = 0xbb, [0x1f] = 0x66,
4891 [0x20] = 0xcc, [0x21] = 0x77,
4892 [0x22] = 0xdd, [0x23] = 0x88,
4893 [0x24] = 0xee, [0x25] = 0x99,
4894 [0x26] = 0xff, [0x27] = 0xaa,
4895 },
4896 { {0x40, 0xcc } },
4897 },
4898 {
4899 "LD_ABS halfword",
4900 .u.insns = {
4901 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
4902 BPF_STMT(BPF_RET | BPF_A, 0x0),
4903 },
4904 CLASSIC,
4905 {
4906 [0x1c] = 0xaa, [0x1d] = 0x55,
4907 [0x1e] = 0xbb, [0x1f] = 0x66,
4908 [0x20] = 0xcc, [0x21] = 0x77,
4909 [0x22] = 0xdd, [0x23] = 0x88,
4910 [0x24] = 0xee, [0x25] = 0x99,
4911 [0x26] = 0xff, [0x27] = 0xaa,
4912 },
4913 { {0x40, 0xdd88 } },
4914 },
4915 {
4916 "LD_ABS halfword unaligned",
4917 .u.insns = {
4918 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
4919 BPF_STMT(BPF_RET | BPF_A, 0x0),
4920 },
4921 CLASSIC,
4922 {
4923 [0x1c] = 0xaa, [0x1d] = 0x55,
4924 [0x1e] = 0xbb, [0x1f] = 0x66,
4925 [0x20] = 0xcc, [0x21] = 0x77,
4926 [0x22] = 0xdd, [0x23] = 0x88,
4927 [0x24] = 0xee, [0x25] = 0x99,
4928 [0x26] = 0xff, [0x27] = 0xaa,
4929 },
4930 { {0x40, 0x99ff } },
4931 },
4932 {
4933 "LD_ABS word",
4934 .u.insns = {
4935 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
4936 BPF_STMT(BPF_RET | BPF_A, 0x0),
4937 },
4938 CLASSIC,
4939 {
4940 [0x1c] = 0xaa, [0x1d] = 0x55,
4941 [0x1e] = 0xbb, [0x1f] = 0x66,
4942 [0x20] = 0xcc, [0x21] = 0x77,
4943 [0x22] = 0xdd, [0x23] = 0x88,
4944 [0x24] = 0xee, [0x25] = 0x99,
4945 [0x26] = 0xff, [0x27] = 0xaa,
4946 },
4947 { {0x40, 0xaa55bb66 } },
4948 },
4949 {
4950 "LD_ABS word unaligned (addr & 3 == 2)",
4951 .u.insns = {
4952 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
4953 BPF_STMT(BPF_RET | BPF_A, 0x0),
4954 },
4955 CLASSIC,
4956 {
4957 [0x1c] = 0xaa, [0x1d] = 0x55,
4958 [0x1e] = 0xbb, [0x1f] = 0x66,
4959 [0x20] = 0xcc, [0x21] = 0x77,
4960 [0x22] = 0xdd, [0x23] = 0x88,
4961 [0x24] = 0xee, [0x25] = 0x99,
4962 [0x26] = 0xff, [0x27] = 0xaa,
4963 },
4964 { {0x40, 0xdd88ee99 } },
4965 },
4966 {
4967 "LD_ABS word unaligned (addr & 3 == 1)",
4968 .u.insns = {
4969 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
4970 BPF_STMT(BPF_RET | BPF_A, 0x0),
4971 },
4972 CLASSIC,
4973 {
4974 [0x1c] = 0xaa, [0x1d] = 0x55,
4975 [0x1e] = 0xbb, [0x1f] = 0x66,
4976 [0x20] = 0xcc, [0x21] = 0x77,
4977 [0x22] = 0xdd, [0x23] = 0x88,
4978 [0x24] = 0xee, [0x25] = 0x99,
4979 [0x26] = 0xff, [0x27] = 0xaa,
4980 },
4981 { {0x40, 0x77dd88ee } },
4982 },
4983 {
4984 "LD_ABS word unaligned (addr & 3 == 3)",
4985 .u.insns = {
4986 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
4987 BPF_STMT(BPF_RET | BPF_A, 0x0),
4988 },
4989 CLASSIC,
4990 {
4991 [0x1c] = 0xaa, [0x1d] = 0x55,
4992 [0x1e] = 0xbb, [0x1f] = 0x66,
4993 [0x20] = 0xcc, [0x21] = 0x77,
4994 [0x22] = 0xdd, [0x23] = 0x88,
4995 [0x24] = 0xee, [0x25] = 0x99,
4996 [0x26] = 0xff, [0x27] = 0xaa,
4997 },
4998 { {0x40, 0x88ee99ff } },
4999 },
5000 /*
5001 * verify that the interpreter or JIT correctly sets A and X
5002 * to 0.
5003 */
5004 {
5005 "ADD default X",
5006 .u.insns = {
5007 /*
5008 * A = 0x42
5009 * A = A + X
5010 * ret A
5011 */
5012 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5013 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
5014 BPF_STMT(BPF_RET | BPF_A, 0x0),
5015 },
5016 CLASSIC | FLAG_NO_DATA,
5017 {},
5018 { {0x1, 0x42 } },
5019 },
5020 {
5021 "ADD default A",
5022 .u.insns = {
5023 /*
5024 * A = A + 0x42
5025 * ret A
5026 */
5027 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
5028 BPF_STMT(BPF_RET | BPF_A, 0x0),
5029 },
5030 CLASSIC | FLAG_NO_DATA,
5031 {},
5032 { {0x1, 0x42 } },
5033 },
5034 {
5035 "SUB default X",
5036 .u.insns = {
5037 /*
5038 * A = 0x66
5039 * A = A - X
5040 * ret A
5041 */
5042 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
5043 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
5044 BPF_STMT(BPF_RET | BPF_A, 0x0),
5045 },
5046 CLASSIC | FLAG_NO_DATA,
5047 {},
5048 { {0x1, 0x66 } },
5049 },
5050 {
5051 "SUB default A",
5052 .u.insns = {
5053 /*
5054 * A = A - -0x66
5055 * ret A
5056 */
5057 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
5058 BPF_STMT(BPF_RET | BPF_A, 0x0),
5059 },
5060 CLASSIC | FLAG_NO_DATA,
5061 {},
5062 { {0x1, 0x66 } },
5063 },
5064 {
5065 "MUL default X",
5066 .u.insns = {
5067 /*
5068 * A = 0x42
5069 * A = A * X
5070 * ret A
5071 */
5072 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5073 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
5074 BPF_STMT(BPF_RET | BPF_A, 0x0),
5075 },
5076 CLASSIC | FLAG_NO_DATA,
5077 {},
5078 { {0x1, 0x0 } },
5079 },
5080 {
5081 "MUL default A",
5082 .u.insns = {
5083 /*
5084 * A = A * 0x66
5085 * ret A
5086 */
5087 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
5088 BPF_STMT(BPF_RET | BPF_A, 0x0),
5089 },
5090 CLASSIC | FLAG_NO_DATA,
5091 {},
5092 { {0x1, 0x0 } },
5093 },
5094 {
5095 "DIV default X",
5096 .u.insns = {
5097 /*
5098 * A = 0x42
5099 * A = A / X ; this halt the filter execution if X is 0
5100 * ret 0x42
5101 */
5102 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5103 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
5104 BPF_STMT(BPF_RET | BPF_K, 0x42),
5105 },
5106 CLASSIC | FLAG_NO_DATA,
5107 {},
5108 { {0x1, 0x0 } },
5109 },
5110 {
5111 "DIV default A",
5112 .u.insns = {
5113 /*
5114 * A = A / 1
5115 * ret A
5116 */
5117 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
5118 BPF_STMT(BPF_RET | BPF_A, 0x0),
5119 },
5120 CLASSIC | FLAG_NO_DATA,
5121 {},
5122 { {0x1, 0x0 } },
5123 },
5124 {
5125 "MOD default X",
5126 .u.insns = {
5127 /*
5128 * A = 0x42
5129 * A = A mod X ; this halt the filter execution if X is 0
5130 * ret 0x42
5131 */
5132 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5133 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
5134 BPF_STMT(BPF_RET | BPF_K, 0x42),
5135 },
5136 CLASSIC | FLAG_NO_DATA,
5137 {},
5138 { {0x1, 0x0 } },
5139 },
5140 {
5141 "MOD default A",
5142 .u.insns = {
5143 /*
5144 * A = A mod 1
5145 * ret A
5146 */
5147 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
5148 BPF_STMT(BPF_RET | BPF_A, 0x0),
5149 },
5150 CLASSIC | FLAG_NO_DATA,
5151 {},
5152 { {0x1, 0x0 } },
5153 },
5154 {
5155 "JMP EQ default A",
5156 .u.insns = {
5157 /*
5158 * cmp A, 0x0, 0, 1
5159 * ret 0x42
5160 * ret 0x66
5161 */
5162 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
5163 BPF_STMT(BPF_RET | BPF_K, 0x42),
5164 BPF_STMT(BPF_RET | BPF_K, 0x66),
5165 },
5166 CLASSIC | FLAG_NO_DATA,
5167 {},
5168 { {0x1, 0x42 } },
5169 },
5170 {
5171 "JMP EQ default X",
5172 .u.insns = {
5173 /*
5174 * A = 0x0
5175 * cmp A, X, 0, 1
5176 * ret 0x42
5177 * ret 0x66
5178 */
5179 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
5180 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
5181 BPF_STMT(BPF_RET | BPF_K, 0x42),
5182 BPF_STMT(BPF_RET | BPF_K, 0x66),
5183 },
5184 CLASSIC | FLAG_NO_DATA,
5185 {},
5186 { {0x1, 0x42 } },
5187 },
5188 };
5189
5190 static struct net_device dev;
5191
populate_skb(char * buf,int size)5192 static struct sk_buff *populate_skb(char *buf, int size)
5193 {
5194 struct sk_buff *skb;
5195
5196 if (size >= MAX_DATA)
5197 return NULL;
5198
5199 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
5200 if (!skb)
5201 return NULL;
5202
5203 memcpy(__skb_put(skb, size), buf, size);
5204
5205 /* Initialize a fake skb with test pattern. */
5206 skb_reset_mac_header(skb);
5207 skb->protocol = htons(ETH_P_IP);
5208 skb->pkt_type = SKB_TYPE;
5209 skb->mark = SKB_MARK;
5210 skb->hash = SKB_HASH;
5211 skb->queue_mapping = SKB_QUEUE_MAP;
5212 skb->vlan_tci = SKB_VLAN_TCI;
5213 skb->dev = &dev;
5214 skb->dev->ifindex = SKB_DEV_IFINDEX;
5215 skb->dev->type = SKB_DEV_TYPE;
5216 skb_set_network_header(skb, min(size, ETH_HLEN));
5217
5218 return skb;
5219 }
5220
generate_test_data(struct bpf_test * test,int sub)5221 static void *generate_test_data(struct bpf_test *test, int sub)
5222 {
5223 struct sk_buff *skb;
5224 struct page *page;
5225
5226 if (test->aux & FLAG_NO_DATA)
5227 return NULL;
5228
5229 /* Test case expects an skb, so populate one. Various
5230 * subtests generate skbs of different sizes based on
5231 * the same data.
5232 */
5233 skb = populate_skb(test->data, test->test[sub].data_size);
5234 if (!skb)
5235 return NULL;
5236
5237 if (test->aux & FLAG_SKB_FRAG) {
5238 /*
5239 * when the test requires a fragmented skb, add a
5240 * single fragment to the skb, filled with
5241 * test->frag_data.
5242 */
5243 void *ptr;
5244
5245 page = alloc_page(GFP_KERNEL);
5246
5247 if (!page)
5248 goto err_kfree_skb;
5249
5250 ptr = kmap(page);
5251 if (!ptr)
5252 goto err_free_page;
5253 memcpy(ptr, test->frag_data, MAX_DATA);
5254 kunmap(page);
5255 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
5256 }
5257
5258 return skb;
5259
5260 err_free_page:
5261 __free_page(page);
5262 err_kfree_skb:
5263 kfree_skb(skb);
5264 return NULL;
5265 }
5266
release_test_data(const struct bpf_test * test,void * data)5267 static void release_test_data(const struct bpf_test *test, void *data)
5268 {
5269 if (test->aux & FLAG_NO_DATA)
5270 return;
5271
5272 kfree_skb(data);
5273 }
5274
filter_length(int which)5275 static int filter_length(int which)
5276 {
5277 struct sock_filter *fp;
5278 int len;
5279
5280 if (tests[which].fill_helper)
5281 return tests[which].u.ptr.len;
5282
5283 fp = tests[which].u.insns;
5284 for (len = MAX_INSNS - 1; len > 0; --len)
5285 if (fp[len].code != 0 || fp[len].k != 0)
5286 break;
5287
5288 return len + 1;
5289 }
5290
filter_pointer(int which)5291 static void *filter_pointer(int which)
5292 {
5293 if (tests[which].fill_helper)
5294 return tests[which].u.ptr.insns;
5295 else
5296 return tests[which].u.insns;
5297 }
5298
generate_filter(int which,int * err)5299 static struct bpf_prog *generate_filter(int which, int *err)
5300 {
5301 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
5302 unsigned int flen = filter_length(which);
5303 void *fptr = filter_pointer(which);
5304 struct sock_fprog_kern fprog;
5305 struct bpf_prog *fp;
5306
5307 switch (test_type) {
5308 case CLASSIC:
5309 fprog.filter = fptr;
5310 fprog.len = flen;
5311
5312 *err = bpf_prog_create(&fp, &fprog);
5313 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
5314 if (*err == tests[which].expected_errcode) {
5315 pr_cont("PASS\n");
5316 /* Verifier rejected filter as expected. */
5317 *err = 0;
5318 return NULL;
5319 } else {
5320 pr_cont("UNEXPECTED_PASS\n");
5321 /* Verifier didn't reject the test that's
5322 * bad enough, just return!
5323 */
5324 *err = -EINVAL;
5325 return NULL;
5326 }
5327 }
5328 if (*err) {
5329 pr_cont("FAIL to prog_create err=%d len=%d\n",
5330 *err, fprog.len);
5331 return NULL;
5332 }
5333 break;
5334
5335 case INTERNAL:
5336 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
5337 if (fp == NULL) {
5338 pr_cont("UNEXPECTED_FAIL no memory left\n");
5339 *err = -ENOMEM;
5340 return NULL;
5341 }
5342
5343 fp->len = flen;
5344 /* Type doesn't really matter here as long as it's not unspec. */
5345 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
5346 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
5347
5348 *err = bpf_prog_select_runtime(fp);
5349 if (*err) {
5350 pr_cont("FAIL to select_runtime err=%d\n", *err);
5351 return NULL;
5352 }
5353 break;
5354 }
5355
5356 *err = 0;
5357 return fp;
5358 }
5359
release_filter(struct bpf_prog * fp,int which)5360 static void release_filter(struct bpf_prog *fp, int which)
5361 {
5362 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
5363
5364 switch (test_type) {
5365 case CLASSIC:
5366 bpf_prog_destroy(fp);
5367 break;
5368 case INTERNAL:
5369 bpf_prog_free(fp);
5370 break;
5371 }
5372 }
5373
__run_one(const struct bpf_prog * fp,const void * data,int runs,u64 * duration)5374 static int __run_one(const struct bpf_prog *fp, const void *data,
5375 int runs, u64 *duration)
5376 {
5377 u64 start, finish;
5378 int ret = 0, i;
5379
5380 start = ktime_get_ns();
5381
5382 for (i = 0; i < runs; i++)
5383 ret = BPF_PROG_RUN(fp, data);
5384
5385 finish = ktime_get_ns();
5386
5387 *duration = finish - start;
5388 do_div(*duration, runs);
5389
5390 return ret;
5391 }
5392
run_one(const struct bpf_prog * fp,struct bpf_test * test)5393 static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
5394 {
5395 int err_cnt = 0, i, runs = MAX_TESTRUNS;
5396
5397 for (i = 0; i < MAX_SUBTESTS; i++) {
5398 void *data;
5399 u64 duration;
5400 u32 ret;
5401
5402 /*
5403 * NOTE: Several sub-tests may be present, in which case
5404 * a zero {data_size, result} tuple indicates the end of
5405 * the sub-test array. The first test is always run,
5406 * even if both data_size and result happen to be zero.
5407 */
5408 if (i > 0 &&
5409 test->test[i].data_size == 0 &&
5410 test->test[i].result == 0)
5411 break;
5412
5413 data = generate_test_data(test, i);
5414 if (!data && !(test->aux & FLAG_NO_DATA)) {
5415 pr_cont("data generation failed ");
5416 err_cnt++;
5417 break;
5418 }
5419 ret = __run_one(fp, data, runs, &duration);
5420 release_test_data(test, data);
5421
5422 if (ret == test->test[i].result) {
5423 pr_cont("%lld ", duration);
5424 } else {
5425 pr_cont("ret %d != %d ", ret,
5426 test->test[i].result);
5427 err_cnt++;
5428 }
5429 }
5430
5431 return err_cnt;
5432 }
5433
5434 static char test_name[64];
5435 module_param_string(test_name, test_name, sizeof(test_name), 0);
5436
5437 static int test_id = -1;
5438 module_param(test_id, int, 0);
5439
5440 static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
5441 module_param_array(test_range, int, NULL, 0);
5442
find_test_index(const char * test_name)5443 static __init int find_test_index(const char *test_name)
5444 {
5445 int i;
5446
5447 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5448 if (!strcmp(tests[i].descr, test_name))
5449 return i;
5450 }
5451 return -1;
5452 }
5453
prepare_bpf_tests(void)5454 static __init int prepare_bpf_tests(void)
5455 {
5456 int i;
5457
5458 if (test_id >= 0) {
5459 /*
5460 * if a test_id was specified, use test_range to
5461 * cover only that test.
5462 */
5463 if (test_id >= ARRAY_SIZE(tests)) {
5464 pr_err("test_bpf: invalid test_id specified.\n");
5465 return -EINVAL;
5466 }
5467
5468 test_range[0] = test_id;
5469 test_range[1] = test_id;
5470 } else if (*test_name) {
5471 /*
5472 * if a test_name was specified, find it and setup
5473 * test_range to cover only that test.
5474 */
5475 int idx = find_test_index(test_name);
5476
5477 if (idx < 0) {
5478 pr_err("test_bpf: no test named '%s' found.\n",
5479 test_name);
5480 return -EINVAL;
5481 }
5482 test_range[0] = idx;
5483 test_range[1] = idx;
5484 } else {
5485 /*
5486 * check that the supplied test_range is valid.
5487 */
5488 if (test_range[0] >= ARRAY_SIZE(tests) ||
5489 test_range[1] >= ARRAY_SIZE(tests) ||
5490 test_range[0] < 0 || test_range[1] < 0) {
5491 pr_err("test_bpf: test_range is out of bound.\n");
5492 return -EINVAL;
5493 }
5494
5495 if (test_range[1] < test_range[0]) {
5496 pr_err("test_bpf: test_range is ending before it starts.\n");
5497 return -EINVAL;
5498 }
5499 }
5500
5501 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5502 if (tests[i].fill_helper &&
5503 tests[i].fill_helper(&tests[i]) < 0)
5504 return -ENOMEM;
5505 }
5506
5507 return 0;
5508 }
5509
destroy_bpf_tests(void)5510 static __init void destroy_bpf_tests(void)
5511 {
5512 int i;
5513
5514 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5515 if (tests[i].fill_helper)
5516 kfree(tests[i].u.ptr.insns);
5517 }
5518 }
5519
exclude_test(int test_id)5520 static bool exclude_test(int test_id)
5521 {
5522 return test_id < test_range[0] || test_id > test_range[1];
5523 }
5524
test_bpf(void)5525 static __init int test_bpf(void)
5526 {
5527 int i, err_cnt = 0, pass_cnt = 0;
5528 int jit_cnt = 0, run_cnt = 0;
5529
5530 for (i = 0; i < ARRAY_SIZE(tests); i++) {
5531 struct bpf_prog *fp;
5532 int err;
5533
5534 if (exclude_test(i))
5535 continue;
5536
5537 pr_info("#%d %s ", i, tests[i].descr);
5538
5539 fp = generate_filter(i, &err);
5540 if (fp == NULL) {
5541 if (err == 0) {
5542 pass_cnt++;
5543 continue;
5544 }
5545 err_cnt++;
5546 continue;
5547 }
5548
5549 pr_cont("jited:%u ", fp->jited);
5550
5551 run_cnt++;
5552 if (fp->jited)
5553 jit_cnt++;
5554
5555 err = run_one(fp, &tests[i]);
5556 release_filter(fp, i);
5557
5558 if (err) {
5559 pr_cont("FAIL (%d times)\n", err);
5560 err_cnt++;
5561 } else {
5562 pr_cont("PASS\n");
5563 pass_cnt++;
5564 }
5565 }
5566
5567 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
5568 pass_cnt, err_cnt, jit_cnt, run_cnt);
5569
5570 return err_cnt ? -EINVAL : 0;
5571 }
5572
test_bpf_init(void)5573 static int __init test_bpf_init(void)
5574 {
5575 int ret;
5576
5577 ret = prepare_bpf_tests();
5578 if (ret < 0)
5579 return ret;
5580
5581 ret = test_bpf();
5582
5583 destroy_bpf_tests();
5584 return ret;
5585 }
5586
test_bpf_exit(void)5587 static void __exit test_bpf_exit(void)
5588 {
5589 }
5590
5591 module_init(test_bpf_init);
5592 module_exit(test_bpf_exit);
5593
5594 MODULE_LICENSE("GPL");
5595