2 * Testsuite for BPF interpreter and BPF JIT compiler
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
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.
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.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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>
28 /* General test specific settings */
29 #define MAX_SUBTESTS 3
30 #define MAX_TESTRUNS 10000
33 #define MAX_K 0xffffFFFF
35 /* Few constants used to init test 'skb' */
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
44 /* Redefine REGs to make tests less verbose */
55 #define R10 BPF_REG_10
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)
63 CLASSIC
= BIT(6), /* Old BPF instructions only. */
64 INTERNAL
= BIT(7), /* Extended instruction set. */
67 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
72 struct sock_filter insns
[MAX_INSNS
];
73 struct bpf_insn insns_int
[MAX_INSNS
];
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 int stack_depth
; /* for eBPF only, since tests don't call verifier */
91 /* Large test cases need separate allocation and fill handler. */
93 static int bpf_fill_maxinsns1(struct bpf_test
*self
)
95 unsigned int len
= BPF_MAXINSNS
;
96 struct sock_filter
*insn
;
100 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
104 for (i
= 0; i
< len
; i
++, k
--)
105 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, k
);
107 self
->u
.ptr
.insns
= insn
;
108 self
->u
.ptr
.len
= len
;
113 static int bpf_fill_maxinsns2(struct bpf_test
*self
)
115 unsigned int len
= BPF_MAXINSNS
;
116 struct sock_filter
*insn
;
119 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
123 for (i
= 0; i
< len
; i
++)
124 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
126 self
->u
.ptr
.insns
= insn
;
127 self
->u
.ptr
.len
= len
;
132 static int bpf_fill_maxinsns3(struct bpf_test
*self
)
134 unsigned int len
= BPF_MAXINSNS
;
135 struct sock_filter
*insn
;
136 struct rnd_state rnd
;
139 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
143 prandom_seed_state(&rnd
, 3141592653589793238ULL);
145 for (i
= 0; i
< len
- 1; i
++) {
146 __u32 k
= prandom_u32_state(&rnd
);
148 insn
[i
] = __BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, k
);
151 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
153 self
->u
.ptr
.insns
= insn
;
154 self
->u
.ptr
.len
= len
;
159 static int bpf_fill_maxinsns4(struct bpf_test
*self
)
161 unsigned int len
= BPF_MAXINSNS
+ 1;
162 struct sock_filter
*insn
;
165 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
169 for (i
= 0; i
< len
; i
++)
170 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
172 self
->u
.ptr
.insns
= insn
;
173 self
->u
.ptr
.len
= len
;
178 static int bpf_fill_maxinsns5(struct bpf_test
*self
)
180 unsigned int len
= BPF_MAXINSNS
;
181 struct sock_filter
*insn
;
184 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
188 insn
[0] = __BPF_JUMP(BPF_JMP
| BPF_JA
, len
- 2, 0, 0);
190 for (i
= 1; i
< len
- 1; i
++)
191 insn
[i
] = __BPF_STMT(BPF_RET
| BPF_K
, 0xfefefefe);
193 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xabababab);
195 self
->u
.ptr
.insns
= insn
;
196 self
->u
.ptr
.len
= len
;
201 static int bpf_fill_maxinsns6(struct bpf_test
*self
)
203 unsigned int len
= BPF_MAXINSNS
;
204 struct sock_filter
*insn
;
207 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
211 for (i
= 0; i
< len
- 1; i
++)
212 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
213 SKF_AD_VLAN_TAG_PRESENT
);
215 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
217 self
->u
.ptr
.insns
= insn
;
218 self
->u
.ptr
.len
= len
;
223 static int bpf_fill_maxinsns7(struct bpf_test
*self
)
225 unsigned int len
= BPF_MAXINSNS
;
226 struct sock_filter
*insn
;
229 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
233 for (i
= 0; i
< len
- 4; i
++)
234 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
237 insn
[len
- 4] = __BPF_STMT(BPF_MISC
| BPF_TAX
, 0);
238 insn
[len
- 3] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, SKF_AD_OFF
+
240 insn
[len
- 2] = __BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0);
241 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
243 self
->u
.ptr
.insns
= insn
;
244 self
->u
.ptr
.len
= len
;
249 static int bpf_fill_maxinsns8(struct bpf_test
*self
)
251 unsigned int len
= BPF_MAXINSNS
;
252 struct sock_filter
*insn
;
253 int i
, jmp_off
= len
- 3;
255 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
259 insn
[0] = __BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff);
261 for (i
= 1; i
< len
- 1; i
++)
262 insn
[i
] = __BPF_JUMP(BPF_JMP
| BPF_JGT
, 0xffffffff, jmp_off
--, 0);
264 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_A
, 0);
266 self
->u
.ptr
.insns
= insn
;
267 self
->u
.ptr
.len
= len
;
272 static int bpf_fill_maxinsns9(struct bpf_test
*self
)
274 unsigned int len
= BPF_MAXINSNS
;
275 struct bpf_insn
*insn
;
278 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
282 insn
[0] = BPF_JMP_IMM(BPF_JA
, 0, 0, len
- 2);
283 insn
[1] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xcbababab);
284 insn
[2] = BPF_EXIT_INSN();
286 for (i
= 3; i
< len
- 2; i
++)
287 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xfefefefe);
289 insn
[len
- 2] = BPF_EXIT_INSN();
290 insn
[len
- 1] = BPF_JMP_IMM(BPF_JA
, 0, 0, -(len
- 1));
292 self
->u
.ptr
.insns
= insn
;
293 self
->u
.ptr
.len
= len
;
298 static int bpf_fill_maxinsns10(struct bpf_test
*self
)
300 unsigned int len
= BPF_MAXINSNS
, hlen
= len
- 2;
301 struct bpf_insn
*insn
;
304 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
308 for (i
= 0; i
< hlen
/ 2; i
++)
309 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 2 - 2 * i
);
310 for (i
= hlen
- 1; i
> hlen
/ 2; i
--)
311 insn
[i
] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
- 1 - 2 * i
);
313 insn
[hlen
/ 2] = BPF_JMP_IMM(BPF_JA
, 0, 0, hlen
/ 2 - 1);
314 insn
[hlen
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xabababac);
315 insn
[hlen
+ 1] = BPF_EXIT_INSN();
317 self
->u
.ptr
.insns
= insn
;
318 self
->u
.ptr
.len
= len
;
323 static int __bpf_fill_ja(struct bpf_test
*self
, unsigned int len
,
326 struct sock_filter
*insn
;
330 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
334 rlen
= (len
% plen
) - 1;
336 for (i
= 0; i
+ plen
< len
; i
+= plen
)
337 for (j
= 0; j
< plen
; j
++)
338 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
,
340 for (j
= 0; j
< rlen
; j
++)
341 insn
[i
+ j
] = __BPF_JUMP(BPF_JMP
| BPF_JA
, rlen
- 1 - j
,
344 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xababcbac);
346 self
->u
.ptr
.insns
= insn
;
347 self
->u
.ptr
.len
= len
;
352 static int bpf_fill_maxinsns11(struct bpf_test
*self
)
354 /* Hits 70 passes on x86_64, so cannot get JITed there. */
355 return __bpf_fill_ja(self
, BPF_MAXINSNS
, 68);
358 static int bpf_fill_ja(struct bpf_test
*self
)
360 /* Hits exactly 11 passes on x86_64 JIT. */
361 return __bpf_fill_ja(self
, 12, 9);
364 static int bpf_fill_ld_abs_get_processor_id(struct bpf_test
*self
)
366 unsigned int len
= BPF_MAXINSNS
;
367 struct sock_filter
*insn
;
370 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
374 for (i
= 0; i
< len
- 1; i
+= 2) {
375 insn
[i
] = __BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 0);
376 insn
[i
+ 1] = __BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
377 SKF_AD_OFF
+ SKF_AD_CPU
);
380 insn
[len
- 1] = __BPF_STMT(BPF_RET
| BPF_K
, 0xbee);
382 self
->u
.ptr
.insns
= insn
;
383 self
->u
.ptr
.len
= len
;
389 /* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
390 static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test
*self
)
392 unsigned int len
= BPF_MAXINSNS
;
393 struct bpf_insn
*insn
;
396 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
400 insn
[i
++] = BPF_MOV64_REG(R6
, R1
);
402 for (j
= 0; j
< PUSH_CNT
; j
++) {
403 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
404 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0x34, len
- i
- 2);
406 insn
[i
++] = BPF_MOV64_REG(R1
, R6
);
407 insn
[i
++] = BPF_MOV64_IMM(R2
, 1);
408 insn
[i
++] = BPF_MOV64_IMM(R3
, 2);
409 insn
[i
++] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
410 bpf_skb_vlan_push_proto
.func
- __bpf_call_base
);
411 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0, len
- i
- 2);
415 for (j
= 0; j
< PUSH_CNT
; j
++) {
416 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
417 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0x34, len
- i
- 2);
419 insn
[i
++] = BPF_MOV64_REG(R1
, R6
);
420 insn
[i
++] = BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 0, 0,
421 bpf_skb_vlan_pop_proto
.func
- __bpf_call_base
);
422 insn
[i
] = BPF_JMP_IMM(BPF_JNE
, R0
, 0, len
- i
- 2);
428 for (; i
< len
- 1; i
++)
429 insn
[i
] = BPF_ALU32_IMM(BPF_MOV
, R0
, 0xbef);
431 insn
[len
- 1] = BPF_EXIT_INSN();
433 self
->u
.ptr
.insns
= insn
;
434 self
->u
.ptr
.len
= len
;
439 static int bpf_fill_jump_around_ld_abs(struct bpf_test
*self
)
441 unsigned int len
= BPF_MAXINSNS
;
442 struct bpf_insn
*insn
;
445 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
449 insn
[i
++] = BPF_MOV64_REG(R6
, R1
);
450 insn
[i
++] = BPF_LD_ABS(BPF_B
, 0);
451 insn
[i
] = BPF_JMP_IMM(BPF_JEQ
, R0
, 10, len
- i
- 2);
454 insn
[i
++] = BPF_LD_ABS(BPF_B
, 1);
455 insn
[i
] = BPF_EXIT_INSN();
457 self
->u
.ptr
.insns
= insn
;
458 self
->u
.ptr
.len
= len
;
463 static int __bpf_fill_stxdw(struct bpf_test
*self
, int size
)
465 unsigned int len
= BPF_MAXINSNS
;
466 struct bpf_insn
*insn
;
469 insn
= kmalloc_array(len
, sizeof(*insn
), GFP_KERNEL
);
473 insn
[0] = BPF_ALU32_IMM(BPF_MOV
, R0
, 1);
474 insn
[1] = BPF_ST_MEM(size
, R10
, -40, 42);
476 for (i
= 2; i
< len
- 2; i
++)
477 insn
[i
] = BPF_STX_XADD(size
, R10
, R0
, -40);
479 insn
[len
- 2] = BPF_LDX_MEM(size
, R0
, R10
, -40);
480 insn
[len
- 1] = BPF_EXIT_INSN();
482 self
->u
.ptr
.insns
= insn
;
483 self
->u
.ptr
.len
= len
;
484 self
->stack_depth
= 40;
489 static int bpf_fill_stxw(struct bpf_test
*self
)
491 return __bpf_fill_stxdw(self
, BPF_W
);
494 static int bpf_fill_stxdw(struct bpf_test
*self
)
496 return __bpf_fill_stxdw(self
, BPF_DW
);
499 static struct bpf_test tests
[] = {
503 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
504 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
505 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
506 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
507 BPF_STMT(BPF_ALU
| BPF_NEG
, 0), /* A == -3 */
508 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
509 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
510 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
511 BPF_STMT(BPF_MISC
| BPF_TAX
, 0), /* X == len - 3 */
512 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
513 BPF_STMT(BPF_RET
| BPF_A
, 0)
516 { 10, 20, 30, 40, 50 },
517 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
522 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
523 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
524 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
525 BPF_STMT(BPF_RET
| BPF_A
, 0) /* A == len * 2 */
528 { 10, 20, 30, 40, 50 },
529 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
534 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
535 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 2),
536 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
537 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
538 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0xffffffff),
539 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 3),
540 BPF_STMT(BPF_RET
| BPF_A
, 0)
542 CLASSIC
| FLAG_NO_DATA
,
544 { { 0, 0xfffffffd } }
549 BPF_STMT(BPF_LD
| BPF_IMM
, 8),
550 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 2),
551 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
552 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
553 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
554 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
555 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
556 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x70000000),
557 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
558 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
559 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
560 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
561 BPF_STMT(BPF_LD
| BPF_IMM
, 0xffffffff),
562 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x70000000),
563 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
564 BPF_STMT(BPF_RET
| BPF_A
, 0)
566 CLASSIC
| FLAG_NO_DATA
,
568 { { 0, 0x20000000 } }
573 BPF_STMT(BPF_LD
| BPF_IMM
, 0xff),
574 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
575 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 27),
576 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
577 BPF_STMT(BPF_LD
| BPF_IMM
, 0xf),
578 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_K
, 0xf0),
579 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
580 BPF_STMT(BPF_RET
| BPF_A
, 0)
582 CLASSIC
| FLAG_NO_DATA
,
584 { { 0, 0x800000ff }, { 1, 0x800000ff } },
589 BPF_STMT(BPF_LD
| BPF_IMM
, 0), /* ld #0 */
590 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, 1, 0),
591 BPF_STMT(BPF_RET
| BPF_K
, 0),
592 BPF_STMT(BPF_RET
| BPF_K
, 1),
601 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
602 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, MAX_K
),
603 BPF_STMT(BPF_RET
| BPF_K
, 1)
607 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
612 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
, 1000),
613 BPF_STMT(BPF_RET
| BPF_K
, 1)
617 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
622 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
),
623 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
624 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_LL_OFF
+ 1),
625 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
626 BPF_STMT(BPF_RET
| BPF_A
, 0)
630 { { 1, 0 }, { 2, 3 } },
635 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_LL_OFF
- 1),
636 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
637 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
638 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
639 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
640 BPF_STMT(BPF_RET
| BPF_A
, 0)
644 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
649 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
),
650 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
651 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, SKF_NET_OFF
+ 1),
652 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
653 BPF_STMT(BPF_RET
| BPF_A
, 0)
656 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
657 { { 15, 0 }, { 16, 3 } },
662 BPF_STMT(BPF_LD
| BPF_IMM
, SKF_NET_OFF
- 15),
663 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
664 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
665 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
666 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
667 BPF_STMT(BPF_RET
| BPF_A
, 0)
670 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
671 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
676 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
677 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
678 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
679 BPF_STMT(BPF_RET
| BPF_K
, 1),
680 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
681 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
682 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
683 BPF_STMT(BPF_RET
| BPF_K
, 1),
684 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
685 SKF_AD_OFF
+ SKF_AD_PKTTYPE
),
686 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, SKB_TYPE
, 1, 0),
687 BPF_STMT(BPF_RET
| BPF_K
, 1),
688 BPF_STMT(BPF_RET
| BPF_A
, 0)
692 { { 1, 3 }, { 10, 3 } },
697 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
698 SKF_AD_OFF
+ SKF_AD_MARK
),
699 BPF_STMT(BPF_RET
| BPF_A
, 0)
703 { { 1, SKB_MARK
}, { 10, SKB_MARK
} },
708 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
709 SKF_AD_OFF
+ SKF_AD_RXHASH
),
710 BPF_STMT(BPF_RET
| BPF_A
, 0)
714 { { 1, SKB_HASH
}, { 10, SKB_HASH
} },
719 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
720 SKF_AD_OFF
+ SKF_AD_QUEUE
),
721 BPF_STMT(BPF_RET
| BPF_A
, 0)
725 { { 1, SKB_QUEUE_MAP
}, { 10, SKB_QUEUE_MAP
} },
730 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 1),
731 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 20, 1, 0),
732 BPF_STMT(BPF_RET
| BPF_K
, 0),
733 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
734 SKF_AD_OFF
+ SKF_AD_PROTOCOL
),
735 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
736 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
737 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 30, 1, 0),
738 BPF_STMT(BPF_RET
| BPF_K
, 0),
739 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
740 BPF_STMT(BPF_RET
| BPF_A
, 0)
744 { { 10, ETH_P_IP
}, { 100, ETH_P_IP
} },
749 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
750 SKF_AD_OFF
+ SKF_AD_VLAN_TAG
),
751 BPF_STMT(BPF_RET
| BPF_A
, 0)
756 { 1, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
},
757 { 10, SKB_VLAN_TCI
& ~VLAN_TAG_PRESENT
}
761 "LD_VLAN_TAG_PRESENT",
763 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
764 SKF_AD_OFF
+ SKF_AD_VLAN_TAG_PRESENT
),
765 BPF_STMT(BPF_RET
| BPF_A
, 0)
770 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
771 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
777 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
778 SKF_AD_OFF
+ SKF_AD_IFINDEX
),
779 BPF_STMT(BPF_RET
| BPF_A
, 0)
783 { { 1, SKB_DEV_IFINDEX
}, { 10, SKB_DEV_IFINDEX
} },
788 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
789 SKF_AD_OFF
+ SKF_AD_HATYPE
),
790 BPF_STMT(BPF_RET
| BPF_A
, 0)
794 { { 1, SKB_DEV_TYPE
}, { 10, SKB_DEV_TYPE
} },
799 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
800 SKF_AD_OFF
+ SKF_AD_CPU
),
801 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
802 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
803 SKF_AD_OFF
+ SKF_AD_CPU
),
804 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
805 BPF_STMT(BPF_RET
| BPF_A
, 0)
809 { { 1, 0 }, { 10, 0 } },
814 BPF_STMT(BPF_LDX
| BPF_IMM
, 2),
815 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
816 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
817 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
818 SKF_AD_OFF
+ SKF_AD_NLATTR
),
819 BPF_STMT(BPF_RET
| BPF_A
, 0)
823 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
825 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
827 { { 4, 0 }, { 20, 6 } },
832 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
833 BPF_STMT(BPF_LDX
| BPF_IMM
, 3),
834 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
835 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
836 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
837 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
838 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
839 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
840 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
841 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
842 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
843 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
844 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
845 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
846 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
847 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
848 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
849 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
850 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
851 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
852 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
853 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
854 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
855 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
856 SKF_AD_OFF
+ SKF_AD_NLATTR_NEST
),
857 BPF_STMT(BPF_RET
| BPF_A
, 0)
861 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
863 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
865 { { 4, 0 }, { 20, 10 } },
870 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
871 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
872 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
873 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
874 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
875 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
876 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
877 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
878 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
879 SKF_AD_OFF
+ SKF_AD_PAY_OFFSET
),
880 BPF_STMT(BPF_RET
| BPF_A
, 0)
883 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
884 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
885 * id 9737, seq 1, length 64
887 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
890 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
891 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
892 { { 30, 0 }, { 100, 42 } },
897 BPF_STMT(BPF_LD
| BPF_IMM
, 10),
898 BPF_STMT(BPF_LDX
| BPF_IMM
, 300),
899 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
900 SKF_AD_OFF
+ SKF_AD_ALU_XOR_X
),
901 BPF_STMT(BPF_RET
| BPF_A
, 0)
905 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
910 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
911 BPF_STMT(BPF_LD
| BPF_IMM
, 2),
912 BPF_STMT(BPF_ALU
| BPF_RSH
, 1),
913 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
914 BPF_STMT(BPF_ST
, 1), /* M1 = 1 ^ len */
915 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_K
, 0x80000000),
916 BPF_STMT(BPF_ST
, 2), /* M2 = 1 ^ len ^ 0x80000000 */
917 BPF_STMT(BPF_STX
, 15), /* M3 = len */
918 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
919 BPF_STMT(BPF_LD
| BPF_MEM
, 2),
920 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
921 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
922 BPF_STMT(BPF_ALU
| BPF_XOR
| BPF_X
, 0),
923 BPF_STMT(BPF_RET
| BPF_A
, 0)
927 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
932 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
933 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
934 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 0, 1),
935 BPF_STMT(BPF_RET
| BPF_K
, 1),
936 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
940 { { 1, 0 }, { 3, 1 }, { 4, MAX_K
} },
945 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
946 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
947 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_X
, 0, 0, 1),
948 BPF_STMT(BPF_RET
| BPF_K
, 1),
949 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
953 { { 2, 0 }, { 3, 1 }, { 4, MAX_K
} },
956 "JGE (jt 0), test 1",
958 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
959 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
960 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
961 BPF_STMT(BPF_RET
| BPF_K
, 1),
962 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
966 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
969 "JGE (jt 0), test 2",
971 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
972 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
973 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_X
, 0, 0, 1),
974 BPF_STMT(BPF_RET
| BPF_K
, 1),
975 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
979 { { 4, 1 }, { 5, 1 }, { 6, MAX_K
} },
984 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
985 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, MAX_K
),
986 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 1, 1, 0),
987 BPF_STMT(BPF_RET
| BPF_K
, 10),
988 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 2, 1, 0),
989 BPF_STMT(BPF_RET
| BPF_K
, 20),
990 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 3, 1, 0),
991 BPF_STMT(BPF_RET
| BPF_K
, 30),
992 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 4, 1, 0),
993 BPF_STMT(BPF_RET
| BPF_K
, 40),
994 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
998 { { 1, 20 }, { 3, 40 }, { 5, MAX_K
} },
1003 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1004 BPF_JUMP(BPF_JMP
| BPF_JA
, 1, 1, 1),
1005 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1006 BPF_JUMP(BPF_JMP
| BPF_JA
, 0, 0, 0),
1007 BPF_STMT(BPF_LDX
| BPF_LEN
, 0),
1008 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1009 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, 4),
1010 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
1011 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
1012 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 1, 0, 1),
1013 BPF_STMT(BPF_RET
| BPF_K
, 10),
1014 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x80000000, 0, 1),
1015 BPF_STMT(BPF_RET
| BPF_K
, 20),
1016 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1017 BPF_STMT(BPF_RET
| BPF_K
, 30),
1018 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1019 BPF_STMT(BPF_RET
| BPF_K
, 30),
1020 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1021 BPF_STMT(BPF_RET
| BPF_K
, 30),
1022 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1023 BPF_STMT(BPF_RET
| BPF_K
, 30),
1024 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0xffffff, 1, 0),
1025 BPF_STMT(BPF_RET
| BPF_K
, 30),
1026 BPF_STMT(BPF_RET
| BPF_K
, MAX_K
)
1029 { 0, 0xAA, 0x55, 1 },
1030 { { 4, 10 }, { 5, 20 }, { 6, MAX_K
} },
1035 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1036 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 0, 8), /* IPv6 */
1037 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 20),
1038 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1039 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1040 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 17),
1041 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 54),
1042 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 14, 0),
1043 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 56),
1044 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 12, 13),
1045 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0800, 0, 12), /* IPv4 */
1046 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1047 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x84, 2, 0),
1048 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 1, 0),
1049 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x11, 0, 8),
1050 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1051 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 6, 0),
1052 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1053 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1054 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1055 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1056 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 1),
1057 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1058 BPF_STMT(BPF_RET
| BPF_K
, 0),
1061 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1062 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1063 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1064 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1066 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1067 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1069 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1070 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1071 0x0a, 0x01, 0x01, 0x95, /* ip src */
1072 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1074 0x00, 0x16 /* dst port */ },
1075 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1080 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1081 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1082 * (len > 115 or len < 30000000000)' -d
1084 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 12),
1085 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x86dd, 30, 0),
1086 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x800, 0, 29),
1087 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 23),
1088 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x6, 0, 27),
1089 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 20),
1090 BPF_JUMP(BPF_JMP
| BPF_JSET
| BPF_K
, 0x1fff, 25, 0),
1091 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1092 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 14),
1093 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 2, 0),
1094 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 16),
1095 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 22, 0, 20),
1096 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 16),
1097 BPF_STMT(BPF_ST
, 1),
1098 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 14),
1099 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf),
1100 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 2),
1101 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x5), /* libpcap emits K on TAX */
1102 BPF_STMT(BPF_LD
| BPF_MEM
, 1),
1103 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
1104 BPF_STMT(BPF_ST
, 5),
1105 BPF_STMT(BPF_LDX
| BPF_B
| BPF_MSH
, 14),
1106 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 26),
1107 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xf0),
1108 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 2),
1109 BPF_STMT(BPF_MISC
| BPF_TAX
, 0x9), /* libpcap emits K on TAX */
1110 BPF_STMT(BPF_LD
| BPF_MEM
, 5),
1111 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, 4, 0),
1112 BPF_STMT(BPF_LD
| BPF_LEN
, 0),
1113 BPF_JUMP(BPF_JMP
| BPF_JGT
| BPF_K
, 0x73, 1, 0),
1114 BPF_JUMP(BPF_JMP
| BPF_JGE
| BPF_K
, 0xfc23ac00, 1, 0),
1115 BPF_STMT(BPF_RET
| BPF_K
, 0xffff),
1116 BPF_STMT(BPF_RET
| BPF_K
, 0),
1119 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1120 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1122 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1123 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1124 0x0a, 0x01, 0x01, 0x95, /* ip src */
1125 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1127 0x00, 0x16 /* dst port */ },
1128 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1133 /* check that unitialized X and A contain zeros */
1134 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
1135 BPF_STMT(BPF_RET
| BPF_A
, 0)
1144 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1145 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
1146 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1147 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1148 BPF_ALU64_IMM(BPF_ADD
, R1
, -1),
1149 BPF_ALU64_IMM(BPF_MUL
, R1
, 3),
1150 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
1155 { { 0, 0xfffffffd } }
1160 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1161 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1162 BPF_ALU64_IMM(BPF_MOV
, R2
, 3),
1163 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1164 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xfffffffd, 1),
1166 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1176 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1177 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
1178 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1179 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1180 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1181 BPF_JMP_IMM(BPF_JEQ
, R1
, 0x2ffffff, 1),
1183 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1193 BPF_ALU32_IMM(BPF_MOV
, R0
, -1),
1194 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1195 BPF_ALU32_IMM(BPF_MOV
, R2
, 3),
1196 BPF_ALU32_REG(BPF_MUL
, R1
, R2
),
1197 BPF_ALU64_IMM(BPF_RSH
, R1
, 8),
1198 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xffffff, 1),
1200 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
1208 /* Have to test all register combinations, since
1209 * JITing of different registers will produce
1210 * different asm code.
1214 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1215 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1216 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1217 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1218 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1219 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1220 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1221 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1222 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1223 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1224 BPF_ALU64_IMM(BPF_ADD
, R0
, 20),
1225 BPF_ALU64_IMM(BPF_ADD
, R1
, 20),
1226 BPF_ALU64_IMM(BPF_ADD
, R2
, 20),
1227 BPF_ALU64_IMM(BPF_ADD
, R3
, 20),
1228 BPF_ALU64_IMM(BPF_ADD
, R4
, 20),
1229 BPF_ALU64_IMM(BPF_ADD
, R5
, 20),
1230 BPF_ALU64_IMM(BPF_ADD
, R6
, 20),
1231 BPF_ALU64_IMM(BPF_ADD
, R7
, 20),
1232 BPF_ALU64_IMM(BPF_ADD
, R8
, 20),
1233 BPF_ALU64_IMM(BPF_ADD
, R9
, 20),
1234 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1235 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1236 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1237 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1238 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1239 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1240 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1241 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1242 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1243 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1244 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1245 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1246 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1247 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1248 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1249 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1250 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1251 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1252 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1253 BPF_ALU64_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1254 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1256 BPF_ALU64_REG(BPF_ADD
, R1
, R0
),
1257 BPF_ALU64_REG(BPF_ADD
, R1
, R1
),
1258 BPF_ALU64_REG(BPF_ADD
, R1
, R2
),
1259 BPF_ALU64_REG(BPF_ADD
, R1
, R3
),
1260 BPF_ALU64_REG(BPF_ADD
, R1
, R4
),
1261 BPF_ALU64_REG(BPF_ADD
, R1
, R5
),
1262 BPF_ALU64_REG(BPF_ADD
, R1
, R6
),
1263 BPF_ALU64_REG(BPF_ADD
, R1
, R7
),
1264 BPF_ALU64_REG(BPF_ADD
, R1
, R8
),
1265 BPF_ALU64_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1266 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1268 BPF_ALU64_REG(BPF_ADD
, R2
, R0
),
1269 BPF_ALU64_REG(BPF_ADD
, R2
, R1
),
1270 BPF_ALU64_REG(BPF_ADD
, R2
, R2
),
1271 BPF_ALU64_REG(BPF_ADD
, R2
, R3
),
1272 BPF_ALU64_REG(BPF_ADD
, R2
, R4
),
1273 BPF_ALU64_REG(BPF_ADD
, R2
, R5
),
1274 BPF_ALU64_REG(BPF_ADD
, R2
, R6
),
1275 BPF_ALU64_REG(BPF_ADD
, R2
, R7
),
1276 BPF_ALU64_REG(BPF_ADD
, R2
, R8
),
1277 BPF_ALU64_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1278 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1280 BPF_ALU64_REG(BPF_ADD
, R3
, R0
),
1281 BPF_ALU64_REG(BPF_ADD
, R3
, R1
),
1282 BPF_ALU64_REG(BPF_ADD
, R3
, R2
),
1283 BPF_ALU64_REG(BPF_ADD
, R3
, R3
),
1284 BPF_ALU64_REG(BPF_ADD
, R3
, R4
),
1285 BPF_ALU64_REG(BPF_ADD
, R3
, R5
),
1286 BPF_ALU64_REG(BPF_ADD
, R3
, R6
),
1287 BPF_ALU64_REG(BPF_ADD
, R3
, R7
),
1288 BPF_ALU64_REG(BPF_ADD
, R3
, R8
),
1289 BPF_ALU64_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1290 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1292 BPF_ALU64_REG(BPF_ADD
, R4
, R0
),
1293 BPF_ALU64_REG(BPF_ADD
, R4
, R1
),
1294 BPF_ALU64_REG(BPF_ADD
, R4
, R2
),
1295 BPF_ALU64_REG(BPF_ADD
, R4
, R3
),
1296 BPF_ALU64_REG(BPF_ADD
, R4
, R4
),
1297 BPF_ALU64_REG(BPF_ADD
, R4
, R5
),
1298 BPF_ALU64_REG(BPF_ADD
, R4
, R6
),
1299 BPF_ALU64_REG(BPF_ADD
, R4
, R7
),
1300 BPF_ALU64_REG(BPF_ADD
, R4
, R8
),
1301 BPF_ALU64_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1302 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1304 BPF_ALU64_REG(BPF_ADD
, R5
, R0
),
1305 BPF_ALU64_REG(BPF_ADD
, R5
, R1
),
1306 BPF_ALU64_REG(BPF_ADD
, R5
, R2
),
1307 BPF_ALU64_REG(BPF_ADD
, R5
, R3
),
1308 BPF_ALU64_REG(BPF_ADD
, R5
, R4
),
1309 BPF_ALU64_REG(BPF_ADD
, R5
, R5
),
1310 BPF_ALU64_REG(BPF_ADD
, R5
, R6
),
1311 BPF_ALU64_REG(BPF_ADD
, R5
, R7
),
1312 BPF_ALU64_REG(BPF_ADD
, R5
, R8
),
1313 BPF_ALU64_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1314 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1316 BPF_ALU64_REG(BPF_ADD
, R6
, R0
),
1317 BPF_ALU64_REG(BPF_ADD
, R6
, R1
),
1318 BPF_ALU64_REG(BPF_ADD
, R6
, R2
),
1319 BPF_ALU64_REG(BPF_ADD
, R6
, R3
),
1320 BPF_ALU64_REG(BPF_ADD
, R6
, R4
),
1321 BPF_ALU64_REG(BPF_ADD
, R6
, R5
),
1322 BPF_ALU64_REG(BPF_ADD
, R6
, R6
),
1323 BPF_ALU64_REG(BPF_ADD
, R6
, R7
),
1324 BPF_ALU64_REG(BPF_ADD
, R6
, R8
),
1325 BPF_ALU64_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1326 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1328 BPF_ALU64_REG(BPF_ADD
, R7
, R0
),
1329 BPF_ALU64_REG(BPF_ADD
, R7
, R1
),
1330 BPF_ALU64_REG(BPF_ADD
, R7
, R2
),
1331 BPF_ALU64_REG(BPF_ADD
, R7
, R3
),
1332 BPF_ALU64_REG(BPF_ADD
, R7
, R4
),
1333 BPF_ALU64_REG(BPF_ADD
, R7
, R5
),
1334 BPF_ALU64_REG(BPF_ADD
, R7
, R6
),
1335 BPF_ALU64_REG(BPF_ADD
, R7
, R7
),
1336 BPF_ALU64_REG(BPF_ADD
, R7
, R8
),
1337 BPF_ALU64_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1338 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1340 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
1341 BPF_ALU64_REG(BPF_ADD
, R8
, R1
),
1342 BPF_ALU64_REG(BPF_ADD
, R8
, R2
),
1343 BPF_ALU64_REG(BPF_ADD
, R8
, R3
),
1344 BPF_ALU64_REG(BPF_ADD
, R8
, R4
),
1345 BPF_ALU64_REG(BPF_ADD
, R8
, R5
),
1346 BPF_ALU64_REG(BPF_ADD
, R8
, R6
),
1347 BPF_ALU64_REG(BPF_ADD
, R8
, R7
),
1348 BPF_ALU64_REG(BPF_ADD
, R8
, R8
),
1349 BPF_ALU64_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1350 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1352 BPF_ALU64_REG(BPF_ADD
, R9
, R0
),
1353 BPF_ALU64_REG(BPF_ADD
, R9
, R1
),
1354 BPF_ALU64_REG(BPF_ADD
, R9
, R2
),
1355 BPF_ALU64_REG(BPF_ADD
, R9
, R3
),
1356 BPF_ALU64_REG(BPF_ADD
, R9
, R4
),
1357 BPF_ALU64_REG(BPF_ADD
, R9
, R5
),
1358 BPF_ALU64_REG(BPF_ADD
, R9
, R6
),
1359 BPF_ALU64_REG(BPF_ADD
, R9
, R7
),
1360 BPF_ALU64_REG(BPF_ADD
, R9
, R8
),
1361 BPF_ALU64_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1362 BPF_ALU64_REG(BPF_MOV
, R0
, R9
),
1372 BPF_ALU32_IMM(BPF_MOV
, R0
, 20),
1373 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
1374 BPF_ALU32_IMM(BPF_MOV
, R2
, 2),
1375 BPF_ALU32_IMM(BPF_MOV
, R3
, 3),
1376 BPF_ALU32_IMM(BPF_MOV
, R4
, 4),
1377 BPF_ALU32_IMM(BPF_MOV
, R5
, 5),
1378 BPF_ALU32_IMM(BPF_MOV
, R6
, 6),
1379 BPF_ALU32_IMM(BPF_MOV
, R7
, 7),
1380 BPF_ALU32_IMM(BPF_MOV
, R8
, 8),
1381 BPF_ALU32_IMM(BPF_MOV
, R9
, 9),
1382 BPF_ALU64_IMM(BPF_ADD
, R1
, 10),
1383 BPF_ALU64_IMM(BPF_ADD
, R2
, 10),
1384 BPF_ALU64_IMM(BPF_ADD
, R3
, 10),
1385 BPF_ALU64_IMM(BPF_ADD
, R4
, 10),
1386 BPF_ALU64_IMM(BPF_ADD
, R5
, 10),
1387 BPF_ALU64_IMM(BPF_ADD
, R6
, 10),
1388 BPF_ALU64_IMM(BPF_ADD
, R7
, 10),
1389 BPF_ALU64_IMM(BPF_ADD
, R8
, 10),
1390 BPF_ALU64_IMM(BPF_ADD
, R9
, 10),
1391 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
1392 BPF_ALU32_REG(BPF_ADD
, R0
, R2
),
1393 BPF_ALU32_REG(BPF_ADD
, R0
, R3
),
1394 BPF_ALU32_REG(BPF_ADD
, R0
, R4
),
1395 BPF_ALU32_REG(BPF_ADD
, R0
, R5
),
1396 BPF_ALU32_REG(BPF_ADD
, R0
, R6
),
1397 BPF_ALU32_REG(BPF_ADD
, R0
, R7
),
1398 BPF_ALU32_REG(BPF_ADD
, R0
, R8
),
1399 BPF_ALU32_REG(BPF_ADD
, R0
, R9
), /* R0 == 155 */
1400 BPF_JMP_IMM(BPF_JEQ
, R0
, 155, 1),
1402 BPF_ALU32_REG(BPF_ADD
, R1
, R0
),
1403 BPF_ALU32_REG(BPF_ADD
, R1
, R1
),
1404 BPF_ALU32_REG(BPF_ADD
, R1
, R2
),
1405 BPF_ALU32_REG(BPF_ADD
, R1
, R3
),
1406 BPF_ALU32_REG(BPF_ADD
, R1
, R4
),
1407 BPF_ALU32_REG(BPF_ADD
, R1
, R5
),
1408 BPF_ALU32_REG(BPF_ADD
, R1
, R6
),
1409 BPF_ALU32_REG(BPF_ADD
, R1
, R7
),
1410 BPF_ALU32_REG(BPF_ADD
, R1
, R8
),
1411 BPF_ALU32_REG(BPF_ADD
, R1
, R9
), /* R1 == 456 */
1412 BPF_JMP_IMM(BPF_JEQ
, R1
, 456, 1),
1414 BPF_ALU32_REG(BPF_ADD
, R2
, R0
),
1415 BPF_ALU32_REG(BPF_ADD
, R2
, R1
),
1416 BPF_ALU32_REG(BPF_ADD
, R2
, R2
),
1417 BPF_ALU32_REG(BPF_ADD
, R2
, R3
),
1418 BPF_ALU32_REG(BPF_ADD
, R2
, R4
),
1419 BPF_ALU32_REG(BPF_ADD
, R2
, R5
),
1420 BPF_ALU32_REG(BPF_ADD
, R2
, R6
),
1421 BPF_ALU32_REG(BPF_ADD
, R2
, R7
),
1422 BPF_ALU32_REG(BPF_ADD
, R2
, R8
),
1423 BPF_ALU32_REG(BPF_ADD
, R2
, R9
), /* R2 == 1358 */
1424 BPF_JMP_IMM(BPF_JEQ
, R2
, 1358, 1),
1426 BPF_ALU32_REG(BPF_ADD
, R3
, R0
),
1427 BPF_ALU32_REG(BPF_ADD
, R3
, R1
),
1428 BPF_ALU32_REG(BPF_ADD
, R3
, R2
),
1429 BPF_ALU32_REG(BPF_ADD
, R3
, R3
),
1430 BPF_ALU32_REG(BPF_ADD
, R3
, R4
),
1431 BPF_ALU32_REG(BPF_ADD
, R3
, R5
),
1432 BPF_ALU32_REG(BPF_ADD
, R3
, R6
),
1433 BPF_ALU32_REG(BPF_ADD
, R3
, R7
),
1434 BPF_ALU32_REG(BPF_ADD
, R3
, R8
),
1435 BPF_ALU32_REG(BPF_ADD
, R3
, R9
), /* R3 == 4063 */
1436 BPF_JMP_IMM(BPF_JEQ
, R3
, 4063, 1),
1438 BPF_ALU32_REG(BPF_ADD
, R4
, R0
),
1439 BPF_ALU32_REG(BPF_ADD
, R4
, R1
),
1440 BPF_ALU32_REG(BPF_ADD
, R4
, R2
),
1441 BPF_ALU32_REG(BPF_ADD
, R4
, R3
),
1442 BPF_ALU32_REG(BPF_ADD
, R4
, R4
),
1443 BPF_ALU32_REG(BPF_ADD
, R4
, R5
),
1444 BPF_ALU32_REG(BPF_ADD
, R4
, R6
),
1445 BPF_ALU32_REG(BPF_ADD
, R4
, R7
),
1446 BPF_ALU32_REG(BPF_ADD
, R4
, R8
),
1447 BPF_ALU32_REG(BPF_ADD
, R4
, R9
), /* R4 == 12177 */
1448 BPF_JMP_IMM(BPF_JEQ
, R4
, 12177, 1),
1450 BPF_ALU32_REG(BPF_ADD
, R5
, R0
),
1451 BPF_ALU32_REG(BPF_ADD
, R5
, R1
),
1452 BPF_ALU32_REG(BPF_ADD
, R5
, R2
),
1453 BPF_ALU32_REG(BPF_ADD
, R5
, R3
),
1454 BPF_ALU32_REG(BPF_ADD
, R5
, R4
),
1455 BPF_ALU32_REG(BPF_ADD
, R5
, R5
),
1456 BPF_ALU32_REG(BPF_ADD
, R5
, R6
),
1457 BPF_ALU32_REG(BPF_ADD
, R5
, R7
),
1458 BPF_ALU32_REG(BPF_ADD
, R5
, R8
),
1459 BPF_ALU32_REG(BPF_ADD
, R5
, R9
), /* R5 == 36518 */
1460 BPF_JMP_IMM(BPF_JEQ
, R5
, 36518, 1),
1462 BPF_ALU32_REG(BPF_ADD
, R6
, R0
),
1463 BPF_ALU32_REG(BPF_ADD
, R6
, R1
),
1464 BPF_ALU32_REG(BPF_ADD
, R6
, R2
),
1465 BPF_ALU32_REG(BPF_ADD
, R6
, R3
),
1466 BPF_ALU32_REG(BPF_ADD
, R6
, R4
),
1467 BPF_ALU32_REG(BPF_ADD
, R6
, R5
),
1468 BPF_ALU32_REG(BPF_ADD
, R6
, R6
),
1469 BPF_ALU32_REG(BPF_ADD
, R6
, R7
),
1470 BPF_ALU32_REG(BPF_ADD
, R6
, R8
),
1471 BPF_ALU32_REG(BPF_ADD
, R6
, R9
), /* R6 == 109540 */
1472 BPF_JMP_IMM(BPF_JEQ
, R6
, 109540, 1),
1474 BPF_ALU32_REG(BPF_ADD
, R7
, R0
),
1475 BPF_ALU32_REG(BPF_ADD
, R7
, R1
),
1476 BPF_ALU32_REG(BPF_ADD
, R7
, R2
),
1477 BPF_ALU32_REG(BPF_ADD
, R7
, R3
),
1478 BPF_ALU32_REG(BPF_ADD
, R7
, R4
),
1479 BPF_ALU32_REG(BPF_ADD
, R7
, R5
),
1480 BPF_ALU32_REG(BPF_ADD
, R7
, R6
),
1481 BPF_ALU32_REG(BPF_ADD
, R7
, R7
),
1482 BPF_ALU32_REG(BPF_ADD
, R7
, R8
),
1483 BPF_ALU32_REG(BPF_ADD
, R7
, R9
), /* R7 == 328605 */
1484 BPF_JMP_IMM(BPF_JEQ
, R7
, 328605, 1),
1486 BPF_ALU32_REG(BPF_ADD
, R8
, R0
),
1487 BPF_ALU32_REG(BPF_ADD
, R8
, R1
),
1488 BPF_ALU32_REG(BPF_ADD
, R8
, R2
),
1489 BPF_ALU32_REG(BPF_ADD
, R8
, R3
),
1490 BPF_ALU32_REG(BPF_ADD
, R8
, R4
),
1491 BPF_ALU32_REG(BPF_ADD
, R8
, R5
),
1492 BPF_ALU32_REG(BPF_ADD
, R8
, R6
),
1493 BPF_ALU32_REG(BPF_ADD
, R8
, R7
),
1494 BPF_ALU32_REG(BPF_ADD
, R8
, R8
),
1495 BPF_ALU32_REG(BPF_ADD
, R8
, R9
), /* R8 == 985799 */
1496 BPF_JMP_IMM(BPF_JEQ
, R8
, 985799, 1),
1498 BPF_ALU32_REG(BPF_ADD
, R9
, R0
),
1499 BPF_ALU32_REG(BPF_ADD
, R9
, R1
),
1500 BPF_ALU32_REG(BPF_ADD
, R9
, R2
),
1501 BPF_ALU32_REG(BPF_ADD
, R9
, R3
),
1502 BPF_ALU32_REG(BPF_ADD
, R9
, R4
),
1503 BPF_ALU32_REG(BPF_ADD
, R9
, R5
),
1504 BPF_ALU32_REG(BPF_ADD
, R9
, R6
),
1505 BPF_ALU32_REG(BPF_ADD
, R9
, R7
),
1506 BPF_ALU32_REG(BPF_ADD
, R9
, R8
),
1507 BPF_ALU32_REG(BPF_ADD
, R9
, R9
), /* R9 == 2957380 */
1508 BPF_ALU32_REG(BPF_MOV
, R0
, R9
),
1515 { /* Mainly checking JIT here. */
1518 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1519 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1520 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1521 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1522 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1523 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1524 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1525 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1526 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1527 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1528 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1529 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1530 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1531 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1532 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1533 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1534 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1535 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1536 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1537 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1538 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1539 BPF_JMP_IMM(BPF_JEQ
, R0
, -55, 1),
1541 BPF_ALU64_REG(BPF_SUB
, R1
, R0
),
1542 BPF_ALU64_REG(BPF_SUB
, R1
, R2
),
1543 BPF_ALU64_REG(BPF_SUB
, R1
, R3
),
1544 BPF_ALU64_REG(BPF_SUB
, R1
, R4
),
1545 BPF_ALU64_REG(BPF_SUB
, R1
, R5
),
1546 BPF_ALU64_REG(BPF_SUB
, R1
, R6
),
1547 BPF_ALU64_REG(BPF_SUB
, R1
, R7
),
1548 BPF_ALU64_REG(BPF_SUB
, R1
, R8
),
1549 BPF_ALU64_REG(BPF_SUB
, R1
, R9
),
1550 BPF_ALU64_IMM(BPF_SUB
, R1
, 10),
1551 BPF_ALU64_REG(BPF_SUB
, R2
, R0
),
1552 BPF_ALU64_REG(BPF_SUB
, R2
, R1
),
1553 BPF_ALU64_REG(BPF_SUB
, R2
, R3
),
1554 BPF_ALU64_REG(BPF_SUB
, R2
, R4
),
1555 BPF_ALU64_REG(BPF_SUB
, R2
, R5
),
1556 BPF_ALU64_REG(BPF_SUB
, R2
, R6
),
1557 BPF_ALU64_REG(BPF_SUB
, R2
, R7
),
1558 BPF_ALU64_REG(BPF_SUB
, R2
, R8
),
1559 BPF_ALU64_REG(BPF_SUB
, R2
, R9
),
1560 BPF_ALU64_IMM(BPF_SUB
, R2
, 10),
1561 BPF_ALU64_REG(BPF_SUB
, R3
, R0
),
1562 BPF_ALU64_REG(BPF_SUB
, R3
, R1
),
1563 BPF_ALU64_REG(BPF_SUB
, R3
, R2
),
1564 BPF_ALU64_REG(BPF_SUB
, R3
, R4
),
1565 BPF_ALU64_REG(BPF_SUB
, R3
, R5
),
1566 BPF_ALU64_REG(BPF_SUB
, R3
, R6
),
1567 BPF_ALU64_REG(BPF_SUB
, R3
, R7
),
1568 BPF_ALU64_REG(BPF_SUB
, R3
, R8
),
1569 BPF_ALU64_REG(BPF_SUB
, R3
, R9
),
1570 BPF_ALU64_IMM(BPF_SUB
, R3
, 10),
1571 BPF_ALU64_REG(BPF_SUB
, R4
, R0
),
1572 BPF_ALU64_REG(BPF_SUB
, R4
, R1
),
1573 BPF_ALU64_REG(BPF_SUB
, R4
, R2
),
1574 BPF_ALU64_REG(BPF_SUB
, R4
, R3
),
1575 BPF_ALU64_REG(BPF_SUB
, R4
, R5
),
1576 BPF_ALU64_REG(BPF_SUB
, R4
, R6
),
1577 BPF_ALU64_REG(BPF_SUB
, R4
, R7
),
1578 BPF_ALU64_REG(BPF_SUB
, R4
, R8
),
1579 BPF_ALU64_REG(BPF_SUB
, R4
, R9
),
1580 BPF_ALU64_IMM(BPF_SUB
, R4
, 10),
1581 BPF_ALU64_REG(BPF_SUB
, R5
, R0
),
1582 BPF_ALU64_REG(BPF_SUB
, R5
, R1
),
1583 BPF_ALU64_REG(BPF_SUB
, R5
, R2
),
1584 BPF_ALU64_REG(BPF_SUB
, R5
, R3
),
1585 BPF_ALU64_REG(BPF_SUB
, R5
, R4
),
1586 BPF_ALU64_REG(BPF_SUB
, R5
, R6
),
1587 BPF_ALU64_REG(BPF_SUB
, R5
, R7
),
1588 BPF_ALU64_REG(BPF_SUB
, R5
, R8
),
1589 BPF_ALU64_REG(BPF_SUB
, R5
, R9
),
1590 BPF_ALU64_IMM(BPF_SUB
, R5
, 10),
1591 BPF_ALU64_REG(BPF_SUB
, R6
, R0
),
1592 BPF_ALU64_REG(BPF_SUB
, R6
, R1
),
1593 BPF_ALU64_REG(BPF_SUB
, R6
, R2
),
1594 BPF_ALU64_REG(BPF_SUB
, R6
, R3
),
1595 BPF_ALU64_REG(BPF_SUB
, R6
, R4
),
1596 BPF_ALU64_REG(BPF_SUB
, R6
, R5
),
1597 BPF_ALU64_REG(BPF_SUB
, R6
, R7
),
1598 BPF_ALU64_REG(BPF_SUB
, R6
, R8
),
1599 BPF_ALU64_REG(BPF_SUB
, R6
, R9
),
1600 BPF_ALU64_IMM(BPF_SUB
, R6
, 10),
1601 BPF_ALU64_REG(BPF_SUB
, R7
, R0
),
1602 BPF_ALU64_REG(BPF_SUB
, R7
, R1
),
1603 BPF_ALU64_REG(BPF_SUB
, R7
, R2
),
1604 BPF_ALU64_REG(BPF_SUB
, R7
, R3
),
1605 BPF_ALU64_REG(BPF_SUB
, R7
, R4
),
1606 BPF_ALU64_REG(BPF_SUB
, R7
, R5
),
1607 BPF_ALU64_REG(BPF_SUB
, R7
, R6
),
1608 BPF_ALU64_REG(BPF_SUB
, R7
, R8
),
1609 BPF_ALU64_REG(BPF_SUB
, R7
, R9
),
1610 BPF_ALU64_IMM(BPF_SUB
, R7
, 10),
1611 BPF_ALU64_REG(BPF_SUB
, R8
, R0
),
1612 BPF_ALU64_REG(BPF_SUB
, R8
, R1
),
1613 BPF_ALU64_REG(BPF_SUB
, R8
, R2
),
1614 BPF_ALU64_REG(BPF_SUB
, R8
, R3
),
1615 BPF_ALU64_REG(BPF_SUB
, R8
, R4
),
1616 BPF_ALU64_REG(BPF_SUB
, R8
, R5
),
1617 BPF_ALU64_REG(BPF_SUB
, R8
, R6
),
1618 BPF_ALU64_REG(BPF_SUB
, R8
, R7
),
1619 BPF_ALU64_REG(BPF_SUB
, R8
, R9
),
1620 BPF_ALU64_IMM(BPF_SUB
, R8
, 10),
1621 BPF_ALU64_REG(BPF_SUB
, R9
, R0
),
1622 BPF_ALU64_REG(BPF_SUB
, R9
, R1
),
1623 BPF_ALU64_REG(BPF_SUB
, R9
, R2
),
1624 BPF_ALU64_REG(BPF_SUB
, R9
, R3
),
1625 BPF_ALU64_REG(BPF_SUB
, R9
, R4
),
1626 BPF_ALU64_REG(BPF_SUB
, R9
, R5
),
1627 BPF_ALU64_REG(BPF_SUB
, R9
, R6
),
1628 BPF_ALU64_REG(BPF_SUB
, R9
, R7
),
1629 BPF_ALU64_REG(BPF_SUB
, R9
, R8
),
1630 BPF_ALU64_IMM(BPF_SUB
, R9
, 10),
1631 BPF_ALU64_IMM(BPF_SUB
, R0
, 10),
1632 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
1633 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
1634 BPF_ALU64_REG(BPF_SUB
, R0
, R2
),
1635 BPF_ALU64_REG(BPF_SUB
, R0
, R3
),
1636 BPF_ALU64_REG(BPF_SUB
, R0
, R4
),
1637 BPF_ALU64_REG(BPF_SUB
, R0
, R5
),
1638 BPF_ALU64_REG(BPF_SUB
, R0
, R6
),
1639 BPF_ALU64_REG(BPF_SUB
, R0
, R7
),
1640 BPF_ALU64_REG(BPF_SUB
, R0
, R8
),
1641 BPF_ALU64_REG(BPF_SUB
, R0
, R9
),
1648 { /* Mainly checking JIT here. */
1651 BPF_ALU64_REG(BPF_SUB
, R0
, R0
),
1652 BPF_ALU64_REG(BPF_XOR
, R1
, R1
),
1653 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 1),
1655 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1656 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1657 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1658 BPF_ALU64_REG(BPF_XOR
, R2
, R2
),
1659 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
1661 BPF_ALU64_REG(BPF_SUB
, R2
, R2
),
1662 BPF_ALU64_REG(BPF_XOR
, R3
, R3
),
1663 BPF_ALU64_IMM(BPF_MOV
, R0
, 10),
1664 BPF_ALU64_IMM(BPF_MOV
, R1
, -1),
1665 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 1),
1667 BPF_ALU64_REG(BPF_SUB
, R3
, R3
),
1668 BPF_ALU64_REG(BPF_XOR
, R4
, R4
),
1669 BPF_ALU64_IMM(BPF_MOV
, R2
, 1),
1670 BPF_ALU64_IMM(BPF_MOV
, R5
, -1),
1671 BPF_JMP_REG(BPF_JEQ
, R3
, R4
, 1),
1673 BPF_ALU64_REG(BPF_SUB
, R4
, R4
),
1674 BPF_ALU64_REG(BPF_XOR
, R5
, R5
),
1675 BPF_ALU64_IMM(BPF_MOV
, R3
, 1),
1676 BPF_ALU64_IMM(BPF_MOV
, R7
, -1),
1677 BPF_JMP_REG(BPF_JEQ
, R5
, R4
, 1),
1679 BPF_ALU64_IMM(BPF_MOV
, R5
, 1),
1680 BPF_ALU64_REG(BPF_SUB
, R5
, R5
),
1681 BPF_ALU64_REG(BPF_XOR
, R6
, R6
),
1682 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1683 BPF_ALU64_IMM(BPF_MOV
, R8
, -1),
1684 BPF_JMP_REG(BPF_JEQ
, R5
, R6
, 1),
1686 BPF_ALU64_REG(BPF_SUB
, R6
, R6
),
1687 BPF_ALU64_REG(BPF_XOR
, R7
, R7
),
1688 BPF_JMP_REG(BPF_JEQ
, R7
, R6
, 1),
1690 BPF_ALU64_REG(BPF_SUB
, R7
, R7
),
1691 BPF_ALU64_REG(BPF_XOR
, R8
, R8
),
1692 BPF_JMP_REG(BPF_JEQ
, R7
, R8
, 1),
1694 BPF_ALU64_REG(BPF_SUB
, R8
, R8
),
1695 BPF_ALU64_REG(BPF_XOR
, R9
, R9
),
1696 BPF_JMP_REG(BPF_JEQ
, R9
, R8
, 1),
1698 BPF_ALU64_REG(BPF_SUB
, R9
, R9
),
1699 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1700 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 1),
1702 BPF_ALU64_REG(BPF_SUB
, R1
, R1
),
1703 BPF_ALU64_REG(BPF_XOR
, R0
, R0
),
1704 BPF_JMP_REG(BPF_JEQ
, R9
, R0
, 2),
1705 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1707 BPF_ALU64_IMM(BPF_MOV
, R0
, 1),
1714 { /* Mainly checking JIT here. */
1717 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1718 BPF_ALU64_IMM(BPF_MOV
, R1
, 1),
1719 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1720 BPF_ALU64_IMM(BPF_MOV
, R3
, 3),
1721 BPF_ALU64_IMM(BPF_MOV
, R4
, 4),
1722 BPF_ALU64_IMM(BPF_MOV
, R5
, 5),
1723 BPF_ALU64_IMM(BPF_MOV
, R6
, 6),
1724 BPF_ALU64_IMM(BPF_MOV
, R7
, 7),
1725 BPF_ALU64_IMM(BPF_MOV
, R8
, 8),
1726 BPF_ALU64_IMM(BPF_MOV
, R9
, 9),
1727 BPF_ALU64_REG(BPF_MUL
, R0
, R0
),
1728 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
1729 BPF_ALU64_REG(BPF_MUL
, R0
, R2
),
1730 BPF_ALU64_REG(BPF_MUL
, R0
, R3
),
1731 BPF_ALU64_REG(BPF_MUL
, R0
, R4
),
1732 BPF_ALU64_REG(BPF_MUL
, R0
, R5
),
1733 BPF_ALU64_REG(BPF_MUL
, R0
, R6
),
1734 BPF_ALU64_REG(BPF_MUL
, R0
, R7
),
1735 BPF_ALU64_REG(BPF_MUL
, R0
, R8
),
1736 BPF_ALU64_REG(BPF_MUL
, R0
, R9
),
1737 BPF_ALU64_IMM(BPF_MUL
, R0
, 10),
1738 BPF_JMP_IMM(BPF_JEQ
, R0
, 439084800, 1),
1740 BPF_ALU64_REG(BPF_MUL
, R1
, R0
),
1741 BPF_ALU64_REG(BPF_MUL
, R1
, R2
),
1742 BPF_ALU64_REG(BPF_MUL
, R1
, R3
),
1743 BPF_ALU64_REG(BPF_MUL
, R1
, R4
),
1744 BPF_ALU64_REG(BPF_MUL
, R1
, R5
),
1745 BPF_ALU64_REG(BPF_MUL
, R1
, R6
),
1746 BPF_ALU64_REG(BPF_MUL
, R1
, R7
),
1747 BPF_ALU64_REG(BPF_MUL
, R1
, R8
),
1748 BPF_ALU64_REG(BPF_MUL
, R1
, R9
),
1749 BPF_ALU64_IMM(BPF_MUL
, R1
, 10),
1750 BPF_ALU64_REG(BPF_MOV
, R2
, R1
),
1751 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1752 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5a924, 1),
1754 BPF_ALU64_IMM(BPF_LSH
, R1
, 32),
1755 BPF_ALU64_IMM(BPF_ARSH
, R1
, 32),
1756 BPF_JMP_IMM(BPF_JEQ
, R1
, 0xebb90000, 1),
1758 BPF_ALU64_REG(BPF_MUL
, R2
, R0
),
1759 BPF_ALU64_REG(BPF_MUL
, R2
, R1
),
1760 BPF_ALU64_REG(BPF_MUL
, R2
, R3
),
1761 BPF_ALU64_REG(BPF_MUL
, R2
, R4
),
1762 BPF_ALU64_REG(BPF_MUL
, R2
, R5
),
1763 BPF_ALU64_REG(BPF_MUL
, R2
, R6
),
1764 BPF_ALU64_REG(BPF_MUL
, R2
, R7
),
1765 BPF_ALU64_REG(BPF_MUL
, R2
, R8
),
1766 BPF_ALU64_REG(BPF_MUL
, R2
, R9
),
1767 BPF_ALU64_IMM(BPF_MUL
, R2
, 10),
1768 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
1769 BPF_ALU64_REG(BPF_MOV
, R0
, R2
),
1774 { { 0, 0x35d97ef2 } }
1776 { /* Mainly checking JIT here. */
1779 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1780 BPF_MOV64_REG(R1
, R0
),
1781 BPF_MOV64_REG(R2
, R1
),
1782 BPF_MOV64_REG(R3
, R2
),
1783 BPF_MOV64_REG(R4
, R3
),
1784 BPF_MOV64_REG(R5
, R4
),
1785 BPF_MOV64_REG(R6
, R5
),
1786 BPF_MOV64_REG(R7
, R6
),
1787 BPF_MOV64_REG(R8
, R7
),
1788 BPF_MOV64_REG(R9
, R8
),
1789 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
1790 BPF_ALU64_IMM(BPF_MOV
, R1
, 0),
1791 BPF_ALU64_IMM(BPF_MOV
, R2
, 0),
1792 BPF_ALU64_IMM(BPF_MOV
, R3
, 0),
1793 BPF_ALU64_IMM(BPF_MOV
, R4
, 0),
1794 BPF_ALU64_IMM(BPF_MOV
, R5
, 0),
1795 BPF_ALU64_IMM(BPF_MOV
, R6
, 0),
1796 BPF_ALU64_IMM(BPF_MOV
, R7
, 0),
1797 BPF_ALU64_IMM(BPF_MOV
, R8
, 0),
1798 BPF_ALU64_IMM(BPF_MOV
, R9
, 0),
1799 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1800 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1801 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1802 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1803 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1804 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1805 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1806 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1807 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1808 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1809 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1816 { /* Mainly checking JIT here. */
1819 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1820 BPF_MOV64_REG(R1
, R0
),
1821 BPF_MOV64_REG(R2
, R1
),
1822 BPF_MOV64_REG(R3
, R2
),
1823 BPF_MOV64_REG(R4
, R3
),
1824 BPF_MOV64_REG(R5
, R4
),
1825 BPF_MOV64_REG(R6
, R5
),
1826 BPF_MOV64_REG(R7
, R6
),
1827 BPF_MOV64_REG(R8
, R7
),
1828 BPF_MOV64_REG(R9
, R8
),
1829 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
1830 BPF_ALU32_IMM(BPF_MOV
, R1
, 0),
1831 BPF_ALU32_IMM(BPF_MOV
, R2
, 0),
1832 BPF_ALU32_IMM(BPF_MOV
, R3
, 0),
1833 BPF_ALU32_IMM(BPF_MOV
, R4
, 0),
1834 BPF_ALU32_IMM(BPF_MOV
, R5
, 0),
1835 BPF_ALU32_IMM(BPF_MOV
, R6
, 0),
1836 BPF_ALU32_IMM(BPF_MOV
, R7
, 0),
1837 BPF_ALU32_IMM(BPF_MOV
, R8
, 0),
1838 BPF_ALU32_IMM(BPF_MOV
, R9
, 0),
1839 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1840 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1841 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1842 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1843 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1844 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1845 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1846 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1847 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1848 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1849 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1856 { /* Mainly checking JIT here. */
1859 BPF_LD_IMM64(R0
, 0xffffffffffffffffLL
),
1860 BPF_MOV64_REG(R1
, R0
),
1861 BPF_MOV64_REG(R2
, R1
),
1862 BPF_MOV64_REG(R3
, R2
),
1863 BPF_MOV64_REG(R4
, R3
),
1864 BPF_MOV64_REG(R5
, R4
),
1865 BPF_MOV64_REG(R6
, R5
),
1866 BPF_MOV64_REG(R7
, R6
),
1867 BPF_MOV64_REG(R8
, R7
),
1868 BPF_MOV64_REG(R9
, R8
),
1869 BPF_LD_IMM64(R0
, 0x0LL
),
1870 BPF_LD_IMM64(R1
, 0x0LL
),
1871 BPF_LD_IMM64(R2
, 0x0LL
),
1872 BPF_LD_IMM64(R3
, 0x0LL
),
1873 BPF_LD_IMM64(R4
, 0x0LL
),
1874 BPF_LD_IMM64(R5
, 0x0LL
),
1875 BPF_LD_IMM64(R6
, 0x0LL
),
1876 BPF_LD_IMM64(R7
, 0x0LL
),
1877 BPF_LD_IMM64(R8
, 0x0LL
),
1878 BPF_LD_IMM64(R9
, 0x0LL
),
1879 BPF_ALU64_REG(BPF_ADD
, R0
, R0
),
1880 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
1881 BPF_ALU64_REG(BPF_ADD
, R0
, R2
),
1882 BPF_ALU64_REG(BPF_ADD
, R0
, R3
),
1883 BPF_ALU64_REG(BPF_ADD
, R0
, R4
),
1884 BPF_ALU64_REG(BPF_ADD
, R0
, R5
),
1885 BPF_ALU64_REG(BPF_ADD
, R0
, R6
),
1886 BPF_ALU64_REG(BPF_ADD
, R0
, R7
),
1887 BPF_ALU64_REG(BPF_ADD
, R0
, R8
),
1888 BPF_ALU64_REG(BPF_ADD
, R0
, R9
),
1889 BPF_ALU64_IMM(BPF_ADD
, R0
, 0xfefe),
1899 BPF_ALU64_IMM(BPF_MOV
, R0
, 11),
1900 BPF_ALU64_IMM(BPF_ADD
, R0
, -1),
1901 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1902 BPF_ALU64_IMM(BPF_XOR
, R2
, 3),
1903 BPF_ALU64_REG(BPF_DIV
, R0
, R2
),
1904 BPF_JMP_IMM(BPF_JEQ
, R0
, 10, 1),
1906 BPF_ALU64_IMM(BPF_MOD
, R0
, 3),
1907 BPF_JMP_IMM(BPF_JEQ
, R0
, 1, 1),
1909 BPF_ALU64_IMM(BPF_MOV
, R0
, -1),
1917 "INT: shifts by register",
1919 BPF_MOV64_IMM(R0
, -1234),
1920 BPF_MOV64_IMM(R1
, 1),
1921 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
1922 BPF_JMP_IMM(BPF_JEQ
, R0
, 0x7ffffd97, 1),
1924 BPF_MOV64_IMM(R2
, 1),
1925 BPF_ALU64_REG(BPF_LSH
, R0
, R2
),
1926 BPF_MOV32_IMM(R4
, -1234),
1927 BPF_JMP_REG(BPF_JEQ
, R0
, R4
, 1),
1929 BPF_ALU64_IMM(BPF_AND
, R4
, 63),
1930 BPF_ALU64_REG(BPF_LSH
, R0
, R4
), /* R0 <= 46 */
1931 BPF_MOV64_IMM(R3
, 47),
1932 BPF_ALU64_REG(BPF_ARSH
, R0
, R3
),
1933 BPF_JMP_IMM(BPF_JEQ
, R0
, -617, 1),
1935 BPF_MOV64_IMM(R2
, 1),
1936 BPF_ALU64_REG(BPF_LSH
, R4
, R2
), /* R4 = 46 << 1 */
1937 BPF_JMP_IMM(BPF_JEQ
, R4
, 92, 1),
1939 BPF_MOV64_IMM(R4
, 4),
1940 BPF_ALU64_REG(BPF_LSH
, R4
, R4
), /* R4 = 4 << 4 */
1941 BPF_JMP_IMM(BPF_JEQ
, R4
, 64, 1),
1943 BPF_MOV64_IMM(R4
, 5),
1944 BPF_ALU32_REG(BPF_LSH
, R4
, R4
), /* R4 = 5 << 5 */
1945 BPF_JMP_IMM(BPF_JEQ
, R4
, 160, 1),
1947 BPF_MOV64_IMM(R0
, -1),
1957 BPF_ALU64_REG(BPF_MOV
, R6
, R1
),
1958 BPF_LD_ABS(BPF_B
, 3),
1959 BPF_ALU64_IMM(BPF_MOV
, R2
, 2),
1960 BPF_ALU32_REG(BPF_DIV
, R0
, R2
),
1961 BPF_ALU64_REG(BPF_MOV
, R8
, R0
),
1962 BPF_LD_ABS(BPF_B
, 4),
1963 BPF_ALU64_REG(BPF_ADD
, R8
, R0
),
1964 BPF_LD_IND(BPF_B
, R8
, -70),
1968 { 10, 20, 30, 40, 50 },
1969 { { 4, 0 }, { 5, 10 } }
1974 BPF_ALU64_REG(BPF_MOV
, R6
, R1
),
1975 BPF_ALU64_IMM(BPF_MOV
, R7
, 0),
1976 BPF_LD_ABS(BPF_B
, 3),
1977 BPF_ALU32_REG(BPF_DIV
, R0
, R7
),
1981 { 10, 20, 30, 40, 50 },
1982 { { 3, 0 }, { 4, 0 } }
1985 "check: missing ret",
1987 BPF_STMT(BPF_LD
| BPF_IMM
, 1),
1989 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
1992 .fill_helper
= NULL
,
1993 .expected_errcode
= -EINVAL
,
1998 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0),
1999 BPF_STMT(BPF_RET
| BPF_K
, 0)
2001 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2004 .fill_helper
= NULL
,
2005 .expected_errcode
= -EINVAL
,
2008 "check: unknown insn",
2010 /* seccomp insn, rejected in socket filter */
2011 BPF_STMT(BPF_LDX
| BPF_W
| BPF_ABS
, 0),
2012 BPF_STMT(BPF_RET
| BPF_K
, 0)
2014 CLASSIC
| FLAG_EXPECTED_FAIL
,
2017 .fill_helper
= NULL
,
2018 .expected_errcode
= -EINVAL
,
2021 "check: out of range spill/fill",
2023 BPF_STMT(BPF_STX
, 16),
2024 BPF_STMT(BPF_RET
| BPF_K
, 0)
2026 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2029 .fill_helper
= NULL
,
2030 .expected_errcode
= -EINVAL
,
2035 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2036 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 15),
2037 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2038 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2039 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2040 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2041 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2042 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2043 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2044 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2045 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2046 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2047 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2048 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2049 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2050 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 3, 4),
2051 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2052 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90c2894d, 1, 2),
2053 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2054 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2055 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2056 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2057 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2058 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2059 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2060 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2061 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2062 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2063 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2064 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2065 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2066 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2067 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2068 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2069 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 2, 3),
2070 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x2ac28349, 1, 2),
2071 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2072 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 14, 15),
2073 BPF_JUMP(BPF_JMP
| BPF_JGE
, 0, 13, 14),
2074 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2075 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2076 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2077 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2078 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2079 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2080 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2081 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2082 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2083 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2084 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2085 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2086 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2087 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 2, 3),
2088 BPF_JUMP(BPF_JMP
| BPF_JEQ
, 0x90d2ff41, 1, 2),
2089 BPF_STMT(BPF_LD
| BPF_H
| BPF_ABS
, 0),
2090 BPF_STMT(BPF_RET
| BPF_A
, 0),
2091 BPF_STMT(BPF_RET
| BPF_A
, 0),
2094 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2095 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2097 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2098 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2099 0xc0, 0xa8, 0x33, 0x01,
2100 0xc0, 0xa8, 0x33, 0x02,
2103 0x00, 0x14, 0x00, 0x00,
2104 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2105 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2106 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2107 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2108 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2109 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2110 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2111 0xcc, 0xcc, 0xcc, 0xcc },
2117 BPF_STMT(BPF_RET
| BPF_X
, 0),
2119 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2122 .fill_helper
= NULL
,
2123 .expected_errcode
= -EINVAL
,
2126 "check: LDX + RET X",
2128 BPF_STMT(BPF_LDX
| BPF_IMM
, 42),
2129 BPF_STMT(BPF_RET
| BPF_X
, 0),
2131 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2134 .fill_helper
= NULL
,
2135 .expected_errcode
= -EINVAL
,
2137 { /* Mainly checking JIT here. */
2138 "M[]: alt STX + LDX",
2140 BPF_STMT(BPF_LDX
| BPF_IMM
, 100),
2141 BPF_STMT(BPF_STX
, 0),
2142 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2143 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2144 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2145 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2146 BPF_STMT(BPF_STX
, 1),
2147 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2148 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2149 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2150 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2151 BPF_STMT(BPF_STX
, 2),
2152 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2153 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2154 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2155 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2156 BPF_STMT(BPF_STX
, 3),
2157 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2158 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2159 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2160 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2161 BPF_STMT(BPF_STX
, 4),
2162 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2163 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2164 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2165 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2166 BPF_STMT(BPF_STX
, 5),
2167 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2168 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2169 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2170 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2171 BPF_STMT(BPF_STX
, 6),
2172 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2173 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2174 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2175 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2176 BPF_STMT(BPF_STX
, 7),
2177 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2178 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2179 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2180 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2181 BPF_STMT(BPF_STX
, 8),
2182 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2183 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2184 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2185 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2186 BPF_STMT(BPF_STX
, 9),
2187 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2188 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2189 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2190 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2191 BPF_STMT(BPF_STX
, 10),
2192 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2193 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2194 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2195 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2196 BPF_STMT(BPF_STX
, 11),
2197 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2198 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2199 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2200 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2201 BPF_STMT(BPF_STX
, 12),
2202 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2203 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2204 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2205 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2206 BPF_STMT(BPF_STX
, 13),
2207 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2208 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2209 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2210 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2211 BPF_STMT(BPF_STX
, 14),
2212 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2213 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2214 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2215 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2216 BPF_STMT(BPF_STX
, 15),
2217 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2218 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2219 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 1),
2220 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
2221 BPF_STMT(BPF_RET
| BPF_A
, 0),
2223 CLASSIC
| FLAG_NO_DATA
,
2227 { /* Mainly checking JIT here. */
2228 "M[]: full STX + full LDX",
2230 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbadfeedb),
2231 BPF_STMT(BPF_STX
, 0),
2232 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xecabedae),
2233 BPF_STMT(BPF_STX
, 1),
2234 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xafccfeaf),
2235 BPF_STMT(BPF_STX
, 2),
2236 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbffdcedc),
2237 BPF_STMT(BPF_STX
, 3),
2238 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbbbdccb),
2239 BPF_STMT(BPF_STX
, 4),
2240 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfbabcbda),
2241 BPF_STMT(BPF_STX
, 5),
2242 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaedecbdb),
2243 BPF_STMT(BPF_STX
, 6),
2244 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xadebbade),
2245 BPF_STMT(BPF_STX
, 7),
2246 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfcfcfaec),
2247 BPF_STMT(BPF_STX
, 8),
2248 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbcdddbdc),
2249 BPF_STMT(BPF_STX
, 9),
2250 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfeefdfac),
2251 BPF_STMT(BPF_STX
, 10),
2252 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xcddcdeea),
2253 BPF_STMT(BPF_STX
, 11),
2254 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaccfaebb),
2255 BPF_STMT(BPF_STX
, 12),
2256 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xbdcccdcf),
2257 BPF_STMT(BPF_STX
, 13),
2258 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xaaedecde),
2259 BPF_STMT(BPF_STX
, 14),
2260 BPF_STMT(BPF_LDX
| BPF_IMM
, 0xfaeacdad),
2261 BPF_STMT(BPF_STX
, 15),
2262 BPF_STMT(BPF_LDX
| BPF_MEM
, 0),
2263 BPF_STMT(BPF_MISC
| BPF_TXA
, 0),
2264 BPF_STMT(BPF_LDX
| BPF_MEM
, 1),
2265 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2266 BPF_STMT(BPF_LDX
| BPF_MEM
, 2),
2267 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2268 BPF_STMT(BPF_LDX
| BPF_MEM
, 3),
2269 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2270 BPF_STMT(BPF_LDX
| BPF_MEM
, 4),
2271 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2272 BPF_STMT(BPF_LDX
| BPF_MEM
, 5),
2273 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2274 BPF_STMT(BPF_LDX
| BPF_MEM
, 6),
2275 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2276 BPF_STMT(BPF_LDX
| BPF_MEM
, 7),
2277 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2278 BPF_STMT(BPF_LDX
| BPF_MEM
, 8),
2279 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2280 BPF_STMT(BPF_LDX
| BPF_MEM
, 9),
2281 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2282 BPF_STMT(BPF_LDX
| BPF_MEM
, 10),
2283 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2284 BPF_STMT(BPF_LDX
| BPF_MEM
, 11),
2285 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2286 BPF_STMT(BPF_LDX
| BPF_MEM
, 12),
2287 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2288 BPF_STMT(BPF_LDX
| BPF_MEM
, 13),
2289 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2290 BPF_STMT(BPF_LDX
| BPF_MEM
, 14),
2291 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2292 BPF_STMT(BPF_LDX
| BPF_MEM
, 15),
2293 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
2294 BPF_STMT(BPF_RET
| BPF_A
, 0),
2296 CLASSIC
| FLAG_NO_DATA
,
2298 { { 0, 0x2a5a5e5 } },
2301 "check: SKF_AD_MAX",
2303 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2304 SKF_AD_OFF
+ SKF_AD_MAX
),
2305 BPF_STMT(BPF_RET
| BPF_A
, 0),
2307 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
2310 .fill_helper
= NULL
,
2311 .expected_errcode
= -EINVAL
,
2313 { /* Passes checker but fails during runtime. */
2314 "LD [SKF_AD_OFF-1]",
2316 BPF_STMT(BPF_LD
| BPF_W
| BPF_ABS
,
2318 BPF_STMT(BPF_RET
| BPF_K
, 1),
2325 "load 64-bit immediate",
2327 BPF_LD_IMM64(R1
, 0x567800001234LL
),
2328 BPF_MOV64_REG(R2
, R1
),
2329 BPF_MOV64_REG(R3
, R2
),
2330 BPF_ALU64_IMM(BPF_RSH
, R2
, 32),
2331 BPF_ALU64_IMM(BPF_LSH
, R3
, 32),
2332 BPF_ALU64_IMM(BPF_RSH
, R3
, 32),
2333 BPF_ALU64_IMM(BPF_MOV
, R0
, 0),
2334 BPF_JMP_IMM(BPF_JEQ
, R2
, 0x5678, 1),
2336 BPF_JMP_IMM(BPF_JEQ
, R3
, 0x1234, 1),
2338 BPF_LD_IMM64(R0
, 0x1ffffffffLL
),
2339 BPF_ALU64_IMM(BPF_RSH
, R0
, 32), /* R0 = 1 */
2349 BPF_MOV64_REG(R6
, R1
),
2350 BPF_LD_ABS(BPF_H
, 12),
2351 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 28),
2352 BPF_LD_ABS(BPF_H
, 12),
2353 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 26),
2354 BPF_MOV32_IMM(R0
, 18),
2355 BPF_STX_MEM(BPF_W
, R10
, R0
, -64),
2356 BPF_LDX_MEM(BPF_W
, R7
, R10
, -64),
2357 BPF_LD_IND(BPF_W
, R7
, 14),
2358 BPF_STX_MEM(BPF_W
, R10
, R0
, -60),
2359 BPF_MOV32_IMM(R0
, 280971478),
2360 BPF_STX_MEM(BPF_W
, R10
, R0
, -56),
2361 BPF_LDX_MEM(BPF_W
, R7
, R10
, -56),
2362 BPF_LDX_MEM(BPF_W
, R0
, R10
, -60),
2363 BPF_ALU32_REG(BPF_SUB
, R0
, R7
),
2364 BPF_JMP_IMM(BPF_JNE
, R0
, 0, 15),
2365 BPF_LD_ABS(BPF_H
, 12),
2366 BPF_JMP_IMM(BPF_JNE
, R0
, 0x806, 13),
2367 BPF_MOV32_IMM(R0
, 22),
2368 BPF_STX_MEM(BPF_W
, R10
, R0
, -56),
2369 BPF_LDX_MEM(BPF_W
, R7
, R10
, -56),
2370 BPF_LD_IND(BPF_H
, R7
, 14),
2371 BPF_STX_MEM(BPF_W
, R10
, R0
, -52),
2372 BPF_MOV32_IMM(R0
, 17366),
2373 BPF_STX_MEM(BPF_W
, R10
, R0
, -48),
2374 BPF_LDX_MEM(BPF_W
, R7
, R10
, -48),
2375 BPF_LDX_MEM(BPF_W
, R0
, R10
, -52),
2376 BPF_ALU32_REG(BPF_SUB
, R0
, R7
),
2377 BPF_JMP_IMM(BPF_JNE
, R0
, 0, 2),
2378 BPF_MOV32_IMM(R0
, 256),
2380 BPF_MOV32_IMM(R0
, 0),
2384 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2385 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2386 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
2390 /* BPF_ALU | BPF_MOV | BPF_X */
2392 "ALU_MOV_X: dst = 2",
2394 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2395 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2403 "ALU_MOV_X: dst = 4294967295",
2405 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2406 BPF_ALU32_REG(BPF_MOV
, R0
, R1
),
2411 { { 0, 4294967295U } },
2414 "ALU64_MOV_X: dst = 2",
2416 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2417 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2425 "ALU64_MOV_X: dst = 4294967295",
2427 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
2428 BPF_ALU64_REG(BPF_MOV
, R0
, R1
),
2433 { { 0, 4294967295U } },
2435 /* BPF_ALU | BPF_MOV | BPF_K */
2437 "ALU_MOV_K: dst = 2",
2439 BPF_ALU32_IMM(BPF_MOV
, R0
, 2),
2447 "ALU_MOV_K: dst = 4294967295",
2449 BPF_ALU32_IMM(BPF_MOV
, R0
, 4294967295U),
2454 { { 0, 4294967295U } },
2457 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2459 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2460 BPF_LD_IMM64(R3
, 0x00000000ffffffffLL
),
2461 BPF_ALU32_IMM(BPF_MOV
, R2
, 0xffffffff),
2462 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2463 BPF_MOV32_IMM(R0
, 2),
2465 BPF_MOV32_IMM(R0
, 1),
2473 "ALU64_MOV_K: dst = 2",
2475 BPF_ALU64_IMM(BPF_MOV
, R0
, 2),
2483 "ALU64_MOV_K: dst = 2147483647",
2485 BPF_ALU64_IMM(BPF_MOV
, R0
, 2147483647),
2490 { { 0, 2147483647 } },
2493 "ALU64_OR_K: dst = 0x0",
2495 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2496 BPF_LD_IMM64(R3
, 0x0),
2497 BPF_ALU64_IMM(BPF_MOV
, R2
, 0x0),
2498 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2499 BPF_MOV32_IMM(R0
, 2),
2501 BPF_MOV32_IMM(R0
, 1),
2509 "ALU64_MOV_K: dst = -1",
2511 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
2512 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2513 BPF_ALU64_IMM(BPF_MOV
, R2
, 0xffffffff),
2514 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2515 BPF_MOV32_IMM(R0
, 2),
2517 BPF_MOV32_IMM(R0
, 1),
2524 /* BPF_ALU | BPF_ADD | BPF_X */
2526 "ALU_ADD_X: 1 + 2 = 3",
2528 BPF_LD_IMM64(R0
, 1),
2529 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2530 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2538 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2540 BPF_LD_IMM64(R0
, 1),
2541 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2542 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2547 { { 0, 4294967295U } },
2550 "ALU_ADD_X: 2 + 4294967294 = 0",
2552 BPF_LD_IMM64(R0
, 2),
2553 BPF_LD_IMM64(R1
, 4294967294U),
2554 BPF_ALU32_REG(BPF_ADD
, R0
, R1
),
2555 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2556 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2558 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2566 "ALU64_ADD_X: 1 + 2 = 3",
2568 BPF_LD_IMM64(R0
, 1),
2569 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
2570 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2578 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2580 BPF_LD_IMM64(R0
, 1),
2581 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2582 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2587 { { 0, 4294967295U } },
2590 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2592 BPF_LD_IMM64(R0
, 2),
2593 BPF_LD_IMM64(R1
, 4294967294U),
2594 BPF_LD_IMM64(R2
, 4294967296ULL),
2595 BPF_ALU64_REG(BPF_ADD
, R0
, R1
),
2596 BPF_JMP_REG(BPF_JEQ
, R0
, R2
, 2),
2597 BPF_MOV32_IMM(R0
, 0),
2599 BPF_MOV32_IMM(R0
, 1),
2606 /* BPF_ALU | BPF_ADD | BPF_K */
2608 "ALU_ADD_K: 1 + 2 = 3",
2610 BPF_LD_IMM64(R0
, 1),
2611 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2619 "ALU_ADD_K: 3 + 0 = 3",
2621 BPF_LD_IMM64(R0
, 3),
2622 BPF_ALU32_IMM(BPF_ADD
, R0
, 0),
2630 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2632 BPF_LD_IMM64(R0
, 1),
2633 BPF_ALU32_IMM(BPF_ADD
, R0
, 4294967294U),
2638 { { 0, 4294967295U } },
2641 "ALU_ADD_K: 4294967294 + 2 = 0",
2643 BPF_LD_IMM64(R0
, 4294967294U),
2644 BPF_ALU32_IMM(BPF_ADD
, R0
, 2),
2645 BPF_JMP_IMM(BPF_JEQ
, R0
, 0, 2),
2646 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2648 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2656 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2658 BPF_LD_IMM64(R2
, 0x0),
2659 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
2660 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffffffff),
2661 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2662 BPF_MOV32_IMM(R0
, 2),
2664 BPF_MOV32_IMM(R0
, 1),
2672 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2674 BPF_LD_IMM64(R2
, 0x0),
2675 BPF_LD_IMM64(R3
, 0xffff),
2676 BPF_ALU32_IMM(BPF_ADD
, R2
, 0xffff),
2677 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2678 BPF_MOV32_IMM(R0
, 2),
2680 BPF_MOV32_IMM(R0
, 1),
2688 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2690 BPF_LD_IMM64(R2
, 0x0),
2691 BPF_LD_IMM64(R3
, 0x7fffffff),
2692 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x7fffffff),
2693 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2694 BPF_MOV32_IMM(R0
, 2),
2696 BPF_MOV32_IMM(R0
, 1),
2704 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2706 BPF_LD_IMM64(R2
, 0x0),
2707 BPF_LD_IMM64(R3
, 0x80000000),
2708 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80000000),
2709 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2710 BPF_MOV32_IMM(R0
, 2),
2712 BPF_MOV32_IMM(R0
, 1),
2720 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2722 BPF_LD_IMM64(R2
, 0x0),
2723 BPF_LD_IMM64(R3
, 0x80008000),
2724 BPF_ALU32_IMM(BPF_ADD
, R2
, 0x80008000),
2725 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2726 BPF_MOV32_IMM(R0
, 2),
2728 BPF_MOV32_IMM(R0
, 1),
2736 "ALU64_ADD_K: 1 + 2 = 3",
2738 BPF_LD_IMM64(R0
, 1),
2739 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2747 "ALU64_ADD_K: 3 + 0 = 3",
2749 BPF_LD_IMM64(R0
, 3),
2750 BPF_ALU64_IMM(BPF_ADD
, R0
, 0),
2758 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2760 BPF_LD_IMM64(R0
, 1),
2761 BPF_ALU64_IMM(BPF_ADD
, R0
, 2147483646),
2766 { { 0, 2147483647 } },
2769 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2771 BPF_LD_IMM64(R0
, 4294967294U),
2772 BPF_LD_IMM64(R1
, 4294967296ULL),
2773 BPF_ALU64_IMM(BPF_ADD
, R0
, 2),
2774 BPF_JMP_REG(BPF_JEQ
, R0
, R1
, 2),
2775 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
2777 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
2785 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2787 BPF_LD_IMM64(R0
, 2147483646),
2788 BPF_ALU64_IMM(BPF_ADD
, R0
, -2147483647),
2796 "ALU64_ADD_K: 1 + 0 = 1",
2798 BPF_LD_IMM64(R2
, 0x1),
2799 BPF_LD_IMM64(R3
, 0x1),
2800 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x0),
2801 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2802 BPF_MOV32_IMM(R0
, 2),
2804 BPF_MOV32_IMM(R0
, 1),
2812 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2814 BPF_LD_IMM64(R2
, 0x0),
2815 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
2816 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffffffff),
2817 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2818 BPF_MOV32_IMM(R0
, 2),
2820 BPF_MOV32_IMM(R0
, 1),
2828 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2830 BPF_LD_IMM64(R2
, 0x0),
2831 BPF_LD_IMM64(R3
, 0xffff),
2832 BPF_ALU64_IMM(BPF_ADD
, R2
, 0xffff),
2833 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2834 BPF_MOV32_IMM(R0
, 2),
2836 BPF_MOV32_IMM(R0
, 1),
2844 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2846 BPF_LD_IMM64(R2
, 0x0),
2847 BPF_LD_IMM64(R3
, 0x7fffffff),
2848 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x7fffffff),
2849 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2850 BPF_MOV32_IMM(R0
, 2),
2852 BPF_MOV32_IMM(R0
, 1),
2860 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2862 BPF_LD_IMM64(R2
, 0x0),
2863 BPF_LD_IMM64(R3
, 0xffffffff80000000LL
),
2864 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80000000),
2865 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2866 BPF_MOV32_IMM(R0
, 2),
2868 BPF_MOV32_IMM(R0
, 1),
2876 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2878 BPF_LD_IMM64(R2
, 0x0),
2879 BPF_LD_IMM64(R3
, 0xffffffff80008000LL
),
2880 BPF_ALU64_IMM(BPF_ADD
, R2
, 0x80008000),
2881 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
2882 BPF_MOV32_IMM(R0
, 2),
2884 BPF_MOV32_IMM(R0
, 1),
2891 /* BPF_ALU | BPF_SUB | BPF_X */
2893 "ALU_SUB_X: 3 - 1 = 2",
2895 BPF_LD_IMM64(R0
, 3),
2896 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2897 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2905 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2907 BPF_LD_IMM64(R0
, 4294967295U),
2908 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2909 BPF_ALU32_REG(BPF_SUB
, R0
, R1
),
2917 "ALU64_SUB_X: 3 - 1 = 2",
2919 BPF_LD_IMM64(R0
, 3),
2920 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
2921 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2929 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2931 BPF_LD_IMM64(R0
, 4294967295U),
2932 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967294U),
2933 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
2940 /* BPF_ALU | BPF_SUB | BPF_K */
2942 "ALU_SUB_K: 3 - 1 = 2",
2944 BPF_LD_IMM64(R0
, 3),
2945 BPF_ALU32_IMM(BPF_SUB
, R0
, 1),
2953 "ALU_SUB_K: 3 - 0 = 3",
2955 BPF_LD_IMM64(R0
, 3),
2956 BPF_ALU32_IMM(BPF_SUB
, R0
, 0),
2964 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2966 BPF_LD_IMM64(R0
, 4294967295U),
2967 BPF_ALU32_IMM(BPF_SUB
, R0
, 4294967294U),
2975 "ALU64_SUB_K: 3 - 1 = 2",
2977 BPF_LD_IMM64(R0
, 3),
2978 BPF_ALU64_IMM(BPF_SUB
, R0
, 1),
2986 "ALU64_SUB_K: 3 - 0 = 3",
2988 BPF_LD_IMM64(R0
, 3),
2989 BPF_ALU64_IMM(BPF_SUB
, R0
, 0),
2997 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2999 BPF_LD_IMM64(R0
, 4294967294U),
3000 BPF_ALU64_IMM(BPF_SUB
, R0
, 4294967295U),
3008 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3010 BPF_LD_IMM64(R0
, 2147483646),
3011 BPF_ALU64_IMM(BPF_SUB
, R0
, 2147483647),
3018 /* BPF_ALU | BPF_MUL | BPF_X */
3020 "ALU_MUL_X: 2 * 3 = 6",
3022 BPF_LD_IMM64(R0
, 2),
3023 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
3024 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3032 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3034 BPF_LD_IMM64(R0
, 2),
3035 BPF_ALU32_IMM(BPF_MOV
, R1
, 0x7FFFFFF8),
3036 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3041 { { 0, 0xFFFFFFF0 } },
3044 "ALU_MUL_X: -1 * -1 = 1",
3046 BPF_LD_IMM64(R0
, -1),
3047 BPF_ALU32_IMM(BPF_MOV
, R1
, -1),
3048 BPF_ALU32_REG(BPF_MUL
, R0
, R1
),
3056 "ALU64_MUL_X: 2 * 3 = 6",
3058 BPF_LD_IMM64(R0
, 2),
3059 BPF_ALU32_IMM(BPF_MOV
, R1
, 3),
3060 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
3068 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3070 BPF_LD_IMM64(R0
, 1),
3071 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3072 BPF_ALU64_REG(BPF_MUL
, R0
, R1
),
3077 { { 0, 2147483647 } },
3079 /* BPF_ALU | BPF_MUL | BPF_K */
3081 "ALU_MUL_K: 2 * 3 = 6",
3083 BPF_LD_IMM64(R0
, 2),
3084 BPF_ALU32_IMM(BPF_MUL
, R0
, 3),
3092 "ALU_MUL_K: 3 * 1 = 3",
3094 BPF_LD_IMM64(R0
, 3),
3095 BPF_ALU32_IMM(BPF_MUL
, R0
, 1),
3103 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3105 BPF_LD_IMM64(R0
, 2),
3106 BPF_ALU32_IMM(BPF_MUL
, R0
, 0x7FFFFFF8),
3111 { { 0, 0xFFFFFFF0 } },
3114 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3116 BPF_LD_IMM64(R2
, 0x1),
3117 BPF_LD_IMM64(R3
, 0x00000000ffffffff),
3118 BPF_ALU32_IMM(BPF_MUL
, R2
, 0xffffffff),
3119 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3120 BPF_MOV32_IMM(R0
, 2),
3122 BPF_MOV32_IMM(R0
, 1),
3130 "ALU64_MUL_K: 2 * 3 = 6",
3132 BPF_LD_IMM64(R0
, 2),
3133 BPF_ALU64_IMM(BPF_MUL
, R0
, 3),
3141 "ALU64_MUL_K: 3 * 1 = 3",
3143 BPF_LD_IMM64(R0
, 3),
3144 BPF_ALU64_IMM(BPF_MUL
, R0
, 1),
3152 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3154 BPF_LD_IMM64(R0
, 1),
3155 BPF_ALU64_IMM(BPF_MUL
, R0
, 2147483647),
3160 { { 0, 2147483647 } },
3163 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3165 BPF_LD_IMM64(R0
, 1),
3166 BPF_ALU64_IMM(BPF_MUL
, R0
, -2147483647),
3171 { { 0, -2147483647 } },
3174 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3176 BPF_LD_IMM64(R2
, 0x1),
3177 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3178 BPF_ALU64_IMM(BPF_MUL
, R2
, 0xffffffff),
3179 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3180 BPF_MOV32_IMM(R0
, 2),
3182 BPF_MOV32_IMM(R0
, 1),
3189 /* BPF_ALU | BPF_DIV | BPF_X */
3191 "ALU_DIV_X: 6 / 2 = 3",
3193 BPF_LD_IMM64(R0
, 6),
3194 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3195 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3203 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3205 BPF_LD_IMM64(R0
, 4294967295U),
3206 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967295U),
3207 BPF_ALU32_REG(BPF_DIV
, R0
, R1
),
3215 "ALU64_DIV_X: 6 / 2 = 3",
3217 BPF_LD_IMM64(R0
, 6),
3218 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3219 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3227 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3229 BPF_LD_IMM64(R0
, 2147483647),
3230 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483647),
3231 BPF_ALU64_REG(BPF_DIV
, R0
, R1
),
3239 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3241 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3242 BPF_LD_IMM64(R4
, 0xffffffffffffffffLL
),
3243 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3244 BPF_ALU64_REG(BPF_DIV
, R2
, R4
),
3245 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3246 BPF_MOV32_IMM(R0
, 2),
3248 BPF_MOV32_IMM(R0
, 1),
3255 /* BPF_ALU | BPF_DIV | BPF_K */
3257 "ALU_DIV_K: 6 / 2 = 3",
3259 BPF_LD_IMM64(R0
, 6),
3260 BPF_ALU32_IMM(BPF_DIV
, R0
, 2),
3268 "ALU_DIV_K: 3 / 1 = 3",
3270 BPF_LD_IMM64(R0
, 3),
3271 BPF_ALU32_IMM(BPF_DIV
, R0
, 1),
3279 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3281 BPF_LD_IMM64(R0
, 4294967295U),
3282 BPF_ALU32_IMM(BPF_DIV
, R0
, 4294967295U),
3290 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3292 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3293 BPF_LD_IMM64(R3
, 0x1UL
),
3294 BPF_ALU32_IMM(BPF_DIV
, R2
, 0xffffffff),
3295 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3296 BPF_MOV32_IMM(R0
, 2),
3298 BPF_MOV32_IMM(R0
, 1),
3306 "ALU64_DIV_K: 6 / 2 = 3",
3308 BPF_LD_IMM64(R0
, 6),
3309 BPF_ALU64_IMM(BPF_DIV
, R0
, 2),
3317 "ALU64_DIV_K: 3 / 1 = 3",
3319 BPF_LD_IMM64(R0
, 3),
3320 BPF_ALU64_IMM(BPF_DIV
, R0
, 1),
3328 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3330 BPF_LD_IMM64(R0
, 2147483647),
3331 BPF_ALU64_IMM(BPF_DIV
, R0
, 2147483647),
3339 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3341 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3342 BPF_LD_IMM64(R3
, 0x0000000000000001LL
),
3343 BPF_ALU64_IMM(BPF_DIV
, R2
, 0xffffffff),
3344 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3345 BPF_MOV32_IMM(R0
, 2),
3347 BPF_MOV32_IMM(R0
, 1),
3354 /* BPF_ALU | BPF_MOD | BPF_X */
3356 "ALU_MOD_X: 3 % 2 = 1",
3358 BPF_LD_IMM64(R0
, 3),
3359 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3360 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3368 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3370 BPF_LD_IMM64(R0
, 4294967295U),
3371 BPF_ALU32_IMM(BPF_MOV
, R1
, 4294967293U),
3372 BPF_ALU32_REG(BPF_MOD
, R0
, R1
),
3380 "ALU64_MOD_X: 3 % 2 = 1",
3382 BPF_LD_IMM64(R0
, 3),
3383 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3384 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3392 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3394 BPF_LD_IMM64(R0
, 2147483647),
3395 BPF_ALU32_IMM(BPF_MOV
, R1
, 2147483645),
3396 BPF_ALU64_REG(BPF_MOD
, R0
, R1
),
3403 /* BPF_ALU | BPF_MOD | BPF_K */
3405 "ALU_MOD_K: 3 % 2 = 1",
3407 BPF_LD_IMM64(R0
, 3),
3408 BPF_ALU32_IMM(BPF_MOD
, R0
, 2),
3416 "ALU_MOD_K: 3 % 1 = 0",
3418 BPF_LD_IMM64(R0
, 3),
3419 BPF_ALU32_IMM(BPF_MOD
, R0
, 1),
3427 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3429 BPF_LD_IMM64(R0
, 4294967295U),
3430 BPF_ALU32_IMM(BPF_MOD
, R0
, 4294967293U),
3438 "ALU64_MOD_K: 3 % 2 = 1",
3440 BPF_LD_IMM64(R0
, 3),
3441 BPF_ALU64_IMM(BPF_MOD
, R0
, 2),
3449 "ALU64_MOD_K: 3 % 1 = 0",
3451 BPF_LD_IMM64(R0
, 3),
3452 BPF_ALU64_IMM(BPF_MOD
, R0
, 1),
3460 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3462 BPF_LD_IMM64(R0
, 2147483647),
3463 BPF_ALU64_IMM(BPF_MOD
, R0
, 2147483645),
3470 /* BPF_ALU | BPF_AND | BPF_X */
3472 "ALU_AND_X: 3 & 2 = 2",
3474 BPF_LD_IMM64(R0
, 3),
3475 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3476 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3484 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3486 BPF_LD_IMM64(R0
, 0xffffffff),
3487 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3488 BPF_ALU32_REG(BPF_AND
, R0
, R1
),
3493 { { 0, 0xffffffff } },
3496 "ALU64_AND_X: 3 & 2 = 2",
3498 BPF_LD_IMM64(R0
, 3),
3499 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3500 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3508 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3510 BPF_LD_IMM64(R0
, 0xffffffff),
3511 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3512 BPF_ALU64_REG(BPF_AND
, R0
, R1
),
3517 { { 0, 0xffffffff } },
3519 /* BPF_ALU | BPF_AND | BPF_K */
3521 "ALU_AND_K: 3 & 2 = 2",
3523 BPF_LD_IMM64(R0
, 3),
3524 BPF_ALU32_IMM(BPF_AND
, R0
, 2),
3532 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3534 BPF_LD_IMM64(R0
, 0xffffffff),
3535 BPF_ALU32_IMM(BPF_AND
, R0
, 0xffffffff),
3540 { { 0, 0xffffffff } },
3543 "ALU64_AND_K: 3 & 2 = 2",
3545 BPF_LD_IMM64(R0
, 3),
3546 BPF_ALU64_IMM(BPF_AND
, R0
, 2),
3554 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3556 BPF_LD_IMM64(R0
, 0xffffffff),
3557 BPF_ALU64_IMM(BPF_AND
, R0
, 0xffffffff),
3562 { { 0, 0xffffffff } },
3565 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3567 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3568 BPF_LD_IMM64(R3
, 0x0000000000000000LL
),
3569 BPF_ALU64_IMM(BPF_AND
, R2
, 0x0),
3570 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3571 BPF_MOV32_IMM(R0
, 2),
3573 BPF_MOV32_IMM(R0
, 1),
3581 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3583 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3584 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3585 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3586 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3587 BPF_MOV32_IMM(R0
, 2),
3589 BPF_MOV32_IMM(R0
, 1),
3597 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3599 BPF_LD_IMM64(R2
, 0xffffffffffffffffLL
),
3600 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3601 BPF_ALU64_IMM(BPF_AND
, R2
, 0xffffffff),
3602 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3603 BPF_MOV32_IMM(R0
, 2),
3605 BPF_MOV32_IMM(R0
, 1),
3612 /* BPF_ALU | BPF_OR | BPF_X */
3614 "ALU_OR_X: 1 | 2 = 3",
3616 BPF_LD_IMM64(R0
, 1),
3617 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3618 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3626 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3628 BPF_LD_IMM64(R0
, 0),
3629 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3630 BPF_ALU32_REG(BPF_OR
, R0
, R1
),
3635 { { 0, 0xffffffff } },
3638 "ALU64_OR_X: 1 | 2 = 3",
3640 BPF_LD_IMM64(R0
, 1),
3641 BPF_ALU32_IMM(BPF_MOV
, R1
, 2),
3642 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3650 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3652 BPF_LD_IMM64(R0
, 0),
3653 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3654 BPF_ALU64_REG(BPF_OR
, R0
, R1
),
3659 { { 0, 0xffffffff } },
3661 /* BPF_ALU | BPF_OR | BPF_K */
3663 "ALU_OR_K: 1 | 2 = 3",
3665 BPF_LD_IMM64(R0
, 1),
3666 BPF_ALU32_IMM(BPF_OR
, R0
, 2),
3674 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3676 BPF_LD_IMM64(R0
, 0),
3677 BPF_ALU32_IMM(BPF_OR
, R0
, 0xffffffff),
3682 { { 0, 0xffffffff } },
3685 "ALU64_OR_K: 1 | 2 = 3",
3687 BPF_LD_IMM64(R0
, 1),
3688 BPF_ALU64_IMM(BPF_OR
, R0
, 2),
3696 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3698 BPF_LD_IMM64(R0
, 0),
3699 BPF_ALU64_IMM(BPF_OR
, R0
, 0xffffffff),
3704 { { 0, 0xffffffff } },
3707 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3709 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3710 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3711 BPF_ALU64_IMM(BPF_OR
, R2
, 0x0),
3712 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3713 BPF_MOV32_IMM(R0
, 2),
3715 BPF_MOV32_IMM(R0
, 1),
3723 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3725 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3726 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3727 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3728 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3729 BPF_MOV32_IMM(R0
, 2),
3731 BPF_MOV32_IMM(R0
, 1),
3739 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3741 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3742 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3743 BPF_ALU64_IMM(BPF_OR
, R2
, 0xffffffff),
3744 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3745 BPF_MOV32_IMM(R0
, 2),
3747 BPF_MOV32_IMM(R0
, 1),
3754 /* BPF_ALU | BPF_XOR | BPF_X */
3756 "ALU_XOR_X: 5 ^ 6 = 3",
3758 BPF_LD_IMM64(R0
, 5),
3759 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3760 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3768 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3770 BPF_LD_IMM64(R0
, 1),
3771 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3772 BPF_ALU32_REG(BPF_XOR
, R0
, R1
),
3777 { { 0, 0xfffffffe } },
3780 "ALU64_XOR_X: 5 ^ 6 = 3",
3782 BPF_LD_IMM64(R0
, 5),
3783 BPF_ALU32_IMM(BPF_MOV
, R1
, 6),
3784 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3792 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3794 BPF_LD_IMM64(R0
, 1),
3795 BPF_ALU32_IMM(BPF_MOV
, R1
, 0xffffffff),
3796 BPF_ALU64_REG(BPF_XOR
, R0
, R1
),
3801 { { 0, 0xfffffffe } },
3803 /* BPF_ALU | BPF_XOR | BPF_K */
3805 "ALU_XOR_K: 5 ^ 6 = 3",
3807 BPF_LD_IMM64(R0
, 5),
3808 BPF_ALU32_IMM(BPF_XOR
, R0
, 6),
3816 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3818 BPF_LD_IMM64(R0
, 1),
3819 BPF_ALU32_IMM(BPF_XOR
, R0
, 0xffffffff),
3824 { { 0, 0xfffffffe } },
3827 "ALU64_XOR_K: 5 ^ 6 = 3",
3829 BPF_LD_IMM64(R0
, 5),
3830 BPF_ALU64_IMM(BPF_XOR
, R0
, 6),
3838 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3840 BPF_LD_IMM64(R0
, 1),
3841 BPF_ALU64_IMM(BPF_XOR
, R0
, 0xffffffff),
3846 { { 0, 0xfffffffe } },
3849 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3851 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3852 BPF_LD_IMM64(R3
, 0x0000ffffffff0000LL
),
3853 BPF_ALU64_IMM(BPF_XOR
, R2
, 0x0),
3854 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3855 BPF_MOV32_IMM(R0
, 2),
3857 BPF_MOV32_IMM(R0
, 1),
3865 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3867 BPF_LD_IMM64(R2
, 0x0000ffffffff0000LL
),
3868 BPF_LD_IMM64(R3
, 0xffff00000000ffffLL
),
3869 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3870 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3871 BPF_MOV32_IMM(R0
, 2),
3873 BPF_MOV32_IMM(R0
, 1),
3881 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3883 BPF_LD_IMM64(R2
, 0x0000000000000000LL
),
3884 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
3885 BPF_ALU64_IMM(BPF_XOR
, R2
, 0xffffffff),
3886 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
3887 BPF_MOV32_IMM(R0
, 2),
3889 BPF_MOV32_IMM(R0
, 1),
3896 /* BPF_ALU | BPF_LSH | BPF_X */
3898 "ALU_LSH_X: 1 << 1 = 2",
3900 BPF_LD_IMM64(R0
, 1),
3901 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3902 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3910 "ALU_LSH_X: 1 << 31 = 0x80000000",
3912 BPF_LD_IMM64(R0
, 1),
3913 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3914 BPF_ALU32_REG(BPF_LSH
, R0
, R1
),
3919 { { 0, 0x80000000 } },
3922 "ALU64_LSH_X: 1 << 1 = 2",
3924 BPF_LD_IMM64(R0
, 1),
3925 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3926 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3934 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3936 BPF_LD_IMM64(R0
, 1),
3937 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
3938 BPF_ALU64_REG(BPF_LSH
, R0
, R1
),
3943 { { 0, 0x80000000 } },
3945 /* BPF_ALU | BPF_LSH | BPF_K */
3947 "ALU_LSH_K: 1 << 1 = 2",
3949 BPF_LD_IMM64(R0
, 1),
3950 BPF_ALU32_IMM(BPF_LSH
, R0
, 1),
3958 "ALU_LSH_K: 1 << 31 = 0x80000000",
3960 BPF_LD_IMM64(R0
, 1),
3961 BPF_ALU32_IMM(BPF_LSH
, R0
, 31),
3966 { { 0, 0x80000000 } },
3969 "ALU64_LSH_K: 1 << 1 = 2",
3971 BPF_LD_IMM64(R0
, 1),
3972 BPF_ALU64_IMM(BPF_LSH
, R0
, 1),
3980 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3982 BPF_LD_IMM64(R0
, 1),
3983 BPF_ALU64_IMM(BPF_LSH
, R0
, 31),
3988 { { 0, 0x80000000 } },
3990 /* BPF_ALU | BPF_RSH | BPF_X */
3992 "ALU_RSH_X: 2 >> 1 = 1",
3994 BPF_LD_IMM64(R0
, 2),
3995 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
3996 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
4004 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4006 BPF_LD_IMM64(R0
, 0x80000000),
4007 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
4008 BPF_ALU32_REG(BPF_RSH
, R0
, R1
),
4016 "ALU64_RSH_X: 2 >> 1 = 1",
4018 BPF_LD_IMM64(R0
, 2),
4019 BPF_ALU32_IMM(BPF_MOV
, R1
, 1),
4020 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
4028 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4030 BPF_LD_IMM64(R0
, 0x80000000),
4031 BPF_ALU32_IMM(BPF_MOV
, R1
, 31),
4032 BPF_ALU64_REG(BPF_RSH
, R0
, R1
),
4039 /* BPF_ALU | BPF_RSH | BPF_K */
4041 "ALU_RSH_K: 2 >> 1 = 1",
4043 BPF_LD_IMM64(R0
, 2),
4044 BPF_ALU32_IMM(BPF_RSH
, R0
, 1),
4052 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4054 BPF_LD_IMM64(R0
, 0x80000000),
4055 BPF_ALU32_IMM(BPF_RSH
, R0
, 31),
4063 "ALU64_RSH_K: 2 >> 1 = 1",
4065 BPF_LD_IMM64(R0
, 2),
4066 BPF_ALU64_IMM(BPF_RSH
, R0
, 1),
4074 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4076 BPF_LD_IMM64(R0
, 0x80000000),
4077 BPF_ALU64_IMM(BPF_RSH
, R0
, 31),
4084 /* BPF_ALU | BPF_ARSH | BPF_X */
4086 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4088 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4089 BPF_ALU32_IMM(BPF_MOV
, R1
, 40),
4090 BPF_ALU64_REG(BPF_ARSH
, R0
, R1
),
4095 { { 0, 0xffff00ff } },
4097 /* BPF_ALU | BPF_ARSH | BPF_K */
4099 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4101 BPF_LD_IMM64(R0
, 0xff00ff0000000000LL
),
4102 BPF_ALU64_IMM(BPF_ARSH
, R0
, 40),
4107 { { 0, 0xffff00ff } },
4109 /* BPF_ALU | BPF_NEG */
4111 "ALU_NEG: -(3) = -3",
4113 BPF_ALU32_IMM(BPF_MOV
, R0
, 3),
4114 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4122 "ALU_NEG: -(-3) = 3",
4124 BPF_ALU32_IMM(BPF_MOV
, R0
, -3),
4125 BPF_ALU32_IMM(BPF_NEG
, R0
, 0),
4133 "ALU64_NEG: -(3) = -3",
4135 BPF_LD_IMM64(R0
, 3),
4136 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4144 "ALU64_NEG: -(-3) = 3",
4146 BPF_LD_IMM64(R0
, -3),
4147 BPF_ALU64_IMM(BPF_NEG
, R0
, 0),
4154 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4156 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4158 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4159 BPF_ENDIAN(BPF_FROM_BE
, R0
, 16),
4164 { { 0, cpu_to_be16(0xcdef) } },
4167 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4169 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4170 BPF_ENDIAN(BPF_FROM_BE
, R0
, 32),
4171 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4172 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4173 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4178 { { 0, cpu_to_be32(0x89abcdef) } },
4181 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4183 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4184 BPF_ENDIAN(BPF_FROM_BE
, R0
, 64),
4189 { { 0, (u32
) cpu_to_be64(0x0123456789abcdefLL
) } },
4191 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4193 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4195 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4196 BPF_ENDIAN(BPF_FROM_LE
, R0
, 16),
4201 { { 0, cpu_to_le16(0xcdef) } },
4204 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4206 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4207 BPF_ENDIAN(BPF_FROM_LE
, R0
, 32),
4208 BPF_ALU64_REG(BPF_MOV
, R1
, R0
),
4209 BPF_ALU64_IMM(BPF_RSH
, R1
, 32),
4210 BPF_ALU32_REG(BPF_ADD
, R0
, R1
), /* R1 = 0 */
4215 { { 0, cpu_to_le32(0x89abcdef) } },
4218 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4220 BPF_LD_IMM64(R0
, 0x0123456789abcdefLL
),
4221 BPF_ENDIAN(BPF_FROM_LE
, R0
, 64),
4226 { { 0, (u32
) cpu_to_le64(0x0123456789abcdefLL
) } },
4228 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4230 "ST_MEM_B: Store/Load byte: max negative",
4232 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4233 BPF_ST_MEM(BPF_B
, R10
, -40, 0xff),
4234 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4243 "ST_MEM_B: Store/Load byte: max positive",
4245 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4246 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7f),
4247 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4256 "STX_MEM_B: Store/Load byte: max negative",
4258 BPF_LD_IMM64(R0
, 0),
4259 BPF_LD_IMM64(R1
, 0xffLL
),
4260 BPF_STX_MEM(BPF_B
, R10
, R1
, -40),
4261 BPF_LDX_MEM(BPF_B
, R0
, R10
, -40),
4270 "ST_MEM_H: Store/Load half word: max negative",
4272 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4273 BPF_ST_MEM(BPF_H
, R10
, -40, 0xffff),
4274 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4283 "ST_MEM_H: Store/Load half word: max positive",
4285 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4286 BPF_ST_MEM(BPF_H
, R10
, -40, 0x7fff),
4287 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4296 "STX_MEM_H: Store/Load half word: max negative",
4298 BPF_LD_IMM64(R0
, 0),
4299 BPF_LD_IMM64(R1
, 0xffffLL
),
4300 BPF_STX_MEM(BPF_H
, R10
, R1
, -40),
4301 BPF_LDX_MEM(BPF_H
, R0
, R10
, -40),
4310 "ST_MEM_W: Store/Load word: max negative",
4312 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4313 BPF_ST_MEM(BPF_W
, R10
, -40, 0xffffffff),
4314 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4319 { { 0, 0xffffffff } },
4323 "ST_MEM_W: Store/Load word: max positive",
4325 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4326 BPF_ST_MEM(BPF_W
, R10
, -40, 0x7fffffff),
4327 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4332 { { 0, 0x7fffffff } },
4336 "STX_MEM_W: Store/Load word: max negative",
4338 BPF_LD_IMM64(R0
, 0),
4339 BPF_LD_IMM64(R1
, 0xffffffffLL
),
4340 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4341 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4346 { { 0, 0xffffffff } },
4350 "ST_MEM_DW: Store/Load double word: max negative",
4352 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4353 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4354 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4359 { { 0, 0xffffffff } },
4363 "ST_MEM_DW: Store/Load double word: max negative 2",
4365 BPF_LD_IMM64(R2
, 0xffff00000000ffffLL
),
4366 BPF_LD_IMM64(R3
, 0xffffffffffffffffLL
),
4367 BPF_ST_MEM(BPF_DW
, R10
, -40, 0xffffffff),
4368 BPF_LDX_MEM(BPF_DW
, R2
, R10
, -40),
4369 BPF_JMP_REG(BPF_JEQ
, R2
, R3
, 2),
4370 BPF_MOV32_IMM(R0
, 2),
4372 BPF_MOV32_IMM(R0
, 1),
4381 "ST_MEM_DW: Store/Load double word: max positive",
4383 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4384 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x7fffffff),
4385 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4390 { { 0, 0x7fffffff } },
4394 "STX_MEM_DW: Store/Load double word: max negative",
4396 BPF_LD_IMM64(R0
, 0),
4397 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4398 BPF_STX_MEM(BPF_W
, R10
, R1
, -40),
4399 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4404 { { 0, 0xffffffff } },
4407 /* BPF_STX | BPF_XADD | BPF_W/DW */
4409 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4411 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4412 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4413 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4414 BPF_LDX_MEM(BPF_W
, R0
, R10
, -40),
4423 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4425 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4426 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4427 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4428 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4429 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4430 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4439 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4441 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4442 BPF_ST_MEM(BPF_W
, R10
, -40, 0x10),
4443 BPF_STX_XADD(BPF_W
, R10
, R0
, -40),
4452 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4457 .fill_helper
= bpf_fill_stxw
,
4460 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4462 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4463 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4464 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4465 BPF_LDX_MEM(BPF_DW
, R0
, R10
, -40),
4474 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4476 BPF_ALU64_REG(BPF_MOV
, R1
, R10
),
4477 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4478 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4479 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4480 BPF_ALU64_REG(BPF_MOV
, R0
, R10
),
4481 BPF_ALU64_REG(BPF_SUB
, R0
, R1
),
4490 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4492 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x12),
4493 BPF_ST_MEM(BPF_DW
, R10
, -40, 0x10),
4494 BPF_STX_XADD(BPF_DW
, R10
, R0
, -40),
4503 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4508 .fill_helper
= bpf_fill_stxdw
,
4510 /* BPF_JMP | BPF_EXIT */
4514 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4711),
4516 BPF_ALU32_IMM(BPF_MOV
, R0
, 0x4712),
4522 /* BPF_JMP | BPF_JA */
4524 "JMP_JA: Unconditional jump: if (true) return 1",
4526 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4527 BPF_JMP_IMM(BPF_JA
, 0, 0, 1),
4529 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4536 /* BPF_JMP | BPF_JSLT | BPF_K */
4538 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4540 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4541 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4542 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4544 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4552 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4554 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4555 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4556 BPF_JMP_IMM(BPF_JSLT
, R1
, -1, 1),
4558 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4565 /* BPF_JMP | BPF_JSGT | BPF_K */
4567 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4569 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4570 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4571 BPF_JMP_IMM(BPF_JSGT
, R1
, -2, 1),
4573 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4581 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4583 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4584 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4585 BPF_JMP_IMM(BPF_JSGT
, R1
, -1, 1),
4587 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4594 /* BPF_JMP | BPF_JSLE | BPF_K */
4596 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4598 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4599 BPF_LD_IMM64(R1
, 0xfffffffffffffffeLL
),
4600 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4602 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4610 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4612 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4613 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4614 BPF_JMP_IMM(BPF_JSLE
, R1
, -1, 1),
4616 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4624 "JMP_JSLE_K: Signed jump: value walk 1",
4626 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4627 BPF_LD_IMM64(R1
, 3),
4628 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 6),
4629 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4630 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4631 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4632 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4633 BPF_ALU64_IMM(BPF_SUB
, R1
, 1),
4634 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4635 BPF_EXIT_INSN(), /* bad exit */
4636 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4644 "JMP_JSLE_K: Signed jump: value walk 2",
4646 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4647 BPF_LD_IMM64(R1
, 3),
4648 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 4),
4649 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4650 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 2),
4651 BPF_ALU64_IMM(BPF_SUB
, R1
, 2),
4652 BPF_JMP_IMM(BPF_JSLE
, R1
, 0, 1),
4653 BPF_EXIT_INSN(), /* bad exit */
4654 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4661 /* BPF_JMP | BPF_JSGE | BPF_K */
4663 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4665 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4666 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4667 BPF_JMP_IMM(BPF_JSGE
, R1
, -2, 1),
4669 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4677 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4679 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4680 BPF_LD_IMM64(R1
, 0xffffffffffffffffLL
),
4681 BPF_JMP_IMM(BPF_JSGE
, R1
, -1, 1),
4683 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4691 "JMP_JSGE_K: Signed jump: value walk 1",
4693 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4694 BPF_LD_IMM64(R1
, -3),
4695 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 6),
4696 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4697 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4698 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4699 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4700 BPF_ALU64_IMM(BPF_ADD
, R1
, 1),
4701 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4702 BPF_EXIT_INSN(), /* bad exit */
4703 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4711 "JMP_JSGE_K: Signed jump: value walk 2",
4713 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4714 BPF_LD_IMM64(R1
, -3),
4715 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 4),
4716 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4717 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 2),
4718 BPF_ALU64_IMM(BPF_ADD
, R1
, 2),
4719 BPF_JMP_IMM(BPF_JSGE
, R1
, 0, 1),
4720 BPF_EXIT_INSN(), /* bad exit */
4721 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* good exit */
4728 /* BPF_JMP | BPF_JGT | BPF_K */
4730 "JMP_JGT_K: if (3 > 2) return 1",
4732 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4733 BPF_LD_IMM64(R1
, 3),
4734 BPF_JMP_IMM(BPF_JGT
, R1
, 2, 1),
4736 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4744 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4746 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4747 BPF_LD_IMM64(R1
, -1),
4748 BPF_JMP_IMM(BPF_JGT
, R1
, 1, 1),
4750 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4757 /* BPF_JMP | BPF_JLT | BPF_K */
4759 "JMP_JLT_K: if (2 < 3) return 1",
4761 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4762 BPF_LD_IMM64(R1
, 2),
4763 BPF_JMP_IMM(BPF_JLT
, R1
, 3, 1),
4765 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4773 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4775 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4776 BPF_LD_IMM64(R1
, 1),
4777 BPF_JMP_IMM(BPF_JLT
, R1
, -1, 1),
4779 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4786 /* BPF_JMP | BPF_JGE | BPF_K */
4788 "JMP_JGE_K: if (3 >= 2) return 1",
4790 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4791 BPF_LD_IMM64(R1
, 3),
4792 BPF_JMP_IMM(BPF_JGE
, R1
, 2, 1),
4794 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4801 /* BPF_JMP | BPF_JLE | BPF_K */
4803 "JMP_JLE_K: if (2 <= 3) return 1",
4805 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4806 BPF_LD_IMM64(R1
, 2),
4807 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4809 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4816 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4818 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4820 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4821 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4823 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4824 BPF_LD_IMM64(R1
, 3), /* note: this takes 2 insns */
4825 BPF_JMP_IMM(BPF_JGT
, R1
, 2, -6), /* goto out */
4833 "JMP_JGE_K: if (3 >= 3) return 1",
4835 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4836 BPF_LD_IMM64(R1
, 3),
4837 BPF_JMP_IMM(BPF_JGE
, R1
, 3, 1),
4839 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4846 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4848 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4850 BPF_JMP_IMM(BPF_JA
, 0, 0, 2), /* goto start */
4851 BPF_ALU32_IMM(BPF_MOV
, R0
, 1), /* out: */
4853 BPF_ALU32_IMM(BPF_MOV
, R0
, 0), /* start: */
4854 BPF_LD_IMM64(R1
, 2), /* note: this takes 2 insns */
4855 BPF_JMP_IMM(BPF_JLT
, R1
, 3, -6), /* goto out */
4863 "JMP_JLE_K: if (3 <= 3) return 1",
4865 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4866 BPF_LD_IMM64(R1
, 3),
4867 BPF_JMP_IMM(BPF_JLE
, R1
, 3, 1),
4869 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4876 /* BPF_JMP | BPF_JNE | BPF_K */
4878 "JMP_JNE_K: if (3 != 2) return 1",
4880 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4881 BPF_LD_IMM64(R1
, 3),
4882 BPF_JMP_IMM(BPF_JNE
, R1
, 2, 1),
4884 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4891 /* BPF_JMP | BPF_JEQ | BPF_K */
4893 "JMP_JEQ_K: if (3 == 3) return 1",
4895 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4896 BPF_LD_IMM64(R1
, 3),
4897 BPF_JMP_IMM(BPF_JEQ
, R1
, 3, 1),
4899 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4906 /* BPF_JMP | BPF_JSET | BPF_K */
4908 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4910 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4911 BPF_LD_IMM64(R1
, 3),
4912 BPF_JMP_IMM(BPF_JSET
, R1
, 2, 1),
4914 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4922 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4924 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4925 BPF_LD_IMM64(R1
, 3),
4926 BPF_JMP_IMM(BPF_JSET
, R1
, 0xffffffff, 1),
4928 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4935 /* BPF_JMP | BPF_JSGT | BPF_X */
4937 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4939 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4940 BPF_LD_IMM64(R1
, -1),
4941 BPF_LD_IMM64(R2
, -2),
4942 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4944 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4952 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4954 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4955 BPF_LD_IMM64(R1
, -1),
4956 BPF_LD_IMM64(R2
, -1),
4957 BPF_JMP_REG(BPF_JSGT
, R1
, R2
, 1),
4959 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4966 /* BPF_JMP | BPF_JSLT | BPF_X */
4968 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
4970 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4971 BPF_LD_IMM64(R1
, -1),
4972 BPF_LD_IMM64(R2
, -2),
4973 BPF_JMP_REG(BPF_JSLT
, R2
, R1
, 1),
4975 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4983 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
4985 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
4986 BPF_LD_IMM64(R1
, -1),
4987 BPF_LD_IMM64(R2
, -1),
4988 BPF_JMP_REG(BPF_JSLT
, R1
, R2
, 1),
4990 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
4997 /* BPF_JMP | BPF_JSGE | BPF_X */
4999 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
5001 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5002 BPF_LD_IMM64(R1
, -1),
5003 BPF_LD_IMM64(R2
, -2),
5004 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
5006 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5014 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
5016 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5017 BPF_LD_IMM64(R1
, -1),
5018 BPF_LD_IMM64(R2
, -1),
5019 BPF_JMP_REG(BPF_JSGE
, R1
, R2
, 1),
5021 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5028 /* BPF_JMP | BPF_JSLE | BPF_X */
5030 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
5032 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5033 BPF_LD_IMM64(R1
, -1),
5034 BPF_LD_IMM64(R2
, -2),
5035 BPF_JMP_REG(BPF_JSLE
, R2
, R1
, 1),
5037 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5045 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
5047 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5048 BPF_LD_IMM64(R1
, -1),
5049 BPF_LD_IMM64(R2
, -1),
5050 BPF_JMP_REG(BPF_JSLE
, R1
, R2
, 1),
5052 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5059 /* BPF_JMP | BPF_JGT | BPF_X */
5061 "JMP_JGT_X: if (3 > 2) return 1",
5063 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5064 BPF_LD_IMM64(R1
, 3),
5065 BPF_LD_IMM64(R2
, 2),
5066 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
5068 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5076 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
5078 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5079 BPF_LD_IMM64(R1
, -1),
5080 BPF_LD_IMM64(R2
, 1),
5081 BPF_JMP_REG(BPF_JGT
, R1
, R2
, 1),
5083 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5090 /* BPF_JMP | BPF_JLT | BPF_X */
5092 "JMP_JLT_X: if (2 < 3) return 1",
5094 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5095 BPF_LD_IMM64(R1
, 3),
5096 BPF_LD_IMM64(R2
, 2),
5097 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5099 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5107 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5109 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5110 BPF_LD_IMM64(R1
, -1),
5111 BPF_LD_IMM64(R2
, 1),
5112 BPF_JMP_REG(BPF_JLT
, R2
, R1
, 1),
5114 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5121 /* BPF_JMP | BPF_JGE | BPF_X */
5123 "JMP_JGE_X: if (3 >= 2) return 1",
5125 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5126 BPF_LD_IMM64(R1
, 3),
5127 BPF_LD_IMM64(R2
, 2),
5128 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5130 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5138 "JMP_JGE_X: if (3 >= 3) return 1",
5140 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5141 BPF_LD_IMM64(R1
, 3),
5142 BPF_LD_IMM64(R2
, 3),
5143 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 1),
5145 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5152 /* BPF_JMP | BPF_JLE | BPF_X */
5154 "JMP_JLE_X: if (2 <= 3) return 1",
5156 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5157 BPF_LD_IMM64(R1
, 3),
5158 BPF_LD_IMM64(R2
, 2),
5159 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 1),
5161 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5169 "JMP_JLE_X: if (3 <= 3) return 1",
5171 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5172 BPF_LD_IMM64(R1
, 3),
5173 BPF_LD_IMM64(R2
, 3),
5174 BPF_JMP_REG(BPF_JLE
, R1
, R2
, 1),
5176 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5184 /* Mainly testing JIT + imm64 here. */
5185 "JMP_JGE_X: ldimm64 test 1",
5187 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5188 BPF_LD_IMM64(R1
, 3),
5189 BPF_LD_IMM64(R2
, 2),
5190 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 2),
5191 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5192 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5197 { { 0, 0xeeeeeeeeU
} },
5200 "JMP_JGE_X: ldimm64 test 2",
5202 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5203 BPF_LD_IMM64(R1
, 3),
5204 BPF_LD_IMM64(R2
, 2),
5205 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 0),
5206 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5211 { { 0, 0xffffffffU
} },
5214 "JMP_JGE_X: ldimm64 test 3",
5216 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5217 BPF_LD_IMM64(R1
, 3),
5218 BPF_LD_IMM64(R2
, 2),
5219 BPF_JMP_REG(BPF_JGE
, R1
, R2
, 4),
5220 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5221 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5229 "JMP_JLE_X: ldimm64 test 1",
5231 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5232 BPF_LD_IMM64(R1
, 3),
5233 BPF_LD_IMM64(R2
, 2),
5234 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 2),
5235 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5236 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5241 { { 0, 0xeeeeeeeeU
} },
5244 "JMP_JLE_X: ldimm64 test 2",
5246 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5247 BPF_LD_IMM64(R1
, 3),
5248 BPF_LD_IMM64(R2
, 2),
5249 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 0),
5250 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5255 { { 0, 0xffffffffU
} },
5258 "JMP_JLE_X: ldimm64 test 3",
5260 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5261 BPF_LD_IMM64(R1
, 3),
5262 BPF_LD_IMM64(R2
, 2),
5263 BPF_JMP_REG(BPF_JLE
, R2
, R1
, 4),
5264 BPF_LD_IMM64(R0
, 0xffffffffffffffffULL
),
5265 BPF_LD_IMM64(R0
, 0xeeeeeeeeeeeeeeeeULL
),
5272 /* BPF_JMP | BPF_JNE | BPF_X */
5274 "JMP_JNE_X: if (3 != 2) return 1",
5276 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5277 BPF_LD_IMM64(R1
, 3),
5278 BPF_LD_IMM64(R2
, 2),
5279 BPF_JMP_REG(BPF_JNE
, R1
, R2
, 1),
5281 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5288 /* BPF_JMP | BPF_JEQ | BPF_X */
5290 "JMP_JEQ_X: if (3 == 3) return 1",
5292 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5293 BPF_LD_IMM64(R1
, 3),
5294 BPF_LD_IMM64(R2
, 3),
5295 BPF_JMP_REG(BPF_JEQ
, R1
, R2
, 1),
5297 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5304 /* BPF_JMP | BPF_JSET | BPF_X */
5306 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5308 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5309 BPF_LD_IMM64(R1
, 3),
5310 BPF_LD_IMM64(R2
, 2),
5311 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5313 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5321 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5323 BPF_ALU32_IMM(BPF_MOV
, R0
, 0),
5324 BPF_LD_IMM64(R1
, 3),
5325 BPF_LD_IMM64(R2
, 0xffffffff),
5326 BPF_JMP_REG(BPF_JSET
, R1
, R2
, 1),
5328 BPF_ALU32_IMM(BPF_MOV
, R0
, 1),
5336 "JMP_JA: Jump, gap, jump, ...",
5338 CLASSIC
| FLAG_NO_DATA
,
5340 { { 0, 0xababcbac } },
5341 .fill_helper
= bpf_fill_ja
,
5343 { /* Mainly checking JIT here. */
5344 "BPF_MAXINSNS: Maximum possible literals",
5346 CLASSIC
| FLAG_NO_DATA
,
5348 { { 0, 0xffffffff } },
5349 .fill_helper
= bpf_fill_maxinsns1
,
5351 { /* Mainly checking JIT here. */
5352 "BPF_MAXINSNS: Single literal",
5354 CLASSIC
| FLAG_NO_DATA
,
5356 { { 0, 0xfefefefe } },
5357 .fill_helper
= bpf_fill_maxinsns2
,
5359 { /* Mainly checking JIT here. */
5360 "BPF_MAXINSNS: Run/add until end",
5362 CLASSIC
| FLAG_NO_DATA
,
5364 { { 0, 0x947bf368 } },
5365 .fill_helper
= bpf_fill_maxinsns3
,
5368 "BPF_MAXINSNS: Too many instructions",
5370 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5373 .fill_helper
= bpf_fill_maxinsns4
,
5374 .expected_errcode
= -EINVAL
,
5376 { /* Mainly checking JIT here. */
5377 "BPF_MAXINSNS: Very long jump",
5379 CLASSIC
| FLAG_NO_DATA
,
5381 { { 0, 0xabababab } },
5382 .fill_helper
= bpf_fill_maxinsns5
,
5384 { /* Mainly checking JIT here. */
5385 "BPF_MAXINSNS: Ctx heavy transformations",
5390 { 1, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) },
5391 { 10, !!(SKB_VLAN_TCI
& VLAN_TAG_PRESENT
) }
5393 .fill_helper
= bpf_fill_maxinsns6
,
5395 { /* Mainly checking JIT here. */
5396 "BPF_MAXINSNS: Call heavy transformations",
5398 CLASSIC
| FLAG_NO_DATA
,
5400 { { 1, 0 }, { 10, 0 } },
5401 .fill_helper
= bpf_fill_maxinsns7
,
5403 { /* Mainly checking JIT here. */
5404 "BPF_MAXINSNS: Jump heavy test",
5406 CLASSIC
| FLAG_NO_DATA
,
5408 { { 0, 0xffffffff } },
5409 .fill_helper
= bpf_fill_maxinsns8
,
5411 { /* Mainly checking JIT here. */
5412 "BPF_MAXINSNS: Very long jump backwards",
5414 INTERNAL
| FLAG_NO_DATA
,
5416 { { 0, 0xcbababab } },
5417 .fill_helper
= bpf_fill_maxinsns9
,
5419 { /* Mainly checking JIT here. */
5420 "BPF_MAXINSNS: Edge hopping nuthouse",
5422 INTERNAL
| FLAG_NO_DATA
,
5424 { { 0, 0xabababac } },
5425 .fill_helper
= bpf_fill_maxinsns10
,
5428 "BPF_MAXINSNS: Jump, gap, jump, ...",
5430 #ifdef CONFIG_BPF_JIT_ALWAYS_ON
5431 CLASSIC
| FLAG_NO_DATA
| FLAG_EXPECTED_FAIL
,
5433 CLASSIC
| FLAG_NO_DATA
,
5436 { { 0, 0xababcbac } },
5437 .fill_helper
= bpf_fill_maxinsns11
,
5438 .expected_errcode
= -ENOTSUPP
,
5441 "BPF_MAXINSNS: ld_abs+get_processor_id",
5446 .fill_helper
= bpf_fill_ld_abs_get_processor_id
,
5449 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
5453 { { ETH_HLEN
, 0xbef } },
5454 .fill_helper
= bpf_fill_ld_abs_vlan_push_pop
,
5457 "BPF_MAXINSNS: jump around ld_abs",
5462 .fill_helper
= bpf_fill_jump_around_ld_abs
,
5465 * LD_IND / LD_ABS on fragmented SKBs
5470 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5471 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x0),
5472 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5474 CLASSIC
| FLAG_SKB_FRAG
,
5478 0x42, 0x00, 0x00, 0x00,
5479 0x43, 0x44, 0x00, 0x00,
5480 0x21, 0x07, 0x19, 0x83,
5484 "LD_IND halfword frag",
5486 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5487 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x4),
5488 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5490 CLASSIC
| FLAG_SKB_FRAG
,
5494 0x42, 0x00, 0x00, 0x00,
5495 0x43, 0x44, 0x00, 0x00,
5496 0x21, 0x07, 0x19, 0x83,
5502 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5503 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x8),
5504 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5506 CLASSIC
| FLAG_SKB_FRAG
,
5508 { {0x40, 0x21071983} },
5510 0x42, 0x00, 0x00, 0x00,
5511 0x43, 0x44, 0x00, 0x00,
5512 0x21, 0x07, 0x19, 0x83,
5516 "LD_IND halfword mixed head/frag",
5518 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5519 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5520 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5522 CLASSIC
| FLAG_SKB_FRAG
,
5523 { [0x3e] = 0x25, [0x3f] = 0x05, },
5525 .frag_data
= { 0x19, 0x82 },
5528 "LD_IND word mixed head/frag",
5530 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x40),
5531 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5532 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5534 CLASSIC
| FLAG_SKB_FRAG
,
5535 { [0x3e] = 0x25, [0x3f] = 0x05, },
5536 { {0x40, 0x25051982} },
5537 .frag_data
= { 0x19, 0x82 },
5542 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x40),
5543 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5545 CLASSIC
| FLAG_SKB_FRAG
,
5549 0x42, 0x00, 0x00, 0x00,
5550 0x43, 0x44, 0x00, 0x00,
5551 0x21, 0x07, 0x19, 0x83,
5555 "LD_ABS halfword frag",
5557 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x44),
5558 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5560 CLASSIC
| FLAG_SKB_FRAG
,
5564 0x42, 0x00, 0x00, 0x00,
5565 0x43, 0x44, 0x00, 0x00,
5566 0x21, 0x07, 0x19, 0x83,
5572 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x48),
5573 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5575 CLASSIC
| FLAG_SKB_FRAG
,
5577 { {0x40, 0x21071983} },
5579 0x42, 0x00, 0x00, 0x00,
5580 0x43, 0x44, 0x00, 0x00,
5581 0x21, 0x07, 0x19, 0x83,
5585 "LD_ABS halfword mixed head/frag",
5587 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x3f),
5588 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5590 CLASSIC
| FLAG_SKB_FRAG
,
5591 { [0x3e] = 0x25, [0x3f] = 0x05, },
5593 .frag_data
= { 0x19, 0x82 },
5596 "LD_ABS word mixed head/frag",
5598 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x3e),
5599 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5601 CLASSIC
| FLAG_SKB_FRAG
,
5602 { [0x3e] = 0x25, [0x3f] = 0x05, },
5603 { {0x40, 0x25051982} },
5604 .frag_data
= { 0x19, 0x82 },
5607 * LD_IND / LD_ABS on non fragmented SKBs
5611 * this tests that the JIT/interpreter correctly resets X
5612 * before using it in an LD_IND instruction.
5614 "LD_IND byte default X",
5616 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5617 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5624 "LD_IND byte positive offset",
5626 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5627 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, 0x1),
5628 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5631 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5635 "LD_IND byte negative offset",
5637 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x3e),
5638 BPF_STMT(BPF_LD
| BPF_IND
| BPF_B
, -0x1),
5639 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5642 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5646 "LD_IND halfword positive offset",
5648 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5649 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, 0x2),
5650 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5654 [0x1c] = 0xaa, [0x1d] = 0x55,
5655 [0x1e] = 0xbb, [0x1f] = 0x66,
5656 [0x20] = 0xcc, [0x21] = 0x77,
5657 [0x22] = 0xdd, [0x23] = 0x88,
5659 { {0x40, 0xdd88 } },
5662 "LD_IND halfword negative offset",
5664 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5665 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x2),
5666 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5670 [0x1c] = 0xaa, [0x1d] = 0x55,
5671 [0x1e] = 0xbb, [0x1f] = 0x66,
5672 [0x20] = 0xcc, [0x21] = 0x77,
5673 [0x22] = 0xdd, [0x23] = 0x88,
5675 { {0x40, 0xbb66 } },
5678 "LD_IND halfword unaligned",
5680 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5681 BPF_STMT(BPF_LD
| BPF_IND
| BPF_H
, -0x1),
5682 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5686 [0x1c] = 0xaa, [0x1d] = 0x55,
5687 [0x1e] = 0xbb, [0x1f] = 0x66,
5688 [0x20] = 0xcc, [0x21] = 0x77,
5689 [0x22] = 0xdd, [0x23] = 0x88,
5691 { {0x40, 0x66cc } },
5694 "LD_IND word positive offset",
5696 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5697 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, 0x4),
5698 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5702 [0x1c] = 0xaa, [0x1d] = 0x55,
5703 [0x1e] = 0xbb, [0x1f] = 0x66,
5704 [0x20] = 0xcc, [0x21] = 0x77,
5705 [0x22] = 0xdd, [0x23] = 0x88,
5706 [0x24] = 0xee, [0x25] = 0x99,
5707 [0x26] = 0xff, [0x27] = 0xaa,
5709 { {0x40, 0xee99ffaa } },
5712 "LD_IND word negative offset",
5714 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5715 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x4),
5716 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5720 [0x1c] = 0xaa, [0x1d] = 0x55,
5721 [0x1e] = 0xbb, [0x1f] = 0x66,
5722 [0x20] = 0xcc, [0x21] = 0x77,
5723 [0x22] = 0xdd, [0x23] = 0x88,
5724 [0x24] = 0xee, [0x25] = 0x99,
5725 [0x26] = 0xff, [0x27] = 0xaa,
5727 { {0x40, 0xaa55bb66 } },
5730 "LD_IND word unaligned (addr & 3 == 2)",
5732 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5733 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x2),
5734 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5738 [0x1c] = 0xaa, [0x1d] = 0x55,
5739 [0x1e] = 0xbb, [0x1f] = 0x66,
5740 [0x20] = 0xcc, [0x21] = 0x77,
5741 [0x22] = 0xdd, [0x23] = 0x88,
5742 [0x24] = 0xee, [0x25] = 0x99,
5743 [0x26] = 0xff, [0x27] = 0xaa,
5745 { {0x40, 0xbb66cc77 } },
5748 "LD_IND word unaligned (addr & 3 == 1)",
5750 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5751 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x3),
5752 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5756 [0x1c] = 0xaa, [0x1d] = 0x55,
5757 [0x1e] = 0xbb, [0x1f] = 0x66,
5758 [0x20] = 0xcc, [0x21] = 0x77,
5759 [0x22] = 0xdd, [0x23] = 0x88,
5760 [0x24] = 0xee, [0x25] = 0x99,
5761 [0x26] = 0xff, [0x27] = 0xaa,
5763 { {0x40, 0x55bb66cc } },
5766 "LD_IND word unaligned (addr & 3 == 3)",
5768 BPF_STMT(BPF_LDX
| BPF_IMM
, 0x20),
5769 BPF_STMT(BPF_LD
| BPF_IND
| BPF_W
, -0x1),
5770 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5774 [0x1c] = 0xaa, [0x1d] = 0x55,
5775 [0x1e] = 0xbb, [0x1f] = 0x66,
5776 [0x20] = 0xcc, [0x21] = 0x77,
5777 [0x22] = 0xdd, [0x23] = 0x88,
5778 [0x24] = 0xee, [0x25] = 0x99,
5779 [0x26] = 0xff, [0x27] = 0xaa,
5781 { {0x40, 0x66cc77dd } },
5786 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_B
, 0x20),
5787 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5791 [0x1c] = 0xaa, [0x1d] = 0x55,
5792 [0x1e] = 0xbb, [0x1f] = 0x66,
5793 [0x20] = 0xcc, [0x21] = 0x77,
5794 [0x22] = 0xdd, [0x23] = 0x88,
5795 [0x24] = 0xee, [0x25] = 0x99,
5796 [0x26] = 0xff, [0x27] = 0xaa,
5803 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x22),
5804 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5808 [0x1c] = 0xaa, [0x1d] = 0x55,
5809 [0x1e] = 0xbb, [0x1f] = 0x66,
5810 [0x20] = 0xcc, [0x21] = 0x77,
5811 [0x22] = 0xdd, [0x23] = 0x88,
5812 [0x24] = 0xee, [0x25] = 0x99,
5813 [0x26] = 0xff, [0x27] = 0xaa,
5815 { {0x40, 0xdd88 } },
5818 "LD_ABS halfword unaligned",
5820 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_H
, 0x25),
5821 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5825 [0x1c] = 0xaa, [0x1d] = 0x55,
5826 [0x1e] = 0xbb, [0x1f] = 0x66,
5827 [0x20] = 0xcc, [0x21] = 0x77,
5828 [0x22] = 0xdd, [0x23] = 0x88,
5829 [0x24] = 0xee, [0x25] = 0x99,
5830 [0x26] = 0xff, [0x27] = 0xaa,
5832 { {0x40, 0x99ff } },
5837 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x1c),
5838 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5842 [0x1c] = 0xaa, [0x1d] = 0x55,
5843 [0x1e] = 0xbb, [0x1f] = 0x66,
5844 [0x20] = 0xcc, [0x21] = 0x77,
5845 [0x22] = 0xdd, [0x23] = 0x88,
5846 [0x24] = 0xee, [0x25] = 0x99,
5847 [0x26] = 0xff, [0x27] = 0xaa,
5849 { {0x40, 0xaa55bb66 } },
5852 "LD_ABS word unaligned (addr & 3 == 2)",
5854 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x22),
5855 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5859 [0x1c] = 0xaa, [0x1d] = 0x55,
5860 [0x1e] = 0xbb, [0x1f] = 0x66,
5861 [0x20] = 0xcc, [0x21] = 0x77,
5862 [0x22] = 0xdd, [0x23] = 0x88,
5863 [0x24] = 0xee, [0x25] = 0x99,
5864 [0x26] = 0xff, [0x27] = 0xaa,
5866 { {0x40, 0xdd88ee99 } },
5869 "LD_ABS word unaligned (addr & 3 == 1)",
5871 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x21),
5872 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5876 [0x1c] = 0xaa, [0x1d] = 0x55,
5877 [0x1e] = 0xbb, [0x1f] = 0x66,
5878 [0x20] = 0xcc, [0x21] = 0x77,
5879 [0x22] = 0xdd, [0x23] = 0x88,
5880 [0x24] = 0xee, [0x25] = 0x99,
5881 [0x26] = 0xff, [0x27] = 0xaa,
5883 { {0x40, 0x77dd88ee } },
5886 "LD_ABS word unaligned (addr & 3 == 3)",
5888 BPF_STMT(BPF_LD
| BPF_ABS
| BPF_W
, 0x23),
5889 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5893 [0x1c] = 0xaa, [0x1d] = 0x55,
5894 [0x1e] = 0xbb, [0x1f] = 0x66,
5895 [0x20] = 0xcc, [0x21] = 0x77,
5896 [0x22] = 0xdd, [0x23] = 0x88,
5897 [0x24] = 0xee, [0x25] = 0x99,
5898 [0x26] = 0xff, [0x27] = 0xaa,
5900 { {0x40, 0x88ee99ff } },
5903 * verify that the interpreter or JIT correctly sets A and X
5914 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
5915 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
5916 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5918 CLASSIC
| FLAG_NO_DATA
,
5929 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 0x42),
5930 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5932 CLASSIC
| FLAG_NO_DATA
,
5944 BPF_STMT(BPF_LD
| BPF_IMM
, 0x66),
5945 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_X
, 0),
5946 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5948 CLASSIC
| FLAG_NO_DATA
,
5959 BPF_STMT(BPF_ALU
| BPF_SUB
| BPF_K
, -0x66),
5960 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5962 CLASSIC
| FLAG_NO_DATA
,
5974 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
5975 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_X
, 0),
5976 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5978 CLASSIC
| FLAG_NO_DATA
,
5989 BPF_STMT(BPF_ALU
| BPF_MUL
| BPF_K
, 0x66),
5990 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
5992 CLASSIC
| FLAG_NO_DATA
,
6001 * A = A / X ; this halt the filter execution if X is 0
6004 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6005 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_X
, 0),
6006 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6008 CLASSIC
| FLAG_NO_DATA
,
6019 BPF_STMT(BPF_ALU
| BPF_DIV
| BPF_K
, 0x1),
6020 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6022 CLASSIC
| FLAG_NO_DATA
,
6031 * A = A mod X ; this halt the filter execution if X is 0
6034 BPF_STMT(BPF_LD
| BPF_IMM
, 0x42),
6035 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_X
, 0),
6036 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6038 CLASSIC
| FLAG_NO_DATA
,
6049 BPF_STMT(BPF_ALU
| BPF_MOD
| BPF_K
, 0x1),
6050 BPF_STMT(BPF_RET
| BPF_A
, 0x0),
6052 CLASSIC
| FLAG_NO_DATA
,
6064 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0, 0, 1),
6065 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6066 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6068 CLASSIC
| FLAG_NO_DATA
,
6081 BPF_STMT(BPF_LD
| BPF_IMM
, 0x0),
6082 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0x0, 0, 1),
6083 BPF_STMT(BPF_RET
| BPF_K
, 0x42),
6084 BPF_STMT(BPF_RET
| BPF_K
, 0x66),
6086 CLASSIC
| FLAG_NO_DATA
,
6092 static struct net_device dev
;
6094 static struct sk_buff
*populate_skb(char *buf
, int size
)
6096 struct sk_buff
*skb
;
6098 if (size
>= MAX_DATA
)
6101 skb
= alloc_skb(MAX_DATA
, GFP_KERNEL
);
6105 __skb_put_data(skb
, buf
, size
);
6107 /* Initialize a fake skb with test pattern. */
6108 skb_reset_mac_header(skb
);
6109 skb
->protocol
= htons(ETH_P_IP
);
6110 skb
->pkt_type
= SKB_TYPE
;
6111 skb
->mark
= SKB_MARK
;
6112 skb
->hash
= SKB_HASH
;
6113 skb
->queue_mapping
= SKB_QUEUE_MAP
;
6114 skb
->vlan_tci
= SKB_VLAN_TCI
;
6115 skb
->vlan_proto
= htons(ETH_P_IP
);
6117 skb
->dev
->ifindex
= SKB_DEV_IFINDEX
;
6118 skb
->dev
->type
= SKB_DEV_TYPE
;
6119 skb_set_network_header(skb
, min(size
, ETH_HLEN
));
6124 static void *generate_test_data(struct bpf_test
*test
, int sub
)
6126 struct sk_buff
*skb
;
6129 if (test
->aux
& FLAG_NO_DATA
)
6132 /* Test case expects an skb, so populate one. Various
6133 * subtests generate skbs of different sizes based on
6136 skb
= populate_skb(test
->data
, test
->test
[sub
].data_size
);
6140 if (test
->aux
& FLAG_SKB_FRAG
) {
6142 * when the test requires a fragmented skb, add a
6143 * single fragment to the skb, filled with
6148 page
= alloc_page(GFP_KERNEL
);
6156 memcpy(ptr
, test
->frag_data
, MAX_DATA
);
6158 skb_add_rx_frag(skb
, 0, page
, 0, MAX_DATA
, MAX_DATA
);
6170 static void release_test_data(const struct bpf_test
*test
, void *data
)
6172 if (test
->aux
& FLAG_NO_DATA
)
6178 static int filter_length(int which
)
6180 struct sock_filter
*fp
;
6183 if (tests
[which
].fill_helper
)
6184 return tests
[which
].u
.ptr
.len
;
6186 fp
= tests
[which
].u
.insns
;
6187 for (len
= MAX_INSNS
- 1; len
> 0; --len
)
6188 if (fp
[len
].code
!= 0 || fp
[len
].k
!= 0)
6194 static void *filter_pointer(int which
)
6196 if (tests
[which
].fill_helper
)
6197 return tests
[which
].u
.ptr
.insns
;
6199 return tests
[which
].u
.insns
;
6202 static struct bpf_prog
*generate_filter(int which
, int *err
)
6204 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6205 unsigned int flen
= filter_length(which
);
6206 void *fptr
= filter_pointer(which
);
6207 struct sock_fprog_kern fprog
;
6208 struct bpf_prog
*fp
;
6210 switch (test_type
) {
6212 fprog
.filter
= fptr
;
6215 *err
= bpf_prog_create(&fp
, &fprog
);
6216 if (tests
[which
].aux
& FLAG_EXPECTED_FAIL
) {
6217 if (*err
== tests
[which
].expected_errcode
) {
6219 /* Verifier rejected filter as expected. */
6223 pr_cont("UNEXPECTED_PASS\n");
6224 /* Verifier didn't reject the test that's
6225 * bad enough, just return!
6232 pr_cont("FAIL to prog_create err=%d len=%d\n",
6239 fp
= bpf_prog_alloc(bpf_prog_size(flen
), 0);
6241 pr_cont("UNEXPECTED_FAIL no memory left\n");
6247 /* Type doesn't really matter here as long as it's not unspec. */
6248 fp
->type
= BPF_PROG_TYPE_SOCKET_FILTER
;
6249 memcpy(fp
->insnsi
, fptr
, fp
->len
* sizeof(struct bpf_insn
));
6250 fp
->aux
->stack_depth
= tests
[which
].stack_depth
;
6252 /* We cannot error here as we don't need type compatibility
6255 fp
= bpf_prog_select_runtime(fp
, err
);
6257 pr_cont("FAIL to select_runtime err=%d\n", *err
);
6267 static void release_filter(struct bpf_prog
*fp
, int which
)
6269 __u8 test_type
= tests
[which
].aux
& TEST_TYPE_MASK
;
6271 switch (test_type
) {
6273 bpf_prog_destroy(fp
);
6281 static int __run_one(const struct bpf_prog
*fp
, const void *data
,
6282 int runs
, u64
*duration
)
6287 start
= ktime_get_ns();
6289 for (i
= 0; i
< runs
; i
++)
6290 ret
= BPF_PROG_RUN(fp
, data
);
6292 finish
= ktime_get_ns();
6294 *duration
= finish
- start
;
6295 do_div(*duration
, runs
);
6300 static int run_one(const struct bpf_prog
*fp
, struct bpf_test
*test
)
6302 int err_cnt
= 0, i
, runs
= MAX_TESTRUNS
;
6304 for (i
= 0; i
< MAX_SUBTESTS
; i
++) {
6309 if (test
->test
[i
].data_size
== 0 &&
6310 test
->test
[i
].result
== 0)
6313 data
= generate_test_data(test
, i
);
6314 if (!data
&& !(test
->aux
& FLAG_NO_DATA
)) {
6315 pr_cont("data generation failed ");
6319 ret
= __run_one(fp
, data
, runs
, &duration
);
6320 release_test_data(test
, data
);
6322 if (ret
== test
->test
[i
].result
) {
6323 pr_cont("%lld ", duration
);
6325 pr_cont("ret %d != %d ", ret
,
6326 test
->test
[i
].result
);
6334 static char test_name
[64];
6335 module_param_string(test_name
, test_name
, sizeof(test_name
), 0);
6337 static int test_id
= -1;
6338 module_param(test_id
, int, 0);
6340 static int test_range
[2] = { 0, ARRAY_SIZE(tests
) - 1 };
6341 module_param_array(test_range
, int, NULL
, 0);
6343 static __init
int find_test_index(const char *test_name
)
6347 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6348 if (!strcmp(tests
[i
].descr
, test_name
))
6354 static __init
int prepare_bpf_tests(void)
6360 * if a test_id was specified, use test_range to
6361 * cover only that test.
6363 if (test_id
>= ARRAY_SIZE(tests
)) {
6364 pr_err("test_bpf: invalid test_id specified.\n");
6368 test_range
[0] = test_id
;
6369 test_range
[1] = test_id
;
6370 } else if (*test_name
) {
6372 * if a test_name was specified, find it and setup
6373 * test_range to cover only that test.
6375 int idx
= find_test_index(test_name
);
6378 pr_err("test_bpf: no test named '%s' found.\n",
6382 test_range
[0] = idx
;
6383 test_range
[1] = idx
;
6386 * check that the supplied test_range is valid.
6388 if (test_range
[0] >= ARRAY_SIZE(tests
) ||
6389 test_range
[1] >= ARRAY_SIZE(tests
) ||
6390 test_range
[0] < 0 || test_range
[1] < 0) {
6391 pr_err("test_bpf: test_range is out of bound.\n");
6395 if (test_range
[1] < test_range
[0]) {
6396 pr_err("test_bpf: test_range is ending before it starts.\n");
6401 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6402 if (tests
[i
].fill_helper
&&
6403 tests
[i
].fill_helper(&tests
[i
]) < 0)
6410 static __init
void destroy_bpf_tests(void)
6414 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6415 if (tests
[i
].fill_helper
)
6416 kfree(tests
[i
].u
.ptr
.insns
);
6420 static bool exclude_test(int test_id
)
6422 return test_id
< test_range
[0] || test_id
> test_range
[1];
6425 static __init
int test_bpf(void)
6427 int i
, err_cnt
= 0, pass_cnt
= 0;
6428 int jit_cnt
= 0, run_cnt
= 0;
6430 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
6431 struct bpf_prog
*fp
;
6434 if (exclude_test(i
))
6437 pr_info("#%d %s ", i
, tests
[i
].descr
);
6439 fp
= generate_filter(i
, &err
);
6449 pr_cont("jited:%u ", fp
->jited
);
6455 err
= run_one(fp
, &tests
[i
]);
6456 release_filter(fp
, i
);
6459 pr_cont("FAIL (%d times)\n", err
);
6467 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6468 pass_cnt
, err_cnt
, jit_cnt
, run_cnt
);
6470 return err_cnt
? -EINVAL
: 0;
6473 static int __init
test_bpf_init(void)
6477 ret
= prepare_bpf_tests();
6483 destroy_bpf_tests();
6487 static void __exit
test_bpf_exit(void)
6491 module_init(test_bpf_init
);
6492 module_exit(test_bpf_exit
);
6494 MODULE_LICENSE("GPL");