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/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_vlan.h>
25 /* General test specific settings */
26 #define MAX_SUBTESTS 3
27 #define MAX_TESTRUNS 10000
30 #define MAX_K 0xffffFFFF
32 /* Few constants used to init test 'skb' */
34 #define SKB_MARK 0x1234aaaa
35 #define SKB_HASH 0x1234aaab
36 #define SKB_QUEUE_MAP 123
37 #define SKB_VLAN_TCI 0xffff
38 #define SKB_DEV_IFINDEX 577
39 #define SKB_DEV_TYPE 588
41 /* Redefine REGs to make tests less verbose */
52 #define R10 BPF_REG_10
54 /* Flags that can be passed to test cases */
55 #define FLAG_NO_DATA BIT(0)
56 #define FLAG_EXPECTED_FAIL BIT(1)
59 CLASSIC = BIT(6), /* Old BPF instructions only. */
60 INTERNAL = BIT(7), /* Extended instruction set. */
63 #define TEST_TYPE_MASK (CLASSIC | INTERNAL)
68 struct sock_filter insns[MAX_INSNS];
69 struct sock_filter_int insns_int[MAX_INSNS];
79 static struct bpf_test tests[] = {
83 BPF_STMT(BPF_LD | BPF_IMM, 1),
84 BPF_STMT(BPF_MISC | BPF_TAX, 0),
85 BPF_STMT(BPF_LD | BPF_IMM, 2),
86 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
87 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
88 BPF_STMT(BPF_MISC | BPF_TAX, 0),
89 BPF_STMT(BPF_LD | BPF_LEN, 0),
90 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
91 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
92 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
93 BPF_STMT(BPF_RET | BPF_A, 0)
96 { 10, 20, 30, 40, 50 },
97 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
102 BPF_STMT(BPF_LDX | BPF_LEN, 0),
103 BPF_STMT(BPF_MISC | BPF_TXA, 0),
104 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
105 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
108 { 10, 20, 30, 40, 50 },
109 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
114 BPF_STMT(BPF_LD | BPF_IMM, 1),
115 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
116 BPF_STMT(BPF_LDX | BPF_IMM, 3),
117 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
118 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
119 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
120 BPF_STMT(BPF_RET | BPF_A, 0)
122 CLASSIC | FLAG_NO_DATA,
124 { { 0, 0xfffffffd } }
129 BPF_STMT(BPF_LD | BPF_IMM, 8),
130 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
131 BPF_STMT(BPF_MISC | BPF_TAX, 0),
132 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
133 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
134 BPF_STMT(BPF_MISC | BPF_TAX, 0),
135 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
136 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
137 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
138 BPF_STMT(BPF_RET | BPF_A, 0)
140 CLASSIC | FLAG_NO_DATA,
142 { { 0, 0x40000001 } }
147 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
148 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
149 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
150 BPF_STMT(BPF_MISC | BPF_TAX, 0),
151 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
152 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
153 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
154 BPF_STMT(BPF_RET | BPF_A, 0)
156 CLASSIC | FLAG_NO_DATA,
158 { { 0, 0x800000ff }, { 1, 0x800000ff } },
163 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
164 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
165 BPF_STMT(BPF_RET | BPF_K, 0),
166 BPF_STMT(BPF_RET | BPF_K, 1),
175 BPF_STMT(BPF_LDX | BPF_LEN, 0),
176 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
177 BPF_STMT(BPF_RET | BPF_K, 1)
181 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
186 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
187 BPF_STMT(BPF_RET | BPF_K, 1)
191 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
196 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
197 BPF_STMT(BPF_MISC | BPF_TAX, 0),
198 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
199 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
200 BPF_STMT(BPF_RET | BPF_A, 0)
204 { { 1, 0 }, { 2, 3 } },
209 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
210 BPF_STMT(BPF_LDX | BPF_LEN, 0),
211 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
212 BPF_STMT(BPF_MISC | BPF_TAX, 0),
213 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
214 BPF_STMT(BPF_RET | BPF_A, 0)
218 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
223 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
224 BPF_STMT(BPF_MISC | BPF_TAX, 0),
225 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
226 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
227 BPF_STMT(BPF_RET | BPF_A, 0)
230 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
231 { { 15, 0 }, { 16, 3 } },
236 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
237 BPF_STMT(BPF_LDX | BPF_LEN, 0),
238 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
239 BPF_STMT(BPF_MISC | BPF_TAX, 0),
240 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
241 BPF_STMT(BPF_RET | BPF_A, 0)
244 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
245 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
250 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
251 SKF_AD_OFF + SKF_AD_PKTTYPE),
252 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
253 BPF_STMT(BPF_RET | BPF_K, 1),
254 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
255 SKF_AD_OFF + SKF_AD_PKTTYPE),
256 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
257 BPF_STMT(BPF_RET | BPF_K, 1),
258 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
259 SKF_AD_OFF + SKF_AD_PKTTYPE),
260 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
261 BPF_STMT(BPF_RET | BPF_K, 1),
262 BPF_STMT(BPF_RET | BPF_A, 0)
266 { { 1, 3 }, { 10, 3 } },
271 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
272 SKF_AD_OFF + SKF_AD_MARK),
273 BPF_STMT(BPF_RET | BPF_A, 0)
277 { { 1, SKB_MARK}, { 10, SKB_MARK} },
282 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
283 SKF_AD_OFF + SKF_AD_RXHASH),
284 BPF_STMT(BPF_RET | BPF_A, 0)
288 { { 1, SKB_HASH}, { 10, SKB_HASH} },
293 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
294 SKF_AD_OFF + SKF_AD_QUEUE),
295 BPF_STMT(BPF_RET | BPF_A, 0)
299 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
304 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
305 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
306 BPF_STMT(BPF_RET | BPF_K, 0),
307 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
308 SKF_AD_OFF + SKF_AD_PROTOCOL),
309 BPF_STMT(BPF_MISC | BPF_TAX, 0),
310 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
311 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
312 BPF_STMT(BPF_RET | BPF_K, 0),
313 BPF_STMT(BPF_MISC | BPF_TXA, 0),
314 BPF_STMT(BPF_RET | BPF_A, 0)
318 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
323 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
324 SKF_AD_OFF + SKF_AD_VLAN_TAG),
325 BPF_STMT(BPF_RET | BPF_A, 0)
330 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
331 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
335 "LD_VLAN_TAG_PRESENT",
337 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
338 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
339 BPF_STMT(BPF_RET | BPF_A, 0)
344 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
345 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
351 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
352 SKF_AD_OFF + SKF_AD_IFINDEX),
353 BPF_STMT(BPF_RET | BPF_A, 0)
357 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
362 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
363 SKF_AD_OFF + SKF_AD_HATYPE),
364 BPF_STMT(BPF_RET | BPF_A, 0)
368 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
373 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
374 SKF_AD_OFF + SKF_AD_CPU),
375 BPF_STMT(BPF_MISC | BPF_TAX, 0),
376 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
377 SKF_AD_OFF + SKF_AD_CPU),
378 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
379 BPF_STMT(BPF_RET | BPF_A, 0)
383 { { 1, 0 }, { 10, 0 } },
388 BPF_STMT(BPF_LDX | BPF_IMM, 2),
389 BPF_STMT(BPF_MISC | BPF_TXA, 0),
390 BPF_STMT(BPF_LDX | BPF_IMM, 3),
391 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
392 SKF_AD_OFF + SKF_AD_NLATTR),
393 BPF_STMT(BPF_RET | BPF_A, 0)
397 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
399 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
401 { { 4, 0 }, { 20, 6 } },
406 BPF_STMT(BPF_LD | BPF_IMM, 2),
407 BPF_STMT(BPF_LDX | BPF_IMM, 3),
408 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
409 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
410 BPF_STMT(BPF_LD | BPF_IMM, 2),
411 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
412 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
413 BPF_STMT(BPF_LD | BPF_IMM, 2),
414 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
415 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
416 BPF_STMT(BPF_LD | BPF_IMM, 2),
417 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
418 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
419 BPF_STMT(BPF_LD | BPF_IMM, 2),
420 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
421 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
422 BPF_STMT(BPF_LD | BPF_IMM, 2),
423 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
424 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
425 BPF_STMT(BPF_LD | BPF_IMM, 2),
426 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
427 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
428 BPF_STMT(BPF_LD | BPF_IMM, 2),
429 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
430 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
431 BPF_STMT(BPF_RET | BPF_A, 0)
435 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
437 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
439 { { 4, 0 }, { 20, 10 } },
444 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
445 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
446 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
447 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
448 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
449 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
450 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
451 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
452 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
453 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
454 BPF_STMT(BPF_RET | BPF_A, 0)
457 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
458 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
459 * id 9737, seq 1, length 64
461 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
462 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
464 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
465 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
466 { { 30, 0 }, { 100, 42 } },
471 BPF_STMT(BPF_LD | BPF_IMM, 10),
472 BPF_STMT(BPF_LDX | BPF_IMM, 300),
473 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
474 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
475 BPF_STMT(BPF_RET | BPF_A, 0)
479 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
484 BPF_STMT(BPF_LDX | BPF_LEN, 0),
485 BPF_STMT(BPF_LD | BPF_IMM, 2),
486 BPF_STMT(BPF_ALU | BPF_RSH, 1),
487 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
488 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
489 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
490 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
491 BPF_STMT(BPF_STX, 15), /* M3 = len */
492 BPF_STMT(BPF_LDX | BPF_MEM, 1),
493 BPF_STMT(BPF_LD | BPF_MEM, 2),
494 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
495 BPF_STMT(BPF_LDX | BPF_MEM, 15),
496 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
497 BPF_STMT(BPF_RET | BPF_A, 0)
501 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
506 BPF_STMT(BPF_LDX | BPF_LEN, 0),
507 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
508 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
509 BPF_STMT(BPF_RET | BPF_K, 1),
510 BPF_STMT(BPF_RET | BPF_K, MAX_K)
514 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
519 BPF_STMT(BPF_LDX | BPF_LEN, 0),
520 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
521 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
522 BPF_STMT(BPF_RET | BPF_K, 1),
523 BPF_STMT(BPF_RET | BPF_K, MAX_K)
527 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
532 BPF_STMT(BPF_LDX | BPF_LEN, 0),
533 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
534 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
535 BPF_STMT(BPF_RET | BPF_K, 10),
536 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
537 BPF_STMT(BPF_RET | BPF_K, 20),
538 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
539 BPF_STMT(BPF_RET | BPF_K, 30),
540 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
541 BPF_STMT(BPF_RET | BPF_K, 40),
542 BPF_STMT(BPF_RET | BPF_K, MAX_K)
546 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
551 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
552 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
553 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
554 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
555 BPF_STMT(BPF_LDX | BPF_LEN, 0),
556 BPF_STMT(BPF_MISC | BPF_TXA, 0),
557 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
558 BPF_STMT(BPF_MISC | BPF_TAX, 0),
559 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
560 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
561 BPF_STMT(BPF_RET | BPF_K, 10),
562 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
563 BPF_STMT(BPF_RET | BPF_K, 20),
564 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
565 BPF_STMT(BPF_RET | BPF_K, 30),
566 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
567 BPF_STMT(BPF_RET | BPF_K, 30),
568 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
569 BPF_STMT(BPF_RET | BPF_K, 30),
570 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
571 BPF_STMT(BPF_RET | BPF_K, 30),
572 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
573 BPF_STMT(BPF_RET | BPF_K, 30),
574 BPF_STMT(BPF_RET | BPF_K, MAX_K)
577 { 0, 0xAA, 0x55, 1 },
578 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
583 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
584 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
585 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
586 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
587 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
588 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
589 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
590 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
591 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
592 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
593 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
594 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
595 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
596 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
597 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
598 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
599 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
600 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
601 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
602 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
603 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
604 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
605 BPF_STMT(BPF_RET | BPF_K, 0xffff),
606 BPF_STMT(BPF_RET | BPF_K, 0),
609 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
610 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
611 * seq 1305692979:1305693027, ack 3650467037, win 65535,
612 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
614 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
615 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
617 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
618 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
619 0x0a, 0x01, 0x01, 0x95, /* ip src */
620 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
622 0x00, 0x16 /* dst port */ },
623 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
628 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
629 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
630 * (len > 115 or len < 30000000000)' -d
632 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
633 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
634 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
635 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
636 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
637 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
638 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
639 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
640 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
641 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
642 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
643 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
644 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
646 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
647 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
648 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
649 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
650 BPF_STMT(BPF_LD | BPF_MEM, 1),
651 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
653 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
654 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
655 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
656 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
657 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
658 BPF_STMT(BPF_LD | BPF_MEM, 5),
659 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
660 BPF_STMT(BPF_LD | BPF_LEN, 0),
661 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
662 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
663 BPF_STMT(BPF_RET | BPF_K, 0xffff),
664 BPF_STMT(BPF_RET | BPF_K, 0),
667 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
668 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
670 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
671 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
672 0x0a, 0x01, 0x01, 0x95, /* ip src */
673 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
675 0x00, 0x16 /* dst port */ },
676 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
681 /* check that unitialized X and A contain zeros */
682 BPF_STMT(BPF_MISC | BPF_TXA, 0),
683 BPF_STMT(BPF_RET | BPF_A, 0)
692 BPF_ALU64_IMM(BPF_MOV, R1, 1),
693 BPF_ALU64_IMM(BPF_ADD, R1, 2),
694 BPF_ALU64_IMM(BPF_MOV, R2, 3),
695 BPF_ALU64_REG(BPF_SUB, R1, R2),
696 BPF_ALU64_IMM(BPF_ADD, R1, -1),
697 BPF_ALU64_IMM(BPF_MUL, R1, 3),
698 BPF_ALU64_REG(BPF_MOV, R0, R1),
703 { { 0, 0xfffffffd } }
708 BPF_ALU64_IMM(BPF_MOV, R0, -1),
709 BPF_ALU64_IMM(BPF_MOV, R1, -1),
710 BPF_ALU64_IMM(BPF_MOV, R2, 3),
711 BPF_ALU64_REG(BPF_MUL, R1, R2),
712 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
714 BPF_ALU64_IMM(BPF_MOV, R0, 1),
724 BPF_ALU32_IMM(BPF_MOV, R0, -1),
725 BPF_ALU32_IMM(BPF_MOV, R1, -1),
726 BPF_ALU32_IMM(BPF_MOV, R2, 3),
727 BPF_ALU64_REG(BPF_MUL, R1, R2),
728 BPF_ALU64_IMM(BPF_RSH, R1, 8),
729 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
731 BPF_ALU32_IMM(BPF_MOV, R0, 1),
741 BPF_ALU32_IMM(BPF_MOV, R0, -1),
742 BPF_ALU64_IMM(BPF_MOV, R1, -1),
743 BPF_ALU32_IMM(BPF_MOV, R2, 3),
744 BPF_ALU32_REG(BPF_MUL, R1, R2),
745 BPF_ALU64_IMM(BPF_RSH, R1, 8),
746 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
748 BPF_ALU32_IMM(BPF_MOV, R0, 1),
756 /* Have to test all register combinations, since
757 * JITing of different registers will produce
758 * different asm code.
762 BPF_ALU64_IMM(BPF_MOV, R0, 0),
763 BPF_ALU64_IMM(BPF_MOV, R1, 1),
764 BPF_ALU64_IMM(BPF_MOV, R2, 2),
765 BPF_ALU64_IMM(BPF_MOV, R3, 3),
766 BPF_ALU64_IMM(BPF_MOV, R4, 4),
767 BPF_ALU64_IMM(BPF_MOV, R5, 5),
768 BPF_ALU64_IMM(BPF_MOV, R6, 6),
769 BPF_ALU64_IMM(BPF_MOV, R7, 7),
770 BPF_ALU64_IMM(BPF_MOV, R8, 8),
771 BPF_ALU64_IMM(BPF_MOV, R9, 9),
772 BPF_ALU64_IMM(BPF_ADD, R0, 20),
773 BPF_ALU64_IMM(BPF_ADD, R1, 20),
774 BPF_ALU64_IMM(BPF_ADD, R2, 20),
775 BPF_ALU64_IMM(BPF_ADD, R3, 20),
776 BPF_ALU64_IMM(BPF_ADD, R4, 20),
777 BPF_ALU64_IMM(BPF_ADD, R5, 20),
778 BPF_ALU64_IMM(BPF_ADD, R6, 20),
779 BPF_ALU64_IMM(BPF_ADD, R7, 20),
780 BPF_ALU64_IMM(BPF_ADD, R8, 20),
781 BPF_ALU64_IMM(BPF_ADD, R9, 20),
782 BPF_ALU64_IMM(BPF_SUB, R0, 10),
783 BPF_ALU64_IMM(BPF_SUB, R1, 10),
784 BPF_ALU64_IMM(BPF_SUB, R2, 10),
785 BPF_ALU64_IMM(BPF_SUB, R3, 10),
786 BPF_ALU64_IMM(BPF_SUB, R4, 10),
787 BPF_ALU64_IMM(BPF_SUB, R5, 10),
788 BPF_ALU64_IMM(BPF_SUB, R6, 10),
789 BPF_ALU64_IMM(BPF_SUB, R7, 10),
790 BPF_ALU64_IMM(BPF_SUB, R8, 10),
791 BPF_ALU64_IMM(BPF_SUB, R9, 10),
792 BPF_ALU64_REG(BPF_ADD, R0, R0),
793 BPF_ALU64_REG(BPF_ADD, R0, R1),
794 BPF_ALU64_REG(BPF_ADD, R0, R2),
795 BPF_ALU64_REG(BPF_ADD, R0, R3),
796 BPF_ALU64_REG(BPF_ADD, R0, R4),
797 BPF_ALU64_REG(BPF_ADD, R0, R5),
798 BPF_ALU64_REG(BPF_ADD, R0, R6),
799 BPF_ALU64_REG(BPF_ADD, R0, R7),
800 BPF_ALU64_REG(BPF_ADD, R0, R8),
801 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
802 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
804 BPF_ALU64_REG(BPF_ADD, R1, R0),
805 BPF_ALU64_REG(BPF_ADD, R1, R1),
806 BPF_ALU64_REG(BPF_ADD, R1, R2),
807 BPF_ALU64_REG(BPF_ADD, R1, R3),
808 BPF_ALU64_REG(BPF_ADD, R1, R4),
809 BPF_ALU64_REG(BPF_ADD, R1, R5),
810 BPF_ALU64_REG(BPF_ADD, R1, R6),
811 BPF_ALU64_REG(BPF_ADD, R1, R7),
812 BPF_ALU64_REG(BPF_ADD, R1, R8),
813 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
814 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
816 BPF_ALU64_REG(BPF_ADD, R2, R0),
817 BPF_ALU64_REG(BPF_ADD, R2, R1),
818 BPF_ALU64_REG(BPF_ADD, R2, R2),
819 BPF_ALU64_REG(BPF_ADD, R2, R3),
820 BPF_ALU64_REG(BPF_ADD, R2, R4),
821 BPF_ALU64_REG(BPF_ADD, R2, R5),
822 BPF_ALU64_REG(BPF_ADD, R2, R6),
823 BPF_ALU64_REG(BPF_ADD, R2, R7),
824 BPF_ALU64_REG(BPF_ADD, R2, R8),
825 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
826 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
828 BPF_ALU64_REG(BPF_ADD, R3, R0),
829 BPF_ALU64_REG(BPF_ADD, R3, R1),
830 BPF_ALU64_REG(BPF_ADD, R3, R2),
831 BPF_ALU64_REG(BPF_ADD, R3, R3),
832 BPF_ALU64_REG(BPF_ADD, R3, R4),
833 BPF_ALU64_REG(BPF_ADD, R3, R5),
834 BPF_ALU64_REG(BPF_ADD, R3, R6),
835 BPF_ALU64_REG(BPF_ADD, R3, R7),
836 BPF_ALU64_REG(BPF_ADD, R3, R8),
837 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
838 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
840 BPF_ALU64_REG(BPF_ADD, R4, R0),
841 BPF_ALU64_REG(BPF_ADD, R4, R1),
842 BPF_ALU64_REG(BPF_ADD, R4, R2),
843 BPF_ALU64_REG(BPF_ADD, R4, R3),
844 BPF_ALU64_REG(BPF_ADD, R4, R4),
845 BPF_ALU64_REG(BPF_ADD, R4, R5),
846 BPF_ALU64_REG(BPF_ADD, R4, R6),
847 BPF_ALU64_REG(BPF_ADD, R4, R7),
848 BPF_ALU64_REG(BPF_ADD, R4, R8),
849 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
850 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
852 BPF_ALU64_REG(BPF_ADD, R5, R0),
853 BPF_ALU64_REG(BPF_ADD, R5, R1),
854 BPF_ALU64_REG(BPF_ADD, R5, R2),
855 BPF_ALU64_REG(BPF_ADD, R5, R3),
856 BPF_ALU64_REG(BPF_ADD, R5, R4),
857 BPF_ALU64_REG(BPF_ADD, R5, R5),
858 BPF_ALU64_REG(BPF_ADD, R5, R6),
859 BPF_ALU64_REG(BPF_ADD, R5, R7),
860 BPF_ALU64_REG(BPF_ADD, R5, R8),
861 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
862 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
864 BPF_ALU64_REG(BPF_ADD, R6, R0),
865 BPF_ALU64_REG(BPF_ADD, R6, R1),
866 BPF_ALU64_REG(BPF_ADD, R6, R2),
867 BPF_ALU64_REG(BPF_ADD, R6, R3),
868 BPF_ALU64_REG(BPF_ADD, R6, R4),
869 BPF_ALU64_REG(BPF_ADD, R6, R5),
870 BPF_ALU64_REG(BPF_ADD, R6, R6),
871 BPF_ALU64_REG(BPF_ADD, R6, R7),
872 BPF_ALU64_REG(BPF_ADD, R6, R8),
873 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
874 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
876 BPF_ALU64_REG(BPF_ADD, R7, R0),
877 BPF_ALU64_REG(BPF_ADD, R7, R1),
878 BPF_ALU64_REG(BPF_ADD, R7, R2),
879 BPF_ALU64_REG(BPF_ADD, R7, R3),
880 BPF_ALU64_REG(BPF_ADD, R7, R4),
881 BPF_ALU64_REG(BPF_ADD, R7, R5),
882 BPF_ALU64_REG(BPF_ADD, R7, R6),
883 BPF_ALU64_REG(BPF_ADD, R7, R7),
884 BPF_ALU64_REG(BPF_ADD, R7, R8),
885 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
886 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
888 BPF_ALU64_REG(BPF_ADD, R8, R0),
889 BPF_ALU64_REG(BPF_ADD, R8, R1),
890 BPF_ALU64_REG(BPF_ADD, R8, R2),
891 BPF_ALU64_REG(BPF_ADD, R8, R3),
892 BPF_ALU64_REG(BPF_ADD, R8, R4),
893 BPF_ALU64_REG(BPF_ADD, R8, R5),
894 BPF_ALU64_REG(BPF_ADD, R8, R6),
895 BPF_ALU64_REG(BPF_ADD, R8, R7),
896 BPF_ALU64_REG(BPF_ADD, R8, R8),
897 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
898 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
900 BPF_ALU64_REG(BPF_ADD, R9, R0),
901 BPF_ALU64_REG(BPF_ADD, R9, R1),
902 BPF_ALU64_REG(BPF_ADD, R9, R2),
903 BPF_ALU64_REG(BPF_ADD, R9, R3),
904 BPF_ALU64_REG(BPF_ADD, R9, R4),
905 BPF_ALU64_REG(BPF_ADD, R9, R5),
906 BPF_ALU64_REG(BPF_ADD, R9, R6),
907 BPF_ALU64_REG(BPF_ADD, R9, R7),
908 BPF_ALU64_REG(BPF_ADD, R9, R8),
909 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
910 BPF_ALU64_REG(BPF_MOV, R0, R9),
920 BPF_ALU32_IMM(BPF_MOV, R0, 20),
921 BPF_ALU32_IMM(BPF_MOV, R1, 1),
922 BPF_ALU32_IMM(BPF_MOV, R2, 2),
923 BPF_ALU32_IMM(BPF_MOV, R3, 3),
924 BPF_ALU32_IMM(BPF_MOV, R4, 4),
925 BPF_ALU32_IMM(BPF_MOV, R5, 5),
926 BPF_ALU32_IMM(BPF_MOV, R6, 6),
927 BPF_ALU32_IMM(BPF_MOV, R7, 7),
928 BPF_ALU32_IMM(BPF_MOV, R8, 8),
929 BPF_ALU32_IMM(BPF_MOV, R9, 9),
930 BPF_ALU64_IMM(BPF_ADD, R1, 10),
931 BPF_ALU64_IMM(BPF_ADD, R2, 10),
932 BPF_ALU64_IMM(BPF_ADD, R3, 10),
933 BPF_ALU64_IMM(BPF_ADD, R4, 10),
934 BPF_ALU64_IMM(BPF_ADD, R5, 10),
935 BPF_ALU64_IMM(BPF_ADD, R6, 10),
936 BPF_ALU64_IMM(BPF_ADD, R7, 10),
937 BPF_ALU64_IMM(BPF_ADD, R8, 10),
938 BPF_ALU64_IMM(BPF_ADD, R9, 10),
939 BPF_ALU32_REG(BPF_ADD, R0, R1),
940 BPF_ALU32_REG(BPF_ADD, R0, R2),
941 BPF_ALU32_REG(BPF_ADD, R0, R3),
942 BPF_ALU32_REG(BPF_ADD, R0, R4),
943 BPF_ALU32_REG(BPF_ADD, R0, R5),
944 BPF_ALU32_REG(BPF_ADD, R0, R6),
945 BPF_ALU32_REG(BPF_ADD, R0, R7),
946 BPF_ALU32_REG(BPF_ADD, R0, R8),
947 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
948 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
950 BPF_ALU32_REG(BPF_ADD, R1, R0),
951 BPF_ALU32_REG(BPF_ADD, R1, R1),
952 BPF_ALU32_REG(BPF_ADD, R1, R2),
953 BPF_ALU32_REG(BPF_ADD, R1, R3),
954 BPF_ALU32_REG(BPF_ADD, R1, R4),
955 BPF_ALU32_REG(BPF_ADD, R1, R5),
956 BPF_ALU32_REG(BPF_ADD, R1, R6),
957 BPF_ALU32_REG(BPF_ADD, R1, R7),
958 BPF_ALU32_REG(BPF_ADD, R1, R8),
959 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
960 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
962 BPF_ALU32_REG(BPF_ADD, R2, R0),
963 BPF_ALU32_REG(BPF_ADD, R2, R1),
964 BPF_ALU32_REG(BPF_ADD, R2, R2),
965 BPF_ALU32_REG(BPF_ADD, R2, R3),
966 BPF_ALU32_REG(BPF_ADD, R2, R4),
967 BPF_ALU32_REG(BPF_ADD, R2, R5),
968 BPF_ALU32_REG(BPF_ADD, R2, R6),
969 BPF_ALU32_REG(BPF_ADD, R2, R7),
970 BPF_ALU32_REG(BPF_ADD, R2, R8),
971 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
972 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
974 BPF_ALU32_REG(BPF_ADD, R3, R0),
975 BPF_ALU32_REG(BPF_ADD, R3, R1),
976 BPF_ALU32_REG(BPF_ADD, R3, R2),
977 BPF_ALU32_REG(BPF_ADD, R3, R3),
978 BPF_ALU32_REG(BPF_ADD, R3, R4),
979 BPF_ALU32_REG(BPF_ADD, R3, R5),
980 BPF_ALU32_REG(BPF_ADD, R3, R6),
981 BPF_ALU32_REG(BPF_ADD, R3, R7),
982 BPF_ALU32_REG(BPF_ADD, R3, R8),
983 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
984 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
986 BPF_ALU32_REG(BPF_ADD, R4, R0),
987 BPF_ALU32_REG(BPF_ADD, R4, R1),
988 BPF_ALU32_REG(BPF_ADD, R4, R2),
989 BPF_ALU32_REG(BPF_ADD, R4, R3),
990 BPF_ALU32_REG(BPF_ADD, R4, R4),
991 BPF_ALU32_REG(BPF_ADD, R4, R5),
992 BPF_ALU32_REG(BPF_ADD, R4, R6),
993 BPF_ALU32_REG(BPF_ADD, R4, R7),
994 BPF_ALU32_REG(BPF_ADD, R4, R8),
995 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
996 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
998 BPF_ALU32_REG(BPF_ADD, R5, R0),
999 BPF_ALU32_REG(BPF_ADD, R5, R1),
1000 BPF_ALU32_REG(BPF_ADD, R5, R2),
1001 BPF_ALU32_REG(BPF_ADD, R5, R3),
1002 BPF_ALU32_REG(BPF_ADD, R5, R4),
1003 BPF_ALU32_REG(BPF_ADD, R5, R5),
1004 BPF_ALU32_REG(BPF_ADD, R5, R6),
1005 BPF_ALU32_REG(BPF_ADD, R5, R7),
1006 BPF_ALU32_REG(BPF_ADD, R5, R8),
1007 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1008 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1010 BPF_ALU32_REG(BPF_ADD, R6, R0),
1011 BPF_ALU32_REG(BPF_ADD, R6, R1),
1012 BPF_ALU32_REG(BPF_ADD, R6, R2),
1013 BPF_ALU32_REG(BPF_ADD, R6, R3),
1014 BPF_ALU32_REG(BPF_ADD, R6, R4),
1015 BPF_ALU32_REG(BPF_ADD, R6, R5),
1016 BPF_ALU32_REG(BPF_ADD, R6, R6),
1017 BPF_ALU32_REG(BPF_ADD, R6, R7),
1018 BPF_ALU32_REG(BPF_ADD, R6, R8),
1019 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1020 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1022 BPF_ALU32_REG(BPF_ADD, R7, R0),
1023 BPF_ALU32_REG(BPF_ADD, R7, R1),
1024 BPF_ALU32_REG(BPF_ADD, R7, R2),
1025 BPF_ALU32_REG(BPF_ADD, R7, R3),
1026 BPF_ALU32_REG(BPF_ADD, R7, R4),
1027 BPF_ALU32_REG(BPF_ADD, R7, R5),
1028 BPF_ALU32_REG(BPF_ADD, R7, R6),
1029 BPF_ALU32_REG(BPF_ADD, R7, R7),
1030 BPF_ALU32_REG(BPF_ADD, R7, R8),
1031 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1032 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1034 BPF_ALU32_REG(BPF_ADD, R8, R0),
1035 BPF_ALU32_REG(BPF_ADD, R8, R1),
1036 BPF_ALU32_REG(BPF_ADD, R8, R2),
1037 BPF_ALU32_REG(BPF_ADD, R8, R3),
1038 BPF_ALU32_REG(BPF_ADD, R8, R4),
1039 BPF_ALU32_REG(BPF_ADD, R8, R5),
1040 BPF_ALU32_REG(BPF_ADD, R8, R6),
1041 BPF_ALU32_REG(BPF_ADD, R8, R7),
1042 BPF_ALU32_REG(BPF_ADD, R8, R8),
1043 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1044 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1046 BPF_ALU32_REG(BPF_ADD, R9, R0),
1047 BPF_ALU32_REG(BPF_ADD, R9, R1),
1048 BPF_ALU32_REG(BPF_ADD, R9, R2),
1049 BPF_ALU32_REG(BPF_ADD, R9, R3),
1050 BPF_ALU32_REG(BPF_ADD, R9, R4),
1051 BPF_ALU32_REG(BPF_ADD, R9, R5),
1052 BPF_ALU32_REG(BPF_ADD, R9, R6),
1053 BPF_ALU32_REG(BPF_ADD, R9, R7),
1054 BPF_ALU32_REG(BPF_ADD, R9, R8),
1055 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1056 BPF_ALU32_REG(BPF_MOV, R0, R9),
1063 { /* Mainly checking JIT here. */
1066 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1067 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1068 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1069 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1070 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1071 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1072 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1073 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1074 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1075 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1076 BPF_ALU64_REG(BPF_SUB, R0, R0),
1077 BPF_ALU64_REG(BPF_SUB, R0, R1),
1078 BPF_ALU64_REG(BPF_SUB, R0, R2),
1079 BPF_ALU64_REG(BPF_SUB, R0, R3),
1080 BPF_ALU64_REG(BPF_SUB, R0, R4),
1081 BPF_ALU64_REG(BPF_SUB, R0, R5),
1082 BPF_ALU64_REG(BPF_SUB, R0, R6),
1083 BPF_ALU64_REG(BPF_SUB, R0, R7),
1084 BPF_ALU64_REG(BPF_SUB, R0, R8),
1085 BPF_ALU64_REG(BPF_SUB, R0, R9),
1086 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1087 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1089 BPF_ALU64_REG(BPF_SUB, R1, R0),
1090 BPF_ALU64_REG(BPF_SUB, R1, R2),
1091 BPF_ALU64_REG(BPF_SUB, R1, R3),
1092 BPF_ALU64_REG(BPF_SUB, R1, R4),
1093 BPF_ALU64_REG(BPF_SUB, R1, R5),
1094 BPF_ALU64_REG(BPF_SUB, R1, R6),
1095 BPF_ALU64_REG(BPF_SUB, R1, R7),
1096 BPF_ALU64_REG(BPF_SUB, R1, R8),
1097 BPF_ALU64_REG(BPF_SUB, R1, R9),
1098 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1099 BPF_ALU64_REG(BPF_SUB, R2, R0),
1100 BPF_ALU64_REG(BPF_SUB, R2, R1),
1101 BPF_ALU64_REG(BPF_SUB, R2, R3),
1102 BPF_ALU64_REG(BPF_SUB, R2, R4),
1103 BPF_ALU64_REG(BPF_SUB, R2, R5),
1104 BPF_ALU64_REG(BPF_SUB, R2, R6),
1105 BPF_ALU64_REG(BPF_SUB, R2, R7),
1106 BPF_ALU64_REG(BPF_SUB, R2, R8),
1107 BPF_ALU64_REG(BPF_SUB, R2, R9),
1108 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1109 BPF_ALU64_REG(BPF_SUB, R3, R0),
1110 BPF_ALU64_REG(BPF_SUB, R3, R1),
1111 BPF_ALU64_REG(BPF_SUB, R3, R2),
1112 BPF_ALU64_REG(BPF_SUB, R3, R4),
1113 BPF_ALU64_REG(BPF_SUB, R3, R5),
1114 BPF_ALU64_REG(BPF_SUB, R3, R6),
1115 BPF_ALU64_REG(BPF_SUB, R3, R7),
1116 BPF_ALU64_REG(BPF_SUB, R3, R8),
1117 BPF_ALU64_REG(BPF_SUB, R3, R9),
1118 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1119 BPF_ALU64_REG(BPF_SUB, R4, R0),
1120 BPF_ALU64_REG(BPF_SUB, R4, R1),
1121 BPF_ALU64_REG(BPF_SUB, R4, R2),
1122 BPF_ALU64_REG(BPF_SUB, R4, R3),
1123 BPF_ALU64_REG(BPF_SUB, R4, R5),
1124 BPF_ALU64_REG(BPF_SUB, R4, R6),
1125 BPF_ALU64_REG(BPF_SUB, R4, R7),
1126 BPF_ALU64_REG(BPF_SUB, R4, R8),
1127 BPF_ALU64_REG(BPF_SUB, R4, R9),
1128 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1129 BPF_ALU64_REG(BPF_SUB, R5, R0),
1130 BPF_ALU64_REG(BPF_SUB, R5, R1),
1131 BPF_ALU64_REG(BPF_SUB, R5, R2),
1132 BPF_ALU64_REG(BPF_SUB, R5, R3),
1133 BPF_ALU64_REG(BPF_SUB, R5, R4),
1134 BPF_ALU64_REG(BPF_SUB, R5, R6),
1135 BPF_ALU64_REG(BPF_SUB, R5, R7),
1136 BPF_ALU64_REG(BPF_SUB, R5, R8),
1137 BPF_ALU64_REG(BPF_SUB, R5, R9),
1138 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1139 BPF_ALU64_REG(BPF_SUB, R6, R0),
1140 BPF_ALU64_REG(BPF_SUB, R6, R1),
1141 BPF_ALU64_REG(BPF_SUB, R6, R2),
1142 BPF_ALU64_REG(BPF_SUB, R6, R3),
1143 BPF_ALU64_REG(BPF_SUB, R6, R4),
1144 BPF_ALU64_REG(BPF_SUB, R6, R5),
1145 BPF_ALU64_REG(BPF_SUB, R6, R7),
1146 BPF_ALU64_REG(BPF_SUB, R6, R8),
1147 BPF_ALU64_REG(BPF_SUB, R6, R9),
1148 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1149 BPF_ALU64_REG(BPF_SUB, R7, R0),
1150 BPF_ALU64_REG(BPF_SUB, R7, R1),
1151 BPF_ALU64_REG(BPF_SUB, R7, R2),
1152 BPF_ALU64_REG(BPF_SUB, R7, R3),
1153 BPF_ALU64_REG(BPF_SUB, R7, R4),
1154 BPF_ALU64_REG(BPF_SUB, R7, R5),
1155 BPF_ALU64_REG(BPF_SUB, R7, R6),
1156 BPF_ALU64_REG(BPF_SUB, R7, R8),
1157 BPF_ALU64_REG(BPF_SUB, R7, R9),
1158 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1159 BPF_ALU64_REG(BPF_SUB, R8, R0),
1160 BPF_ALU64_REG(BPF_SUB, R8, R1),
1161 BPF_ALU64_REG(BPF_SUB, R8, R2),
1162 BPF_ALU64_REG(BPF_SUB, R8, R3),
1163 BPF_ALU64_REG(BPF_SUB, R8, R4),
1164 BPF_ALU64_REG(BPF_SUB, R8, R5),
1165 BPF_ALU64_REG(BPF_SUB, R8, R6),
1166 BPF_ALU64_REG(BPF_SUB, R8, R7),
1167 BPF_ALU64_REG(BPF_SUB, R8, R9),
1168 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1169 BPF_ALU64_REG(BPF_SUB, R9, R0),
1170 BPF_ALU64_REG(BPF_SUB, R9, R1),
1171 BPF_ALU64_REG(BPF_SUB, R9, R2),
1172 BPF_ALU64_REG(BPF_SUB, R9, R3),
1173 BPF_ALU64_REG(BPF_SUB, R9, R4),
1174 BPF_ALU64_REG(BPF_SUB, R9, R5),
1175 BPF_ALU64_REG(BPF_SUB, R9, R6),
1176 BPF_ALU64_REG(BPF_SUB, R9, R7),
1177 BPF_ALU64_REG(BPF_SUB, R9, R8),
1178 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1179 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1180 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1181 BPF_ALU64_REG(BPF_SUB, R0, R1),
1182 BPF_ALU64_REG(BPF_SUB, R0, R2),
1183 BPF_ALU64_REG(BPF_SUB, R0, R3),
1184 BPF_ALU64_REG(BPF_SUB, R0, R4),
1185 BPF_ALU64_REG(BPF_SUB, R0, R5),
1186 BPF_ALU64_REG(BPF_SUB, R0, R6),
1187 BPF_ALU64_REG(BPF_SUB, R0, R7),
1188 BPF_ALU64_REG(BPF_SUB, R0, R8),
1189 BPF_ALU64_REG(BPF_SUB, R0, R9),
1196 { /* Mainly checking JIT here. */
1199 BPF_ALU64_REG(BPF_SUB, R0, R0),
1200 BPF_ALU64_REG(BPF_XOR, R1, R1),
1201 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1203 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1204 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1205 BPF_ALU64_REG(BPF_SUB, R1, R1),
1206 BPF_ALU64_REG(BPF_XOR, R2, R2),
1207 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1209 BPF_ALU64_REG(BPF_SUB, R2, R2),
1210 BPF_ALU64_REG(BPF_XOR, R3, R3),
1211 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1212 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1213 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1215 BPF_ALU64_REG(BPF_SUB, R3, R3),
1216 BPF_ALU64_REG(BPF_XOR, R4, R4),
1217 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1218 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1219 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1221 BPF_ALU64_REG(BPF_SUB, R4, R4),
1222 BPF_ALU64_REG(BPF_XOR, R5, R5),
1223 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1224 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1225 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1227 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1228 BPF_ALU64_REG(BPF_SUB, R5, R5),
1229 BPF_ALU64_REG(BPF_XOR, R6, R6),
1230 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1231 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1232 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1234 BPF_ALU64_REG(BPF_SUB, R6, R6),
1235 BPF_ALU64_REG(BPF_XOR, R7, R7),
1236 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1238 BPF_ALU64_REG(BPF_SUB, R7, R7),
1239 BPF_ALU64_REG(BPF_XOR, R8, R8),
1240 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1242 BPF_ALU64_REG(BPF_SUB, R8, R8),
1243 BPF_ALU64_REG(BPF_XOR, R9, R9),
1244 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1246 BPF_ALU64_REG(BPF_SUB, R9, R9),
1247 BPF_ALU64_REG(BPF_XOR, R0, R0),
1248 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1250 BPF_ALU64_REG(BPF_SUB, R1, R1),
1251 BPF_ALU64_REG(BPF_XOR, R0, R0),
1252 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1253 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1255 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1262 { /* Mainly checking JIT here. */
1265 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1266 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1267 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1268 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1269 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1270 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1271 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1272 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1273 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1274 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1275 BPF_ALU64_REG(BPF_MUL, R0, R0),
1276 BPF_ALU64_REG(BPF_MUL, R0, R1),
1277 BPF_ALU64_REG(BPF_MUL, R0, R2),
1278 BPF_ALU64_REG(BPF_MUL, R0, R3),
1279 BPF_ALU64_REG(BPF_MUL, R0, R4),
1280 BPF_ALU64_REG(BPF_MUL, R0, R5),
1281 BPF_ALU64_REG(BPF_MUL, R0, R6),
1282 BPF_ALU64_REG(BPF_MUL, R0, R7),
1283 BPF_ALU64_REG(BPF_MUL, R0, R8),
1284 BPF_ALU64_REG(BPF_MUL, R0, R9),
1285 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1286 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1288 BPF_ALU64_REG(BPF_MUL, R1, R0),
1289 BPF_ALU64_REG(BPF_MUL, R1, R2),
1290 BPF_ALU64_REG(BPF_MUL, R1, R3),
1291 BPF_ALU64_REG(BPF_MUL, R1, R4),
1292 BPF_ALU64_REG(BPF_MUL, R1, R5),
1293 BPF_ALU64_REG(BPF_MUL, R1, R6),
1294 BPF_ALU64_REG(BPF_MUL, R1, R7),
1295 BPF_ALU64_REG(BPF_MUL, R1, R8),
1296 BPF_ALU64_REG(BPF_MUL, R1, R9),
1297 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1298 BPF_ALU64_REG(BPF_MOV, R2, R1),
1299 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1300 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1302 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1303 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1304 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1306 BPF_ALU64_REG(BPF_MUL, R2, R0),
1307 BPF_ALU64_REG(BPF_MUL, R2, R1),
1308 BPF_ALU64_REG(BPF_MUL, R2, R3),
1309 BPF_ALU64_REG(BPF_MUL, R2, R4),
1310 BPF_ALU64_REG(BPF_MUL, R2, R5),
1311 BPF_ALU64_REG(BPF_MUL, R2, R6),
1312 BPF_ALU64_REG(BPF_MUL, R2, R7),
1313 BPF_ALU64_REG(BPF_MUL, R2, R8),
1314 BPF_ALU64_REG(BPF_MUL, R2, R9),
1315 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1316 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1317 BPF_ALU64_REG(BPF_MOV, R0, R2),
1322 { { 0, 0x35d97ef2 } }
1327 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1328 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1329 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1330 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1331 BPF_ALU64_REG(BPF_DIV, R0, R2),
1332 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1334 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1335 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1337 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1347 BPF_ALU64_REG(BPF_MOV, R6, R1),
1348 BPF_LD_ABS(BPF_B, 3),
1349 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1350 BPF_ALU32_REG(BPF_DIV, R0, R2),
1351 BPF_ALU64_REG(BPF_MOV, R8, R0),
1352 BPF_LD_ABS(BPF_B, 4),
1353 BPF_ALU64_REG(BPF_ADD, R8, R0),
1354 BPF_LD_IND(BPF_B, R8, -70),
1358 { 10, 20, 30, 40, 50 },
1359 { { 4, 0 }, { 5, 10 } }
1364 BPF_ALU64_REG(BPF_MOV, R6, R1),
1365 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1366 BPF_LD_ABS(BPF_B, 3),
1367 BPF_ALU32_REG(BPF_DIV, R0, R7),
1371 { 10, 20, 30, 40, 50 },
1372 { { 3, 0 }, { 4, 0 } }
1375 "check: missing ret",
1377 BPF_STMT(BPF_LD | BPF_IMM, 1),
1379 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1386 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1387 BPF_STMT(BPF_RET | BPF_K, 0)
1389 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1394 "check: unknown insn",
1396 /* seccomp insn, rejected in socket filter */
1397 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1398 BPF_STMT(BPF_RET | BPF_K, 0)
1400 CLASSIC | FLAG_EXPECTED_FAIL,
1405 "check: out of range spill/fill",
1407 BPF_STMT(BPF_STX, 16),
1408 BPF_STMT(BPF_RET | BPF_K, 0)
1410 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1417 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1418 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1419 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1420 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1421 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1422 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1423 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1424 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1425 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1426 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1427 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1428 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1429 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1430 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1431 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1432 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1433 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1434 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1435 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1436 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1437 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1438 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1439 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1440 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1441 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1442 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1443 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1444 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1445 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1446 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1447 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1448 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1449 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1450 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1451 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
1452 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
1453 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1454 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1455 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1456 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1457 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1458 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1459 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1460 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1461 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1462 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1463 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1464 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1465 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1466 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1467 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1468 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1469 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
1470 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
1471 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1472 BPF_STMT(BPF_RET | BPF_A, 0),
1473 BPF_STMT(BPF_RET | BPF_A, 0),
1476 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
1477 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
1479 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
1480 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
1481 0xc0, 0xa8, 0x33, 0x01,
1482 0xc0, 0xa8, 0x33, 0x02,
1485 0x00, 0x14, 0x00, 0x00,
1486 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1487 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1488 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1489 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1490 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1491 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1492 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
1493 0xcc, 0xcc, 0xcc, 0xcc },
1499 BPF_STMT(BPF_RET | BPF_X, 0),
1501 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1506 "check: LDX + RET X",
1508 BPF_STMT(BPF_LDX | BPF_IMM, 42),
1509 BPF_STMT(BPF_RET | BPF_X, 0),
1511 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1515 { /* Mainly checking JIT here. */
1516 "M[]: alt STX + LDX",
1518 BPF_STMT(BPF_LDX | BPF_IMM, 100),
1519 BPF_STMT(BPF_STX, 0),
1520 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1521 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1522 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1523 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1524 BPF_STMT(BPF_STX, 1),
1525 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1526 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1527 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1528 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1529 BPF_STMT(BPF_STX, 2),
1530 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1531 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1532 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1533 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1534 BPF_STMT(BPF_STX, 3),
1535 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1536 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1537 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1538 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1539 BPF_STMT(BPF_STX, 4),
1540 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1541 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1542 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1543 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1544 BPF_STMT(BPF_STX, 5),
1545 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1546 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1547 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1548 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1549 BPF_STMT(BPF_STX, 6),
1550 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1551 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1552 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1553 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1554 BPF_STMT(BPF_STX, 7),
1555 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1556 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1557 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1558 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1559 BPF_STMT(BPF_STX, 8),
1560 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1561 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1562 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1563 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1564 BPF_STMT(BPF_STX, 9),
1565 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1566 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1567 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1568 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1569 BPF_STMT(BPF_STX, 10),
1570 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1571 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1572 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1573 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1574 BPF_STMT(BPF_STX, 11),
1575 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1576 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1577 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1578 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1579 BPF_STMT(BPF_STX, 12),
1580 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1581 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1582 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1583 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1584 BPF_STMT(BPF_STX, 13),
1585 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1586 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1587 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1588 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1589 BPF_STMT(BPF_STX, 14),
1590 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1591 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1592 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1593 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1594 BPF_STMT(BPF_STX, 15),
1595 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1596 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1597 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
1598 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1599 BPF_STMT(BPF_RET | BPF_A, 0),
1601 CLASSIC | FLAG_NO_DATA,
1605 { /* Mainly checking JIT here. */
1606 "M[]: full STX + full LDX",
1608 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
1609 BPF_STMT(BPF_STX, 0),
1610 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
1611 BPF_STMT(BPF_STX, 1),
1612 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
1613 BPF_STMT(BPF_STX, 2),
1614 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
1615 BPF_STMT(BPF_STX, 3),
1616 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
1617 BPF_STMT(BPF_STX, 4),
1618 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
1619 BPF_STMT(BPF_STX, 5),
1620 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
1621 BPF_STMT(BPF_STX, 6),
1622 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
1623 BPF_STMT(BPF_STX, 7),
1624 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
1625 BPF_STMT(BPF_STX, 8),
1626 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
1627 BPF_STMT(BPF_STX, 9),
1628 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
1629 BPF_STMT(BPF_STX, 10),
1630 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
1631 BPF_STMT(BPF_STX, 11),
1632 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
1633 BPF_STMT(BPF_STX, 12),
1634 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
1635 BPF_STMT(BPF_STX, 13),
1636 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
1637 BPF_STMT(BPF_STX, 14),
1638 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
1639 BPF_STMT(BPF_STX, 15),
1640 BPF_STMT(BPF_LDX | BPF_MEM, 0),
1641 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1642 BPF_STMT(BPF_LDX | BPF_MEM, 1),
1643 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1644 BPF_STMT(BPF_LDX | BPF_MEM, 2),
1645 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1646 BPF_STMT(BPF_LDX | BPF_MEM, 3),
1647 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1648 BPF_STMT(BPF_LDX | BPF_MEM, 4),
1649 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1650 BPF_STMT(BPF_LDX | BPF_MEM, 5),
1651 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1652 BPF_STMT(BPF_LDX | BPF_MEM, 6),
1653 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1654 BPF_STMT(BPF_LDX | BPF_MEM, 7),
1655 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1656 BPF_STMT(BPF_LDX | BPF_MEM, 8),
1657 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1658 BPF_STMT(BPF_LDX | BPF_MEM, 9),
1659 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1660 BPF_STMT(BPF_LDX | BPF_MEM, 10),
1661 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1662 BPF_STMT(BPF_LDX | BPF_MEM, 11),
1663 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1664 BPF_STMT(BPF_LDX | BPF_MEM, 12),
1665 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1666 BPF_STMT(BPF_LDX | BPF_MEM, 13),
1667 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1668 BPF_STMT(BPF_LDX | BPF_MEM, 14),
1669 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1670 BPF_STMT(BPF_LDX | BPF_MEM, 15),
1671 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
1672 BPF_STMT(BPF_RET | BPF_A, 0),
1674 CLASSIC | FLAG_NO_DATA,
1676 { { 0, 0x2a5a5e5 } },
1679 "check: SKF_AD_MAX",
1681 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
1682 SKF_AD_OFF + SKF_AD_MAX),
1683 BPF_STMT(BPF_RET | BPF_A, 0),
1685 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
1689 { /* Passes checker but fails during runtime. */
1690 "LD [SKF_AD_OFF-1]",
1692 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
1694 BPF_STMT(BPF_RET | BPF_K, 1),
1702 static struct net_device dev;
1704 static struct sk_buff *populate_skb(char *buf, int size)
1706 struct sk_buff *skb;
1708 if (size >= MAX_DATA)
1711 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
1715 memcpy(__skb_put(skb, size), buf, size);
1717 /* Initialize a fake skb with test pattern. */
1718 skb_reset_mac_header(skb);
1719 skb->protocol = htons(ETH_P_IP);
1720 skb->pkt_type = SKB_TYPE;
1721 skb->mark = SKB_MARK;
1722 skb->hash = SKB_HASH;
1723 skb->queue_mapping = SKB_QUEUE_MAP;
1724 skb->vlan_tci = SKB_VLAN_TCI;
1726 skb->dev->ifindex = SKB_DEV_IFINDEX;
1727 skb->dev->type = SKB_DEV_TYPE;
1728 skb_set_network_header(skb, min(size, ETH_HLEN));
1733 static void *generate_test_data(struct bpf_test *test, int sub)
1735 if (test->aux & FLAG_NO_DATA)
1738 /* Test case expects an skb, so populate one. Various
1739 * subtests generate skbs of different sizes based on
1742 return populate_skb(test->data, test->test[sub].data_size);
1745 static void release_test_data(const struct bpf_test *test, void *data)
1747 if (test->aux & FLAG_NO_DATA)
1753 static int probe_filter_length(struct sock_filter *fp)
1757 for (len = MAX_INSNS - 1; len > 0; --len)
1758 if (fp[len].code != 0 || fp[len].k != 0)
1764 static struct sk_filter *generate_filter(int which, int *err)
1766 struct sk_filter *fp;
1767 struct sock_fprog_kern fprog;
1768 unsigned int flen = probe_filter_length(tests[which].u.insns);
1769 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
1771 switch (test_type) {
1773 fprog.filter = tests[which].u.insns;
1776 *err = sk_unattached_filter_create(&fp, &fprog);
1777 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
1778 if (*err == -EINVAL) {
1780 /* Verifier rejected filter as expected. */
1784 pr_cont("UNEXPECTED_PASS\n");
1785 /* Verifier didn't reject the test that's
1786 * bad enough, just return!
1792 /* We don't expect to fail. */
1794 pr_cont("FAIL to attach err=%d len=%d\n",
1801 fp = kzalloc(sk_filter_size(flen), GFP_KERNEL);
1803 pr_cont("UNEXPECTED_FAIL no memory left\n");
1809 memcpy(fp->insnsi, tests[which].u.insns_int,
1810 fp->len * sizeof(struct sock_filter_int));
1812 sk_filter_select_runtime(fp);
1820 static void release_filter(struct sk_filter *fp, int which)
1822 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
1824 switch (test_type) {
1826 sk_unattached_filter_destroy(fp);
1834 static int __run_one(const struct sk_filter *fp, const void *data,
1835 int runs, u64 *duration)
1840 start = ktime_to_us(ktime_get());
1842 for (i = 0; i < runs; i++)
1843 ret = SK_RUN_FILTER(fp, data);
1845 finish = ktime_to_us(ktime_get());
1847 *duration = (finish - start) * 1000ULL;
1848 do_div(*duration, runs);
1853 static int run_one(const struct sk_filter *fp, struct bpf_test *test)
1855 int err_cnt = 0, i, runs = MAX_TESTRUNS;
1857 for (i = 0; i < MAX_SUBTESTS; i++) {
1862 if (test->test[i].data_size == 0 &&
1863 test->test[i].result == 0)
1866 data = generate_test_data(test, i);
1867 ret = __run_one(fp, data, runs, &duration);
1868 release_test_data(test, data);
1870 if (ret == test->test[i].result) {
1871 pr_cont("%lld ", duration);
1873 pr_cont("ret %d != %d ", ret,
1874 test->test[i].result);
1882 static __init int test_bpf(void)
1884 int i, err_cnt = 0, pass_cnt = 0;
1886 for (i = 0; i < ARRAY_SIZE(tests); i++) {
1887 struct sk_filter *fp;
1890 pr_info("#%d %s ", i, tests[i].descr);
1892 fp = generate_filter(i, &err);
1901 err = run_one(fp, &tests[i]);
1902 release_filter(fp, i);
1905 pr_cont("FAIL (%d times)\n", err);
1913 pr_info("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt);
1914 return err_cnt ? -EINVAL : 0;
1917 static int __init test_bpf_init(void)
1922 static void __exit test_bpf_exit(void)
1926 module_init(test_bpf_init);
1927 module_exit(test_bpf_exit);
1929 MODULE_LICENSE("GPL");