blob: f369889e521d7e7f1e237236651532e6a862e0f5 [file] [log] [blame]
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001/*
2 * Testsuite for BPF interpreter and BPF JIT compiler
3 *
4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/filter.h>
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -070021#include <linux/bpf.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070022#include <linux/skbuff.h>
23#include <linux/netdevice.h>
24#include <linux/if_vlan.h>
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020025#include <linux/random.h>
Nicolas Schichanbac142a2015-08-04 15:19:08 +020026#include <linux/highmem.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070027
Daniel Borkmann10f18e02014-05-23 18:44:00 +020028/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070029#define MAX_SUBTESTS 3
Daniel Borkmann10f18e02014-05-23 18:44:00 +020030#define MAX_TESTRUNS 10000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070031#define MAX_DATA 128
32#define MAX_INSNS 512
33#define MAX_K 0xffffFFFF
34
Daniel Borkmann10f18e02014-05-23 18:44:00 +020035/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070036#define SKB_TYPE 3
37#define SKB_MARK 0x1234aaaa
38#define SKB_HASH 0x1234aaab
39#define SKB_QUEUE_MAP 123
40#define SKB_VLAN_TCI 0xffff
41#define SKB_DEV_IFINDEX 577
42#define SKB_DEV_TYPE 588
43
Daniel Borkmann10f18e02014-05-23 18:44:00 +020044/* Redefine REGs to make tests less verbose */
45#define R0 BPF_REG_0
46#define R1 BPF_REG_1
47#define R2 BPF_REG_2
48#define R3 BPF_REG_3
49#define R4 BPF_REG_4
50#define R5 BPF_REG_5
51#define R6 BPF_REG_6
52#define R7 BPF_REG_7
53#define R8 BPF_REG_8
54#define R9 BPF_REG_9
55#define R10 BPF_REG_10
56
57/* Flags that can be passed to test cases */
58#define FLAG_NO_DATA BIT(0)
59#define FLAG_EXPECTED_FAIL BIT(1)
Nicolas Schichanbac142a2015-08-04 15:19:08 +020060#define FLAG_SKB_FRAG BIT(2)
Daniel Borkmann10f18e02014-05-23 18:44:00 +020061
62enum {
63 CLASSIC = BIT(6), /* Old BPF instructions only. */
64 INTERNAL = BIT(7), /* Extended instruction set. */
65};
66
67#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070068
69struct bpf_test {
70 const char *descr;
71 union {
72 struct sock_filter insns[MAX_INSNS];
Alexei Starovoitov2695fb52014-07-24 16:38:21 -070073 struct bpf_insn insns_int[MAX_INSNS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020074 struct {
75 void *insns;
76 unsigned int len;
77 } ptr;
Andrew Mortonece80492014-05-22 10:16:46 -070078 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020079 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070080 __u8 data[MAX_DATA];
81 struct {
82 int data_size;
83 __u32 result;
84 } test[MAX_SUBTESTS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020085 int (*fill_helper)(struct bpf_test *self);
Nicolas Schichanbac142a2015-08-04 15:19:08 +020086 __u8 frag_data[MAX_DATA];
Alexei Starovoitov105c0362017-05-30 13:31:32 -070087 int stack_depth; /* for eBPF only, since tests don't call verifier */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070088};
89
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020090/* Large test cases need separate allocation and fill handler. */
91
92static int bpf_fill_maxinsns1(struct bpf_test *self)
93{
94 unsigned int len = BPF_MAXINSNS;
95 struct sock_filter *insn;
96 __u32 k = ~0;
97 int i;
98
99 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
100 if (!insn)
101 return -ENOMEM;
102
103 for (i = 0; i < len; i++, k--)
104 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
105
106 self->u.ptr.insns = insn;
107 self->u.ptr.len = len;
108
109 return 0;
110}
111
112static int bpf_fill_maxinsns2(struct bpf_test *self)
113{
114 unsigned int len = BPF_MAXINSNS;
115 struct sock_filter *insn;
116 int i;
117
118 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
119 if (!insn)
120 return -ENOMEM;
121
122 for (i = 0; i < len; i++)
123 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
124
125 self->u.ptr.insns = insn;
126 self->u.ptr.len = len;
127
128 return 0;
129}
130
131static int bpf_fill_maxinsns3(struct bpf_test *self)
132{
133 unsigned int len = BPF_MAXINSNS;
134 struct sock_filter *insn;
135 struct rnd_state rnd;
136 int i;
137
138 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
139 if (!insn)
140 return -ENOMEM;
141
142 prandom_seed_state(&rnd, 3141592653589793238ULL);
143
144 for (i = 0; i < len - 1; i++) {
145 __u32 k = prandom_u32_state(&rnd);
146
147 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
148 }
149
150 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
151
152 self->u.ptr.insns = insn;
153 self->u.ptr.len = len;
154
155 return 0;
156}
157
158static int bpf_fill_maxinsns4(struct bpf_test *self)
159{
160 unsigned int len = BPF_MAXINSNS + 1;
161 struct sock_filter *insn;
162 int i;
163
164 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
165 if (!insn)
166 return -ENOMEM;
167
168 for (i = 0; i < len; i++)
169 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
170
171 self->u.ptr.insns = insn;
172 self->u.ptr.len = len;
173
174 return 0;
175}
176
177static int bpf_fill_maxinsns5(struct bpf_test *self)
178{
179 unsigned int len = BPF_MAXINSNS;
180 struct sock_filter *insn;
181 int i;
182
183 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
184 if (!insn)
185 return -ENOMEM;
186
187 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
188
189 for (i = 1; i < len - 1; i++)
190 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
191
192 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
193
194 self->u.ptr.insns = insn;
195 self->u.ptr.len = len;
196
197 return 0;
198}
199
200static int bpf_fill_maxinsns6(struct bpf_test *self)
201{
202 unsigned int len = BPF_MAXINSNS;
203 struct sock_filter *insn;
204 int i;
205
206 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
207 if (!insn)
208 return -ENOMEM;
209
210 for (i = 0; i < len - 1; i++)
211 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
212 SKF_AD_VLAN_TAG_PRESENT);
213
214 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
215
216 self->u.ptr.insns = insn;
217 self->u.ptr.len = len;
218
219 return 0;
220}
221
222static int bpf_fill_maxinsns7(struct bpf_test *self)
223{
224 unsigned int len = BPF_MAXINSNS;
225 struct sock_filter *insn;
226 int i;
227
228 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
229 if (!insn)
230 return -ENOMEM;
231
232 for (i = 0; i < len - 4; i++)
233 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
234 SKF_AD_CPU);
235
236 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
237 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
238 SKF_AD_CPU);
239 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
240 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
241
242 self->u.ptr.insns = insn;
243 self->u.ptr.len = len;
244
245 return 0;
246}
247
248static int bpf_fill_maxinsns8(struct bpf_test *self)
249{
250 unsigned int len = BPF_MAXINSNS;
251 struct sock_filter *insn;
252 int i, jmp_off = len - 3;
253
254 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
255 if (!insn)
256 return -ENOMEM;
257
258 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
259
260 for (i = 1; i < len - 1; i++)
261 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
262
263 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
264
265 self->u.ptr.insns = insn;
266 self->u.ptr.len = len;
267
268 return 0;
269}
270
Daniel Borkmann3b529602015-05-23 01:10:07 +0200271static int bpf_fill_maxinsns9(struct bpf_test *self)
272{
273 unsigned int len = BPF_MAXINSNS;
274 struct bpf_insn *insn;
275 int i;
276
277 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
278 if (!insn)
279 return -ENOMEM;
280
281 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
282 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
283 insn[2] = BPF_EXIT_INSN();
284
285 for (i = 3; i < len - 2; i++)
286 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
287
288 insn[len - 2] = BPF_EXIT_INSN();
289 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
290
291 self->u.ptr.insns = insn;
292 self->u.ptr.len = len;
293
294 return 0;
295}
296
297static int bpf_fill_maxinsns10(struct bpf_test *self)
298{
299 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
300 struct bpf_insn *insn;
301 int i;
302
303 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
304 if (!insn)
305 return -ENOMEM;
306
307 for (i = 0; i < hlen / 2; i++)
308 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
309 for (i = hlen - 1; i > hlen / 2; i--)
310 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
311
312 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
313 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
314 insn[hlen + 1] = BPF_EXIT_INSN();
315
316 self->u.ptr.insns = insn;
317 self->u.ptr.len = len;
318
319 return 0;
320}
321
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200322static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
323 unsigned int plen)
324{
325 struct sock_filter *insn;
326 unsigned int rlen;
327 int i, j;
328
329 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
330 if (!insn)
331 return -ENOMEM;
332
333 rlen = (len % plen) - 1;
334
335 for (i = 0; i + plen < len; i += plen)
336 for (j = 0; j < plen; j++)
337 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
338 plen - 1 - j, 0, 0);
339 for (j = 0; j < rlen; j++)
340 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
341 0, 0);
342
343 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
344
345 self->u.ptr.insns = insn;
346 self->u.ptr.len = len;
347
348 return 0;
349}
350
351static int bpf_fill_maxinsns11(struct bpf_test *self)
352{
353 /* Hits 70 passes on x86_64, so cannot get JITed there. */
354 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
355}
356
357static int bpf_fill_ja(struct bpf_test *self)
358{
359 /* Hits exactly 11 passes on x86_64 JIT. */
360 return __bpf_fill_ja(self, 12, 9);
361}
362
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -0700363static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
364{
365 unsigned int len = BPF_MAXINSNS;
366 struct sock_filter *insn;
367 int i;
368
369 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
370 if (!insn)
371 return -ENOMEM;
372
373 for (i = 0; i < len - 1; i += 2) {
374 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
375 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
376 SKF_AD_OFF + SKF_AD_CPU);
377 }
378
379 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
380
381 self->u.ptr.insns = insn;
382 self->u.ptr.len = len;
383
384 return 0;
385}
386
387#define PUSH_CNT 68
388/* test: {skb->data[0], vlan_push} x 68 + {skb->data[0], vlan_pop} x 68 */
389static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self)
390{
391 unsigned int len = BPF_MAXINSNS;
392 struct bpf_insn *insn;
393 int i = 0, j, k = 0;
394
395 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
396 if (!insn)
397 return -ENOMEM;
398
399 insn[i++] = BPF_MOV64_REG(R6, R1);
400loop:
401 for (j = 0; j < PUSH_CNT; j++) {
402 insn[i++] = BPF_LD_ABS(BPF_B, 0);
403 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
404 i++;
405 insn[i++] = BPF_MOV64_REG(R1, R6);
406 insn[i++] = BPF_MOV64_IMM(R2, 1);
407 insn[i++] = BPF_MOV64_IMM(R3, 2);
408 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
409 bpf_skb_vlan_push_proto.func - __bpf_call_base);
410 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
411 i++;
412 }
413
414 for (j = 0; j < PUSH_CNT; j++) {
415 insn[i++] = BPF_LD_ABS(BPF_B, 0);
416 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0x34, len - i - 2);
417 i++;
418 insn[i++] = BPF_MOV64_REG(R1, R6);
419 insn[i++] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
420 bpf_skb_vlan_pop_proto.func - __bpf_call_base);
421 insn[i] = BPF_JMP_IMM(BPF_JNE, R0, 0, len - i - 2);
422 i++;
423 }
424 if (++k < 5)
425 goto loop;
426
427 for (; i < len - 1; i++)
428 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xbef);
429
430 insn[len - 1] = BPF_EXIT_INSN();
431
432 self->u.ptr.insns = insn;
433 self->u.ptr.len = len;
434
435 return 0;
436}
437
Daniel Borkmann87ab8192017-12-14 21:07:27 +0100438static int bpf_fill_ld_abs_vlan_push_pop2(struct bpf_test *self)
439{
440 struct bpf_insn *insn;
441
442 insn = kmalloc_array(16, sizeof(*insn), GFP_KERNEL);
443 if (!insn)
444 return -ENOMEM;
445
446 /* Due to func address being non-const, we need to
447 * assemble this here.
448 */
449 insn[0] = BPF_MOV64_REG(R6, R1);
450 insn[1] = BPF_LD_ABS(BPF_B, 0);
451 insn[2] = BPF_LD_ABS(BPF_H, 0);
452 insn[3] = BPF_LD_ABS(BPF_W, 0);
453 insn[4] = BPF_MOV64_REG(R7, R6);
454 insn[5] = BPF_MOV64_IMM(R6, 0);
455 insn[6] = BPF_MOV64_REG(R1, R7);
456 insn[7] = BPF_MOV64_IMM(R2, 1);
457 insn[8] = BPF_MOV64_IMM(R3, 2);
458 insn[9] = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
459 bpf_skb_vlan_push_proto.func - __bpf_call_base);
460 insn[10] = BPF_MOV64_REG(R6, R7);
461 insn[11] = BPF_LD_ABS(BPF_B, 0);
462 insn[12] = BPF_LD_ABS(BPF_H, 0);
463 insn[13] = BPF_LD_ABS(BPF_W, 0);
464 insn[14] = BPF_MOV64_IMM(R0, 42);
465 insn[15] = BPF_EXIT_INSN();
466
467 self->u.ptr.insns = insn;
468 self->u.ptr.len = 16;
469
470 return 0;
471}
472
David Daneyb7127cf2017-06-13 16:49:36 -0700473static int bpf_fill_jump_around_ld_abs(struct bpf_test *self)
474{
475 unsigned int len = BPF_MAXINSNS;
476 struct bpf_insn *insn;
477 int i = 0;
478
479 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
480 if (!insn)
481 return -ENOMEM;
482
483 insn[i++] = BPF_MOV64_REG(R6, R1);
484 insn[i++] = BPF_LD_ABS(BPF_B, 0);
485 insn[i] = BPF_JMP_IMM(BPF_JEQ, R0, 10, len - i - 2);
486 i++;
487 while (i < len - 1)
488 insn[i++] = BPF_LD_ABS(BPF_B, 1);
489 insn[i] = BPF_EXIT_INSN();
490
491 self->u.ptr.insns = insn;
492 self->u.ptr.len = len;
493
494 return 0;
495}
496
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200497static int __bpf_fill_stxdw(struct bpf_test *self, int size)
498{
499 unsigned int len = BPF_MAXINSNS;
500 struct bpf_insn *insn;
501 int i;
502
503 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
504 if (!insn)
505 return -ENOMEM;
506
507 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
508 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
509
510 for (i = 2; i < len - 2; i++)
511 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
512
513 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
514 insn[len - 1] = BPF_EXIT_INSN();
515
516 self->u.ptr.insns = insn;
517 self->u.ptr.len = len;
Alexei Starovoitov105c0362017-05-30 13:31:32 -0700518 self->stack_depth = 40;
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200519
520 return 0;
521}
522
523static int bpf_fill_stxw(struct bpf_test *self)
524{
525 return __bpf_fill_stxdw(self, BPF_W);
526}
527
528static int bpf_fill_stxdw(struct bpf_test *self)
529{
530 return __bpf_fill_stxdw(self, BPF_DW);
531}
532
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700533static struct bpf_test tests[] = {
534 {
535 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -0700536 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700537 BPF_STMT(BPF_LD | BPF_IMM, 1),
538 BPF_STMT(BPF_MISC | BPF_TAX, 0),
539 BPF_STMT(BPF_LD | BPF_IMM, 2),
540 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
541 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
542 BPF_STMT(BPF_MISC | BPF_TAX, 0),
543 BPF_STMT(BPF_LD | BPF_LEN, 0),
544 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
545 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
546 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
547 BPF_STMT(BPF_RET | BPF_A, 0)
548 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200549 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700550 { 10, 20, 30, 40, 50 },
551 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
552 },
553 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700554 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700555 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700556 BPF_STMT(BPF_LDX | BPF_LEN, 0),
557 BPF_STMT(BPF_MISC | BPF_TXA, 0),
558 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
559 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
560 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200561 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700562 { 10, 20, 30, 40, 50 },
563 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
564 },
565 {
566 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700567 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700568 BPF_STMT(BPF_LD | BPF_IMM, 1),
569 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
570 BPF_STMT(BPF_LDX | BPF_IMM, 3),
571 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
572 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
573 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
574 BPF_STMT(BPF_RET | BPF_A, 0)
575 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200576 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700577 { },
578 { { 0, 0xfffffffd } }
579 },
580 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300581 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700582 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700583 BPF_STMT(BPF_LD | BPF_IMM, 8),
584 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
585 BPF_STMT(BPF_MISC | BPF_TAX, 0),
586 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
587 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
588 BPF_STMT(BPF_MISC | BPF_TAX, 0),
589 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
590 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300591 BPF_STMT(BPF_MISC | BPF_TAX, 0),
592 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
593 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
594 BPF_STMT(BPF_MISC | BPF_TAX, 0),
595 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
596 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700597 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
598 BPF_STMT(BPF_RET | BPF_A, 0)
599 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200600 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700601 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300602 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700603 },
604 {
605 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700606 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700607 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
608 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
609 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
610 BPF_STMT(BPF_MISC | BPF_TAX, 0),
611 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
612 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
613 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
614 BPF_STMT(BPF_RET | BPF_A, 0)
615 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200616 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700617 { },
618 { { 0, 0x800000ff }, { 1, 0x800000ff } },
619 },
620 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700621 "LD_IMM_0",
622 .u.insns = {
623 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
624 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
625 BPF_STMT(BPF_RET | BPF_K, 0),
626 BPF_STMT(BPF_RET | BPF_K, 1),
627 },
628 CLASSIC,
629 { },
630 { { 1, 1 } },
631 },
632 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700633 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700634 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700635 BPF_STMT(BPF_LDX | BPF_LEN, 0),
636 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
637 BPF_STMT(BPF_RET | BPF_K, 1)
638 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200639 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700640 { },
641 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
642 },
643 {
644 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700645 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700646 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
647 BPF_STMT(BPF_RET | BPF_K, 1)
648 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200649 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700650 { },
651 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
652 },
653 {
654 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700655 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700656 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
657 BPF_STMT(BPF_MISC | BPF_TAX, 0),
658 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
659 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
660 BPF_STMT(BPF_RET | BPF_A, 0)
661 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200662 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700663 { 1, 2, 3 },
664 { { 1, 0 }, { 2, 3 } },
665 },
666 {
667 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700668 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700669 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
670 BPF_STMT(BPF_LDX | BPF_LEN, 0),
671 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
672 BPF_STMT(BPF_MISC | BPF_TAX, 0),
673 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
674 BPF_STMT(BPF_RET | BPF_A, 0)
675 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200676 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700677 { 1, 2, 3, 0xff },
678 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
679 },
680 {
681 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700682 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700683 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
684 BPF_STMT(BPF_MISC | BPF_TAX, 0),
685 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
686 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
687 BPF_STMT(BPF_RET | BPF_A, 0)
688 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200689 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700690 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
691 { { 15, 0 }, { 16, 3 } },
692 },
693 {
694 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700695 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700696 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
697 BPF_STMT(BPF_LDX | BPF_LEN, 0),
698 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
699 BPF_STMT(BPF_MISC | BPF_TAX, 0),
700 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
701 BPF_STMT(BPF_RET | BPF_A, 0)
702 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200703 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700704 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
705 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
706 },
707 {
708 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700709 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700710 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
711 SKF_AD_OFF + SKF_AD_PKTTYPE),
712 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
713 BPF_STMT(BPF_RET | BPF_K, 1),
714 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
715 SKF_AD_OFF + SKF_AD_PKTTYPE),
716 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
717 BPF_STMT(BPF_RET | BPF_K, 1),
718 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
719 SKF_AD_OFF + SKF_AD_PKTTYPE),
720 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
721 BPF_STMT(BPF_RET | BPF_K, 1),
722 BPF_STMT(BPF_RET | BPF_A, 0)
723 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200724 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700725 { },
726 { { 1, 3 }, { 10, 3 } },
727 },
728 {
729 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700730 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700731 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
732 SKF_AD_OFF + SKF_AD_MARK),
733 BPF_STMT(BPF_RET | BPF_A, 0)
734 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200735 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700736 { },
737 { { 1, SKB_MARK}, { 10, SKB_MARK} },
738 },
739 {
740 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700741 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700742 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
743 SKF_AD_OFF + SKF_AD_RXHASH),
744 BPF_STMT(BPF_RET | BPF_A, 0)
745 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200746 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700747 { },
748 { { 1, SKB_HASH}, { 10, SKB_HASH} },
749 },
750 {
751 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700752 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700753 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
754 SKF_AD_OFF + SKF_AD_QUEUE),
755 BPF_STMT(BPF_RET | BPF_A, 0)
756 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200757 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700758 { },
759 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
760 },
761 {
762 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700763 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700764 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
765 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
766 BPF_STMT(BPF_RET | BPF_K, 0),
767 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
768 SKF_AD_OFF + SKF_AD_PROTOCOL),
769 BPF_STMT(BPF_MISC | BPF_TAX, 0),
770 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
771 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
772 BPF_STMT(BPF_RET | BPF_K, 0),
773 BPF_STMT(BPF_MISC | BPF_TXA, 0),
774 BPF_STMT(BPF_RET | BPF_A, 0)
775 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200776 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700777 { 10, 20, 30 },
778 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
779 },
780 {
781 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700782 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700783 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
784 SKF_AD_OFF + SKF_AD_VLAN_TAG),
785 BPF_STMT(BPF_RET | BPF_A, 0)
786 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200787 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700788 { },
789 {
790 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
791 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
792 },
793 },
794 {
795 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700796 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700797 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
798 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
799 BPF_STMT(BPF_RET | BPF_A, 0)
800 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200801 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700802 { },
803 {
804 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
805 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
806 },
807 },
808 {
809 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700810 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700811 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
812 SKF_AD_OFF + SKF_AD_IFINDEX),
813 BPF_STMT(BPF_RET | BPF_A, 0)
814 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200815 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700816 { },
817 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
818 },
819 {
820 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700821 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700822 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
823 SKF_AD_OFF + SKF_AD_HATYPE),
824 BPF_STMT(BPF_RET | BPF_A, 0)
825 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200826 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700827 { },
828 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
829 },
830 {
831 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700832 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700833 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
834 SKF_AD_OFF + SKF_AD_CPU),
835 BPF_STMT(BPF_MISC | BPF_TAX, 0),
836 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
837 SKF_AD_OFF + SKF_AD_CPU),
838 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
839 BPF_STMT(BPF_RET | BPF_A, 0)
840 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200841 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700842 { },
843 { { 1, 0 }, { 10, 0 } },
844 },
845 {
846 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700847 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700848 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700849 BPF_STMT(BPF_MISC | BPF_TXA, 0),
850 BPF_STMT(BPF_LDX | BPF_IMM, 3),
851 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
852 SKF_AD_OFF + SKF_AD_NLATTR),
853 BPF_STMT(BPF_RET | BPF_A, 0)
854 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200855 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700856#ifdef __BIG_ENDIAN
857 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
858#else
859 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
860#endif
861 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700862 },
863 {
864 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700865 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700866 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700867 BPF_STMT(BPF_LDX | BPF_IMM, 3),
868 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
869 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700870 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700871 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
872 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700873 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700874 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
875 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700876 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700877 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
878 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700879 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700880 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
881 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700882 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700883 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
884 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700885 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700886 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
887 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700888 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700889 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
890 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
891 BPF_STMT(BPF_RET | BPF_A, 0)
892 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200893 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700894#ifdef __BIG_ENDIAN
895 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
896#else
897 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
898#endif
899 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700900 },
901 {
902 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700903 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700904 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
905 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
906 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
907 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
908 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
909 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
910 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
911 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
912 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
913 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
914 BPF_STMT(BPF_RET | BPF_A, 0)
915 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200916 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700917 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
918 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
919 * id 9737, seq 1, length 64
920 */
921 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
922 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
923 0x08, 0x00,
924 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
925 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
926 { { 30, 0 }, { 100, 42 } },
927 },
928 {
929 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700930 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700931 BPF_STMT(BPF_LD | BPF_IMM, 10),
932 BPF_STMT(BPF_LDX | BPF_IMM, 300),
933 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
934 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
935 BPF_STMT(BPF_RET | BPF_A, 0)
936 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200937 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700938 { },
939 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
940 },
941 {
942 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700943 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700944 BPF_STMT(BPF_LDX | BPF_LEN, 0),
945 BPF_STMT(BPF_LD | BPF_IMM, 2),
946 BPF_STMT(BPF_ALU | BPF_RSH, 1),
947 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
948 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
949 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
950 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
951 BPF_STMT(BPF_STX, 15), /* M3 = len */
952 BPF_STMT(BPF_LDX | BPF_MEM, 1),
953 BPF_STMT(BPF_LD | BPF_MEM, 2),
954 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
955 BPF_STMT(BPF_LDX | BPF_MEM, 15),
956 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
957 BPF_STMT(BPF_RET | BPF_A, 0)
958 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200959 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700960 { },
961 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
962 },
963 {
964 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700965 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700966 BPF_STMT(BPF_LDX | BPF_LEN, 0),
967 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
968 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
969 BPF_STMT(BPF_RET | BPF_K, 1),
970 BPF_STMT(BPF_RET | BPF_K, MAX_K)
971 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200972 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700973 { 3, 3, 3, 3, 3 },
974 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
975 },
976 {
977 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700978 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700979 BPF_STMT(BPF_LDX | BPF_LEN, 0),
980 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
981 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
982 BPF_STMT(BPF_RET | BPF_K, 1),
983 BPF_STMT(BPF_RET | BPF_K, MAX_K)
984 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200985 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700986 { 4, 4, 4, 3, 3 },
987 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
988 },
989 {
Daniel Borkmann92b31a92017-08-10 01:39:55 +0200990 "JGE (jt 0), test 1",
991 .u.insns = {
992 BPF_STMT(BPF_LDX | BPF_LEN, 0),
993 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
994 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
995 BPF_STMT(BPF_RET | BPF_K, 1),
996 BPF_STMT(BPF_RET | BPF_K, MAX_K)
997 },
998 CLASSIC,
999 { 4, 4, 4, 3, 3 },
1000 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
1001 },
1002 {
1003 "JGE (jt 0), test 2",
1004 .u.insns = {
1005 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1006 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
1007 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
1008 BPF_STMT(BPF_RET | BPF_K, 1),
1009 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1010 },
1011 CLASSIC,
1012 { 4, 4, 5, 3, 3 },
1013 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
1014 },
1015 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001016 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -07001017 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001018 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1019 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
1020 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
1021 BPF_STMT(BPF_RET | BPF_K, 10),
1022 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
1023 BPF_STMT(BPF_RET | BPF_K, 20),
1024 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
1025 BPF_STMT(BPF_RET | BPF_K, 30),
1026 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
1027 BPF_STMT(BPF_RET | BPF_K, 40),
1028 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1029 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001030 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001031 { 1, 2, 3, 4, 5 },
1032 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
1033 },
1034 {
1035 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -07001036 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001037 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1038 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
1039 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1040 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
1041 BPF_STMT(BPF_LDX | BPF_LEN, 0),
1042 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1043 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
1044 BPF_STMT(BPF_MISC | BPF_TAX, 0),
1045 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
1046 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
1047 BPF_STMT(BPF_RET | BPF_K, 10),
1048 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
1049 BPF_STMT(BPF_RET | BPF_K, 20),
1050 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1051 BPF_STMT(BPF_RET | BPF_K, 30),
1052 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1053 BPF_STMT(BPF_RET | BPF_K, 30),
1054 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1055 BPF_STMT(BPF_RET | BPF_K, 30),
1056 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1057 BPF_STMT(BPF_RET | BPF_K, 30),
1058 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
1059 BPF_STMT(BPF_RET | BPF_K, 30),
1060 BPF_STMT(BPF_RET | BPF_K, MAX_K)
1061 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001062 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001063 { 0, 0xAA, 0x55, 1 },
1064 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
1065 },
1066 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001067 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -07001068 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +02001069 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1070 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1071 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1072 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1073 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1074 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1075 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1076 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1077 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1078 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1079 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1080 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1081 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1082 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1083 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1084 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1085 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1086 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1087 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1088 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1089 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1090 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1091 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1092 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001093 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001094 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001095 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1096 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1097 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1098 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1099 */
1100 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1101 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1102 0x08, 0x00,
1103 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1104 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1105 0x0a, 0x01, 0x01, 0x95, /* ip src */
1106 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1107 0xc2, 0x24,
1108 0x00, 0x16 /* dst port */ },
1109 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1110 },
1111 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001112 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -07001113 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001114 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1115 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1116 * (len > 115 or len < 30000000000)' -d
1117 */
Daniel Borkmannce25b682014-05-26 20:17:35 +02001118 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1119 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1120 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1121 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1122 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1123 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1124 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1125 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1126 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1127 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1128 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1129 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1130 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1131 BPF_STMT(BPF_ST, 1),
1132 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1133 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1134 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1135 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1136 BPF_STMT(BPF_LD | BPF_MEM, 1),
1137 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1138 BPF_STMT(BPF_ST, 5),
1139 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1140 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1141 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1142 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1143 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1144 BPF_STMT(BPF_LD | BPF_MEM, 5),
1145 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1146 BPF_STMT(BPF_LD | BPF_LEN, 0),
1147 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1148 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1149 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1150 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001151 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001152 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001153 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1154 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1155 0x08, 0x00,
1156 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1157 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1158 0x0a, 0x01, 0x01, 0x95, /* ip src */
1159 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1160 0xc2, 0x24,
1161 0x00, 0x16 /* dst port */ },
1162 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1163 },
1164 {
1165 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -07001166 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001167 /* check that unitialized X and A contain zeros */
1168 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1169 BPF_STMT(BPF_RET | BPF_A, 0)
1170 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001171 CLASSIC,
1172 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001173 { {1, 0}, {2, 0} },
1174 },
1175 {
1176 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -07001177 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001178 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1179 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1180 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1181 BPF_ALU64_REG(BPF_SUB, R1, R2),
1182 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1183 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1184 BPF_ALU64_REG(BPF_MOV, R0, R1),
1185 BPF_EXIT_INSN(),
1186 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001187 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001188 { },
1189 { { 0, 0xfffffffd } }
1190 },
1191 {
1192 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001193 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001194 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1195 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1196 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1197 BPF_ALU64_REG(BPF_MUL, R1, R2),
1198 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1199 BPF_EXIT_INSN(),
1200 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1201 BPF_EXIT_INSN(),
1202 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001203 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001204 { },
1205 { { 0, 1 } }
1206 },
1207 {
1208 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -07001209 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001210 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1211 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1212 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1213 BPF_ALU64_REG(BPF_MUL, R1, R2),
1214 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1215 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1216 BPF_EXIT_INSN(),
1217 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1218 BPF_EXIT_INSN(),
1219 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001220 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001221 { },
1222 { { 0, 1 } }
1223 },
1224 {
1225 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001226 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001227 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1228 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1229 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1230 BPF_ALU32_REG(BPF_MUL, R1, R2),
1231 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1232 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1233 BPF_EXIT_INSN(),
1234 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1235 BPF_EXIT_INSN(),
1236 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001237 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001238 { },
1239 { { 0, 1 } }
1240 },
1241 {
1242 /* Have to test all register combinations, since
1243 * JITing of different registers will produce
1244 * different asm code.
1245 */
1246 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001247 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001248 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1249 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1250 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1251 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1252 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1253 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1254 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1255 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1256 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1257 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1258 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1259 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1260 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1261 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1262 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1263 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1264 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1265 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1266 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1267 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1268 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1269 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1270 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1271 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1272 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1273 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1274 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1275 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1276 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1277 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1278 BPF_ALU64_REG(BPF_ADD, R0, R0),
1279 BPF_ALU64_REG(BPF_ADD, R0, R1),
1280 BPF_ALU64_REG(BPF_ADD, R0, R2),
1281 BPF_ALU64_REG(BPF_ADD, R0, R3),
1282 BPF_ALU64_REG(BPF_ADD, R0, R4),
1283 BPF_ALU64_REG(BPF_ADD, R0, R5),
1284 BPF_ALU64_REG(BPF_ADD, R0, R6),
1285 BPF_ALU64_REG(BPF_ADD, R0, R7),
1286 BPF_ALU64_REG(BPF_ADD, R0, R8),
1287 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1288 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1289 BPF_EXIT_INSN(),
1290 BPF_ALU64_REG(BPF_ADD, R1, R0),
1291 BPF_ALU64_REG(BPF_ADD, R1, R1),
1292 BPF_ALU64_REG(BPF_ADD, R1, R2),
1293 BPF_ALU64_REG(BPF_ADD, R1, R3),
1294 BPF_ALU64_REG(BPF_ADD, R1, R4),
1295 BPF_ALU64_REG(BPF_ADD, R1, R5),
1296 BPF_ALU64_REG(BPF_ADD, R1, R6),
1297 BPF_ALU64_REG(BPF_ADD, R1, R7),
1298 BPF_ALU64_REG(BPF_ADD, R1, R8),
1299 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1300 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1301 BPF_EXIT_INSN(),
1302 BPF_ALU64_REG(BPF_ADD, R2, R0),
1303 BPF_ALU64_REG(BPF_ADD, R2, R1),
1304 BPF_ALU64_REG(BPF_ADD, R2, R2),
1305 BPF_ALU64_REG(BPF_ADD, R2, R3),
1306 BPF_ALU64_REG(BPF_ADD, R2, R4),
1307 BPF_ALU64_REG(BPF_ADD, R2, R5),
1308 BPF_ALU64_REG(BPF_ADD, R2, R6),
1309 BPF_ALU64_REG(BPF_ADD, R2, R7),
1310 BPF_ALU64_REG(BPF_ADD, R2, R8),
1311 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1312 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1313 BPF_EXIT_INSN(),
1314 BPF_ALU64_REG(BPF_ADD, R3, R0),
1315 BPF_ALU64_REG(BPF_ADD, R3, R1),
1316 BPF_ALU64_REG(BPF_ADD, R3, R2),
1317 BPF_ALU64_REG(BPF_ADD, R3, R3),
1318 BPF_ALU64_REG(BPF_ADD, R3, R4),
1319 BPF_ALU64_REG(BPF_ADD, R3, R5),
1320 BPF_ALU64_REG(BPF_ADD, R3, R6),
1321 BPF_ALU64_REG(BPF_ADD, R3, R7),
1322 BPF_ALU64_REG(BPF_ADD, R3, R8),
1323 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1324 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1325 BPF_EXIT_INSN(),
1326 BPF_ALU64_REG(BPF_ADD, R4, R0),
1327 BPF_ALU64_REG(BPF_ADD, R4, R1),
1328 BPF_ALU64_REG(BPF_ADD, R4, R2),
1329 BPF_ALU64_REG(BPF_ADD, R4, R3),
1330 BPF_ALU64_REG(BPF_ADD, R4, R4),
1331 BPF_ALU64_REG(BPF_ADD, R4, R5),
1332 BPF_ALU64_REG(BPF_ADD, R4, R6),
1333 BPF_ALU64_REG(BPF_ADD, R4, R7),
1334 BPF_ALU64_REG(BPF_ADD, R4, R8),
1335 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1336 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1337 BPF_EXIT_INSN(),
1338 BPF_ALU64_REG(BPF_ADD, R5, R0),
1339 BPF_ALU64_REG(BPF_ADD, R5, R1),
1340 BPF_ALU64_REG(BPF_ADD, R5, R2),
1341 BPF_ALU64_REG(BPF_ADD, R5, R3),
1342 BPF_ALU64_REG(BPF_ADD, R5, R4),
1343 BPF_ALU64_REG(BPF_ADD, R5, R5),
1344 BPF_ALU64_REG(BPF_ADD, R5, R6),
1345 BPF_ALU64_REG(BPF_ADD, R5, R7),
1346 BPF_ALU64_REG(BPF_ADD, R5, R8),
1347 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1348 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1349 BPF_EXIT_INSN(),
1350 BPF_ALU64_REG(BPF_ADD, R6, R0),
1351 BPF_ALU64_REG(BPF_ADD, R6, R1),
1352 BPF_ALU64_REG(BPF_ADD, R6, R2),
1353 BPF_ALU64_REG(BPF_ADD, R6, R3),
1354 BPF_ALU64_REG(BPF_ADD, R6, R4),
1355 BPF_ALU64_REG(BPF_ADD, R6, R5),
1356 BPF_ALU64_REG(BPF_ADD, R6, R6),
1357 BPF_ALU64_REG(BPF_ADD, R6, R7),
1358 BPF_ALU64_REG(BPF_ADD, R6, R8),
1359 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1360 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1361 BPF_EXIT_INSN(),
1362 BPF_ALU64_REG(BPF_ADD, R7, R0),
1363 BPF_ALU64_REG(BPF_ADD, R7, R1),
1364 BPF_ALU64_REG(BPF_ADD, R7, R2),
1365 BPF_ALU64_REG(BPF_ADD, R7, R3),
1366 BPF_ALU64_REG(BPF_ADD, R7, R4),
1367 BPF_ALU64_REG(BPF_ADD, R7, R5),
1368 BPF_ALU64_REG(BPF_ADD, R7, R6),
1369 BPF_ALU64_REG(BPF_ADD, R7, R7),
1370 BPF_ALU64_REG(BPF_ADD, R7, R8),
1371 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1372 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1373 BPF_EXIT_INSN(),
1374 BPF_ALU64_REG(BPF_ADD, R8, R0),
1375 BPF_ALU64_REG(BPF_ADD, R8, R1),
1376 BPF_ALU64_REG(BPF_ADD, R8, R2),
1377 BPF_ALU64_REG(BPF_ADD, R8, R3),
1378 BPF_ALU64_REG(BPF_ADD, R8, R4),
1379 BPF_ALU64_REG(BPF_ADD, R8, R5),
1380 BPF_ALU64_REG(BPF_ADD, R8, R6),
1381 BPF_ALU64_REG(BPF_ADD, R8, R7),
1382 BPF_ALU64_REG(BPF_ADD, R8, R8),
1383 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1384 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1385 BPF_EXIT_INSN(),
1386 BPF_ALU64_REG(BPF_ADD, R9, R0),
1387 BPF_ALU64_REG(BPF_ADD, R9, R1),
1388 BPF_ALU64_REG(BPF_ADD, R9, R2),
1389 BPF_ALU64_REG(BPF_ADD, R9, R3),
1390 BPF_ALU64_REG(BPF_ADD, R9, R4),
1391 BPF_ALU64_REG(BPF_ADD, R9, R5),
1392 BPF_ALU64_REG(BPF_ADD, R9, R6),
1393 BPF_ALU64_REG(BPF_ADD, R9, R7),
1394 BPF_ALU64_REG(BPF_ADD, R9, R8),
1395 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1396 BPF_ALU64_REG(BPF_MOV, R0, R9),
1397 BPF_EXIT_INSN(),
1398 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001399 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001400 { },
1401 { { 0, 2957380 } }
1402 },
1403 {
1404 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001405 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001406 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1407 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1408 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1409 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1410 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1411 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1412 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1413 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1414 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1415 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1416 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1417 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1418 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1419 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1420 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1421 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1422 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1423 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1424 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1425 BPF_ALU32_REG(BPF_ADD, R0, R1),
1426 BPF_ALU32_REG(BPF_ADD, R0, R2),
1427 BPF_ALU32_REG(BPF_ADD, R0, R3),
1428 BPF_ALU32_REG(BPF_ADD, R0, R4),
1429 BPF_ALU32_REG(BPF_ADD, R0, R5),
1430 BPF_ALU32_REG(BPF_ADD, R0, R6),
1431 BPF_ALU32_REG(BPF_ADD, R0, R7),
1432 BPF_ALU32_REG(BPF_ADD, R0, R8),
1433 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1434 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1435 BPF_EXIT_INSN(),
1436 BPF_ALU32_REG(BPF_ADD, R1, R0),
1437 BPF_ALU32_REG(BPF_ADD, R1, R1),
1438 BPF_ALU32_REG(BPF_ADD, R1, R2),
1439 BPF_ALU32_REG(BPF_ADD, R1, R3),
1440 BPF_ALU32_REG(BPF_ADD, R1, R4),
1441 BPF_ALU32_REG(BPF_ADD, R1, R5),
1442 BPF_ALU32_REG(BPF_ADD, R1, R6),
1443 BPF_ALU32_REG(BPF_ADD, R1, R7),
1444 BPF_ALU32_REG(BPF_ADD, R1, R8),
1445 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1446 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1447 BPF_EXIT_INSN(),
1448 BPF_ALU32_REG(BPF_ADD, R2, R0),
1449 BPF_ALU32_REG(BPF_ADD, R2, R1),
1450 BPF_ALU32_REG(BPF_ADD, R2, R2),
1451 BPF_ALU32_REG(BPF_ADD, R2, R3),
1452 BPF_ALU32_REG(BPF_ADD, R2, R4),
1453 BPF_ALU32_REG(BPF_ADD, R2, R5),
1454 BPF_ALU32_REG(BPF_ADD, R2, R6),
1455 BPF_ALU32_REG(BPF_ADD, R2, R7),
1456 BPF_ALU32_REG(BPF_ADD, R2, R8),
1457 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1458 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1459 BPF_EXIT_INSN(),
1460 BPF_ALU32_REG(BPF_ADD, R3, R0),
1461 BPF_ALU32_REG(BPF_ADD, R3, R1),
1462 BPF_ALU32_REG(BPF_ADD, R3, R2),
1463 BPF_ALU32_REG(BPF_ADD, R3, R3),
1464 BPF_ALU32_REG(BPF_ADD, R3, R4),
1465 BPF_ALU32_REG(BPF_ADD, R3, R5),
1466 BPF_ALU32_REG(BPF_ADD, R3, R6),
1467 BPF_ALU32_REG(BPF_ADD, R3, R7),
1468 BPF_ALU32_REG(BPF_ADD, R3, R8),
1469 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1470 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1471 BPF_EXIT_INSN(),
1472 BPF_ALU32_REG(BPF_ADD, R4, R0),
1473 BPF_ALU32_REG(BPF_ADD, R4, R1),
1474 BPF_ALU32_REG(BPF_ADD, R4, R2),
1475 BPF_ALU32_REG(BPF_ADD, R4, R3),
1476 BPF_ALU32_REG(BPF_ADD, R4, R4),
1477 BPF_ALU32_REG(BPF_ADD, R4, R5),
1478 BPF_ALU32_REG(BPF_ADD, R4, R6),
1479 BPF_ALU32_REG(BPF_ADD, R4, R7),
1480 BPF_ALU32_REG(BPF_ADD, R4, R8),
1481 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1482 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1483 BPF_EXIT_INSN(),
1484 BPF_ALU32_REG(BPF_ADD, R5, R0),
1485 BPF_ALU32_REG(BPF_ADD, R5, R1),
1486 BPF_ALU32_REG(BPF_ADD, R5, R2),
1487 BPF_ALU32_REG(BPF_ADD, R5, R3),
1488 BPF_ALU32_REG(BPF_ADD, R5, R4),
1489 BPF_ALU32_REG(BPF_ADD, R5, R5),
1490 BPF_ALU32_REG(BPF_ADD, R5, R6),
1491 BPF_ALU32_REG(BPF_ADD, R5, R7),
1492 BPF_ALU32_REG(BPF_ADD, R5, R8),
1493 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1494 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1495 BPF_EXIT_INSN(),
1496 BPF_ALU32_REG(BPF_ADD, R6, R0),
1497 BPF_ALU32_REG(BPF_ADD, R6, R1),
1498 BPF_ALU32_REG(BPF_ADD, R6, R2),
1499 BPF_ALU32_REG(BPF_ADD, R6, R3),
1500 BPF_ALU32_REG(BPF_ADD, R6, R4),
1501 BPF_ALU32_REG(BPF_ADD, R6, R5),
1502 BPF_ALU32_REG(BPF_ADD, R6, R6),
1503 BPF_ALU32_REG(BPF_ADD, R6, R7),
1504 BPF_ALU32_REG(BPF_ADD, R6, R8),
1505 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1506 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1507 BPF_EXIT_INSN(),
1508 BPF_ALU32_REG(BPF_ADD, R7, R0),
1509 BPF_ALU32_REG(BPF_ADD, R7, R1),
1510 BPF_ALU32_REG(BPF_ADD, R7, R2),
1511 BPF_ALU32_REG(BPF_ADD, R7, R3),
1512 BPF_ALU32_REG(BPF_ADD, R7, R4),
1513 BPF_ALU32_REG(BPF_ADD, R7, R5),
1514 BPF_ALU32_REG(BPF_ADD, R7, R6),
1515 BPF_ALU32_REG(BPF_ADD, R7, R7),
1516 BPF_ALU32_REG(BPF_ADD, R7, R8),
1517 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1518 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1519 BPF_EXIT_INSN(),
1520 BPF_ALU32_REG(BPF_ADD, R8, R0),
1521 BPF_ALU32_REG(BPF_ADD, R8, R1),
1522 BPF_ALU32_REG(BPF_ADD, R8, R2),
1523 BPF_ALU32_REG(BPF_ADD, R8, R3),
1524 BPF_ALU32_REG(BPF_ADD, R8, R4),
1525 BPF_ALU32_REG(BPF_ADD, R8, R5),
1526 BPF_ALU32_REG(BPF_ADD, R8, R6),
1527 BPF_ALU32_REG(BPF_ADD, R8, R7),
1528 BPF_ALU32_REG(BPF_ADD, R8, R8),
1529 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1530 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1531 BPF_EXIT_INSN(),
1532 BPF_ALU32_REG(BPF_ADD, R9, R0),
1533 BPF_ALU32_REG(BPF_ADD, R9, R1),
1534 BPF_ALU32_REG(BPF_ADD, R9, R2),
1535 BPF_ALU32_REG(BPF_ADD, R9, R3),
1536 BPF_ALU32_REG(BPF_ADD, R9, R4),
1537 BPF_ALU32_REG(BPF_ADD, R9, R5),
1538 BPF_ALU32_REG(BPF_ADD, R9, R6),
1539 BPF_ALU32_REG(BPF_ADD, R9, R7),
1540 BPF_ALU32_REG(BPF_ADD, R9, R8),
1541 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1542 BPF_ALU32_REG(BPF_MOV, R0, R9),
1543 BPF_EXIT_INSN(),
1544 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001545 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001546 { },
1547 { { 0, 2957380 } }
1548 },
1549 { /* Mainly checking JIT here. */
1550 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001551 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001552 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1553 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1554 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1555 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1556 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1557 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1558 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1559 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1560 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1561 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1562 BPF_ALU64_REG(BPF_SUB, R0, R0),
1563 BPF_ALU64_REG(BPF_SUB, R0, R1),
1564 BPF_ALU64_REG(BPF_SUB, R0, R2),
1565 BPF_ALU64_REG(BPF_SUB, R0, R3),
1566 BPF_ALU64_REG(BPF_SUB, R0, R4),
1567 BPF_ALU64_REG(BPF_SUB, R0, R5),
1568 BPF_ALU64_REG(BPF_SUB, R0, R6),
1569 BPF_ALU64_REG(BPF_SUB, R0, R7),
1570 BPF_ALU64_REG(BPF_SUB, R0, R8),
1571 BPF_ALU64_REG(BPF_SUB, R0, R9),
1572 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1573 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1574 BPF_EXIT_INSN(),
1575 BPF_ALU64_REG(BPF_SUB, R1, R0),
1576 BPF_ALU64_REG(BPF_SUB, R1, R2),
1577 BPF_ALU64_REG(BPF_SUB, R1, R3),
1578 BPF_ALU64_REG(BPF_SUB, R1, R4),
1579 BPF_ALU64_REG(BPF_SUB, R1, R5),
1580 BPF_ALU64_REG(BPF_SUB, R1, R6),
1581 BPF_ALU64_REG(BPF_SUB, R1, R7),
1582 BPF_ALU64_REG(BPF_SUB, R1, R8),
1583 BPF_ALU64_REG(BPF_SUB, R1, R9),
1584 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1585 BPF_ALU64_REG(BPF_SUB, R2, R0),
1586 BPF_ALU64_REG(BPF_SUB, R2, R1),
1587 BPF_ALU64_REG(BPF_SUB, R2, R3),
1588 BPF_ALU64_REG(BPF_SUB, R2, R4),
1589 BPF_ALU64_REG(BPF_SUB, R2, R5),
1590 BPF_ALU64_REG(BPF_SUB, R2, R6),
1591 BPF_ALU64_REG(BPF_SUB, R2, R7),
1592 BPF_ALU64_REG(BPF_SUB, R2, R8),
1593 BPF_ALU64_REG(BPF_SUB, R2, R9),
1594 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1595 BPF_ALU64_REG(BPF_SUB, R3, R0),
1596 BPF_ALU64_REG(BPF_SUB, R3, R1),
1597 BPF_ALU64_REG(BPF_SUB, R3, R2),
1598 BPF_ALU64_REG(BPF_SUB, R3, R4),
1599 BPF_ALU64_REG(BPF_SUB, R3, R5),
1600 BPF_ALU64_REG(BPF_SUB, R3, R6),
1601 BPF_ALU64_REG(BPF_SUB, R3, R7),
1602 BPF_ALU64_REG(BPF_SUB, R3, R8),
1603 BPF_ALU64_REG(BPF_SUB, R3, R9),
1604 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1605 BPF_ALU64_REG(BPF_SUB, R4, R0),
1606 BPF_ALU64_REG(BPF_SUB, R4, R1),
1607 BPF_ALU64_REG(BPF_SUB, R4, R2),
1608 BPF_ALU64_REG(BPF_SUB, R4, R3),
1609 BPF_ALU64_REG(BPF_SUB, R4, R5),
1610 BPF_ALU64_REG(BPF_SUB, R4, R6),
1611 BPF_ALU64_REG(BPF_SUB, R4, R7),
1612 BPF_ALU64_REG(BPF_SUB, R4, R8),
1613 BPF_ALU64_REG(BPF_SUB, R4, R9),
1614 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1615 BPF_ALU64_REG(BPF_SUB, R5, R0),
1616 BPF_ALU64_REG(BPF_SUB, R5, R1),
1617 BPF_ALU64_REG(BPF_SUB, R5, R2),
1618 BPF_ALU64_REG(BPF_SUB, R5, R3),
1619 BPF_ALU64_REG(BPF_SUB, R5, R4),
1620 BPF_ALU64_REG(BPF_SUB, R5, R6),
1621 BPF_ALU64_REG(BPF_SUB, R5, R7),
1622 BPF_ALU64_REG(BPF_SUB, R5, R8),
1623 BPF_ALU64_REG(BPF_SUB, R5, R9),
1624 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1625 BPF_ALU64_REG(BPF_SUB, R6, R0),
1626 BPF_ALU64_REG(BPF_SUB, R6, R1),
1627 BPF_ALU64_REG(BPF_SUB, R6, R2),
1628 BPF_ALU64_REG(BPF_SUB, R6, R3),
1629 BPF_ALU64_REG(BPF_SUB, R6, R4),
1630 BPF_ALU64_REG(BPF_SUB, R6, R5),
1631 BPF_ALU64_REG(BPF_SUB, R6, R7),
1632 BPF_ALU64_REG(BPF_SUB, R6, R8),
1633 BPF_ALU64_REG(BPF_SUB, R6, R9),
1634 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1635 BPF_ALU64_REG(BPF_SUB, R7, R0),
1636 BPF_ALU64_REG(BPF_SUB, R7, R1),
1637 BPF_ALU64_REG(BPF_SUB, R7, R2),
1638 BPF_ALU64_REG(BPF_SUB, R7, R3),
1639 BPF_ALU64_REG(BPF_SUB, R7, R4),
1640 BPF_ALU64_REG(BPF_SUB, R7, R5),
1641 BPF_ALU64_REG(BPF_SUB, R7, R6),
1642 BPF_ALU64_REG(BPF_SUB, R7, R8),
1643 BPF_ALU64_REG(BPF_SUB, R7, R9),
1644 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1645 BPF_ALU64_REG(BPF_SUB, R8, R0),
1646 BPF_ALU64_REG(BPF_SUB, R8, R1),
1647 BPF_ALU64_REG(BPF_SUB, R8, R2),
1648 BPF_ALU64_REG(BPF_SUB, R8, R3),
1649 BPF_ALU64_REG(BPF_SUB, R8, R4),
1650 BPF_ALU64_REG(BPF_SUB, R8, R5),
1651 BPF_ALU64_REG(BPF_SUB, R8, R6),
1652 BPF_ALU64_REG(BPF_SUB, R8, R7),
1653 BPF_ALU64_REG(BPF_SUB, R8, R9),
1654 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1655 BPF_ALU64_REG(BPF_SUB, R9, R0),
1656 BPF_ALU64_REG(BPF_SUB, R9, R1),
1657 BPF_ALU64_REG(BPF_SUB, R9, R2),
1658 BPF_ALU64_REG(BPF_SUB, R9, R3),
1659 BPF_ALU64_REG(BPF_SUB, R9, R4),
1660 BPF_ALU64_REG(BPF_SUB, R9, R5),
1661 BPF_ALU64_REG(BPF_SUB, R9, R6),
1662 BPF_ALU64_REG(BPF_SUB, R9, R7),
1663 BPF_ALU64_REG(BPF_SUB, R9, R8),
1664 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1665 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1666 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1667 BPF_ALU64_REG(BPF_SUB, R0, R1),
1668 BPF_ALU64_REG(BPF_SUB, R0, R2),
1669 BPF_ALU64_REG(BPF_SUB, R0, R3),
1670 BPF_ALU64_REG(BPF_SUB, R0, R4),
1671 BPF_ALU64_REG(BPF_SUB, R0, R5),
1672 BPF_ALU64_REG(BPF_SUB, R0, R6),
1673 BPF_ALU64_REG(BPF_SUB, R0, R7),
1674 BPF_ALU64_REG(BPF_SUB, R0, R8),
1675 BPF_ALU64_REG(BPF_SUB, R0, R9),
1676 BPF_EXIT_INSN(),
1677 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001678 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001679 { },
1680 { { 0, 11 } }
1681 },
1682 { /* Mainly checking JIT here. */
1683 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001684 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001685 BPF_ALU64_REG(BPF_SUB, R0, R0),
1686 BPF_ALU64_REG(BPF_XOR, R1, R1),
1687 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1688 BPF_EXIT_INSN(),
1689 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1690 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1691 BPF_ALU64_REG(BPF_SUB, R1, R1),
1692 BPF_ALU64_REG(BPF_XOR, R2, R2),
1693 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1694 BPF_EXIT_INSN(),
1695 BPF_ALU64_REG(BPF_SUB, R2, R2),
1696 BPF_ALU64_REG(BPF_XOR, R3, R3),
1697 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1698 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1699 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1700 BPF_EXIT_INSN(),
1701 BPF_ALU64_REG(BPF_SUB, R3, R3),
1702 BPF_ALU64_REG(BPF_XOR, R4, R4),
1703 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1704 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1705 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1706 BPF_EXIT_INSN(),
1707 BPF_ALU64_REG(BPF_SUB, R4, R4),
1708 BPF_ALU64_REG(BPF_XOR, R5, R5),
1709 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1710 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1711 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1712 BPF_EXIT_INSN(),
1713 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1714 BPF_ALU64_REG(BPF_SUB, R5, R5),
1715 BPF_ALU64_REG(BPF_XOR, R6, R6),
1716 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1717 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1718 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1719 BPF_EXIT_INSN(),
1720 BPF_ALU64_REG(BPF_SUB, R6, R6),
1721 BPF_ALU64_REG(BPF_XOR, R7, R7),
1722 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1723 BPF_EXIT_INSN(),
1724 BPF_ALU64_REG(BPF_SUB, R7, R7),
1725 BPF_ALU64_REG(BPF_XOR, R8, R8),
1726 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1727 BPF_EXIT_INSN(),
1728 BPF_ALU64_REG(BPF_SUB, R8, R8),
1729 BPF_ALU64_REG(BPF_XOR, R9, R9),
1730 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1731 BPF_EXIT_INSN(),
1732 BPF_ALU64_REG(BPF_SUB, R9, R9),
1733 BPF_ALU64_REG(BPF_XOR, R0, R0),
1734 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1735 BPF_EXIT_INSN(),
1736 BPF_ALU64_REG(BPF_SUB, R1, R1),
1737 BPF_ALU64_REG(BPF_XOR, R0, R0),
1738 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1739 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1740 BPF_EXIT_INSN(),
1741 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1742 BPF_EXIT_INSN(),
1743 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001744 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001745 { },
1746 { { 0, 1 } }
1747 },
1748 { /* Mainly checking JIT here. */
1749 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001750 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001751 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1752 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1753 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1754 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1755 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1756 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1757 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1758 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1759 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1760 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1761 BPF_ALU64_REG(BPF_MUL, R0, R0),
1762 BPF_ALU64_REG(BPF_MUL, R0, R1),
1763 BPF_ALU64_REG(BPF_MUL, R0, R2),
1764 BPF_ALU64_REG(BPF_MUL, R0, R3),
1765 BPF_ALU64_REG(BPF_MUL, R0, R4),
1766 BPF_ALU64_REG(BPF_MUL, R0, R5),
1767 BPF_ALU64_REG(BPF_MUL, R0, R6),
1768 BPF_ALU64_REG(BPF_MUL, R0, R7),
1769 BPF_ALU64_REG(BPF_MUL, R0, R8),
1770 BPF_ALU64_REG(BPF_MUL, R0, R9),
1771 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1772 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1773 BPF_EXIT_INSN(),
1774 BPF_ALU64_REG(BPF_MUL, R1, R0),
1775 BPF_ALU64_REG(BPF_MUL, R1, R2),
1776 BPF_ALU64_REG(BPF_MUL, R1, R3),
1777 BPF_ALU64_REG(BPF_MUL, R1, R4),
1778 BPF_ALU64_REG(BPF_MUL, R1, R5),
1779 BPF_ALU64_REG(BPF_MUL, R1, R6),
1780 BPF_ALU64_REG(BPF_MUL, R1, R7),
1781 BPF_ALU64_REG(BPF_MUL, R1, R8),
1782 BPF_ALU64_REG(BPF_MUL, R1, R9),
1783 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1784 BPF_ALU64_REG(BPF_MOV, R2, R1),
1785 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1786 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1787 BPF_EXIT_INSN(),
1788 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1789 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1790 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1791 BPF_EXIT_INSN(),
1792 BPF_ALU64_REG(BPF_MUL, R2, R0),
1793 BPF_ALU64_REG(BPF_MUL, R2, R1),
1794 BPF_ALU64_REG(BPF_MUL, R2, R3),
1795 BPF_ALU64_REG(BPF_MUL, R2, R4),
1796 BPF_ALU64_REG(BPF_MUL, R2, R5),
1797 BPF_ALU64_REG(BPF_MUL, R2, R6),
1798 BPF_ALU64_REG(BPF_MUL, R2, R7),
1799 BPF_ALU64_REG(BPF_MUL, R2, R8),
1800 BPF_ALU64_REG(BPF_MUL, R2, R9),
1801 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1802 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1803 BPF_ALU64_REG(BPF_MOV, R0, R2),
1804 BPF_EXIT_INSN(),
1805 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001806 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001807 { },
1808 { { 0, 0x35d97ef2 } }
1809 },
Daniel Borkmann9dd2af82015-12-17 23:51:57 +01001810 { /* Mainly checking JIT here. */
1811 "MOV REG64",
1812 .u.insns_int = {
1813 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1814 BPF_MOV64_REG(R1, R0),
1815 BPF_MOV64_REG(R2, R1),
1816 BPF_MOV64_REG(R3, R2),
1817 BPF_MOV64_REG(R4, R3),
1818 BPF_MOV64_REG(R5, R4),
1819 BPF_MOV64_REG(R6, R5),
1820 BPF_MOV64_REG(R7, R6),
1821 BPF_MOV64_REG(R8, R7),
1822 BPF_MOV64_REG(R9, R8),
1823 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1824 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1825 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1826 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1827 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1828 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1829 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1830 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1831 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1832 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1833 BPF_ALU64_REG(BPF_ADD, R0, R0),
1834 BPF_ALU64_REG(BPF_ADD, R0, R1),
1835 BPF_ALU64_REG(BPF_ADD, R0, R2),
1836 BPF_ALU64_REG(BPF_ADD, R0, R3),
1837 BPF_ALU64_REG(BPF_ADD, R0, R4),
1838 BPF_ALU64_REG(BPF_ADD, R0, R5),
1839 BPF_ALU64_REG(BPF_ADD, R0, R6),
1840 BPF_ALU64_REG(BPF_ADD, R0, R7),
1841 BPF_ALU64_REG(BPF_ADD, R0, R8),
1842 BPF_ALU64_REG(BPF_ADD, R0, R9),
1843 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1844 BPF_EXIT_INSN(),
1845 },
1846 INTERNAL,
1847 { },
1848 { { 0, 0xfefe } }
1849 },
1850 { /* Mainly checking JIT here. */
1851 "MOV REG32",
1852 .u.insns_int = {
1853 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1854 BPF_MOV64_REG(R1, R0),
1855 BPF_MOV64_REG(R2, R1),
1856 BPF_MOV64_REG(R3, R2),
1857 BPF_MOV64_REG(R4, R3),
1858 BPF_MOV64_REG(R5, R4),
1859 BPF_MOV64_REG(R6, R5),
1860 BPF_MOV64_REG(R7, R6),
1861 BPF_MOV64_REG(R8, R7),
1862 BPF_MOV64_REG(R9, R8),
1863 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1864 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1865 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1866 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1867 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1868 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1869 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1870 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1871 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1872 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1873 BPF_ALU64_REG(BPF_ADD, R0, R0),
1874 BPF_ALU64_REG(BPF_ADD, R0, R1),
1875 BPF_ALU64_REG(BPF_ADD, R0, R2),
1876 BPF_ALU64_REG(BPF_ADD, R0, R3),
1877 BPF_ALU64_REG(BPF_ADD, R0, R4),
1878 BPF_ALU64_REG(BPF_ADD, R0, R5),
1879 BPF_ALU64_REG(BPF_ADD, R0, R6),
1880 BPF_ALU64_REG(BPF_ADD, R0, R7),
1881 BPF_ALU64_REG(BPF_ADD, R0, R8),
1882 BPF_ALU64_REG(BPF_ADD, R0, R9),
1883 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1884 BPF_EXIT_INSN(),
1885 },
1886 INTERNAL,
1887 { },
1888 { { 0, 0xfefe } }
1889 },
1890 { /* Mainly checking JIT here. */
1891 "LD IMM64",
1892 .u.insns_int = {
1893 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1894 BPF_MOV64_REG(R1, R0),
1895 BPF_MOV64_REG(R2, R1),
1896 BPF_MOV64_REG(R3, R2),
1897 BPF_MOV64_REG(R4, R3),
1898 BPF_MOV64_REG(R5, R4),
1899 BPF_MOV64_REG(R6, R5),
1900 BPF_MOV64_REG(R7, R6),
1901 BPF_MOV64_REG(R8, R7),
1902 BPF_MOV64_REG(R9, R8),
1903 BPF_LD_IMM64(R0, 0x0LL),
1904 BPF_LD_IMM64(R1, 0x0LL),
1905 BPF_LD_IMM64(R2, 0x0LL),
1906 BPF_LD_IMM64(R3, 0x0LL),
1907 BPF_LD_IMM64(R4, 0x0LL),
1908 BPF_LD_IMM64(R5, 0x0LL),
1909 BPF_LD_IMM64(R6, 0x0LL),
1910 BPF_LD_IMM64(R7, 0x0LL),
1911 BPF_LD_IMM64(R8, 0x0LL),
1912 BPF_LD_IMM64(R9, 0x0LL),
1913 BPF_ALU64_REG(BPF_ADD, R0, R0),
1914 BPF_ALU64_REG(BPF_ADD, R0, R1),
1915 BPF_ALU64_REG(BPF_ADD, R0, R2),
1916 BPF_ALU64_REG(BPF_ADD, R0, R3),
1917 BPF_ALU64_REG(BPF_ADD, R0, R4),
1918 BPF_ALU64_REG(BPF_ADD, R0, R5),
1919 BPF_ALU64_REG(BPF_ADD, R0, R6),
1920 BPF_ALU64_REG(BPF_ADD, R0, R7),
1921 BPF_ALU64_REG(BPF_ADD, R0, R8),
1922 BPF_ALU64_REG(BPF_ADD, R0, R9),
1923 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1924 BPF_EXIT_INSN(),
1925 },
1926 INTERNAL,
1927 { },
1928 { { 0, 0xfefe } }
1929 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001930 {
1931 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001932 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001933 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1934 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1935 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1936 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1937 BPF_ALU64_REG(BPF_DIV, R0, R2),
1938 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1939 BPF_EXIT_INSN(),
1940 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1941 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1942 BPF_EXIT_INSN(),
1943 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1944 BPF_EXIT_INSN(),
1945 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001946 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001947 { },
1948 { { 0, -1 } }
1949 },
1950 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001951 "INT: shifts by register",
1952 .u.insns_int = {
1953 BPF_MOV64_IMM(R0, -1234),
1954 BPF_MOV64_IMM(R1, 1),
1955 BPF_ALU32_REG(BPF_RSH, R0, R1),
1956 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1957 BPF_EXIT_INSN(),
1958 BPF_MOV64_IMM(R2, 1),
1959 BPF_ALU64_REG(BPF_LSH, R0, R2),
1960 BPF_MOV32_IMM(R4, -1234),
1961 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1962 BPF_EXIT_INSN(),
1963 BPF_ALU64_IMM(BPF_AND, R4, 63),
1964 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1965 BPF_MOV64_IMM(R3, 47),
1966 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1967 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1968 BPF_EXIT_INSN(),
1969 BPF_MOV64_IMM(R2, 1),
1970 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1971 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1972 BPF_EXIT_INSN(),
1973 BPF_MOV64_IMM(R4, 4),
1974 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1975 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1976 BPF_EXIT_INSN(),
1977 BPF_MOV64_IMM(R4, 5),
1978 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1979 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1980 BPF_EXIT_INSN(),
1981 BPF_MOV64_IMM(R0, -1),
1982 BPF_EXIT_INSN(),
1983 },
1984 INTERNAL,
1985 { },
1986 { { 0, -1 } }
1987 },
1988 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001989 "INT: DIV + ABS",
Andrew Mortonece80492014-05-22 10:16:46 -07001990 .u.insns_int = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001991 BPF_ALU64_REG(BPF_MOV, R6, R1),
1992 BPF_LD_ABS(BPF_B, 3),
1993 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1994 BPF_ALU32_REG(BPF_DIV, R0, R2),
1995 BPF_ALU64_REG(BPF_MOV, R8, R0),
1996 BPF_LD_ABS(BPF_B, 4),
1997 BPF_ALU64_REG(BPF_ADD, R8, R0),
1998 BPF_LD_IND(BPF_B, R8, -70),
1999 BPF_EXIT_INSN(),
2000 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002001 INTERNAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002002 { 10, 20, 30, 40, 50 },
2003 { { 4, 0 }, { 5, 10 } }
2004 },
2005 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002006 "INT: DIV by zero",
Andrew Mortonece80492014-05-22 10:16:46 -07002007 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002008 BPF_ALU64_REG(BPF_MOV, R6, R1),
2009 BPF_ALU64_IMM(BPF_MOV, R7, 0),
2010 BPF_LD_ABS(BPF_B, 3),
2011 BPF_ALU32_REG(BPF_DIV, R0, R7),
2012 BPF_EXIT_INSN(),
2013 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002014 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002015 { 10, 20, 30, 40, 50 },
2016 { { 3, 0 }, { 4, 0 } }
2017 },
2018 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002019 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07002020 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002021 BPF_STMT(BPF_LD | BPF_IMM, 1),
2022 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002023 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002024 { },
2025 { }
2026 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002027 {
2028 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07002029 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002030 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
2031 BPF_STMT(BPF_RET | BPF_K, 0)
2032 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002033 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002034 { },
2035 { }
2036 },
2037 {
2038 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07002039 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002040 /* seccomp insn, rejected in socket filter */
2041 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
2042 BPF_STMT(BPF_RET | BPF_K, 0)
2043 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002044 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002045 { },
2046 { }
2047 },
2048 {
2049 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07002050 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002051 BPF_STMT(BPF_STX, 16),
2052 BPF_STMT(BPF_RET | BPF_K, 0)
2053 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02002054 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07002055 { },
2056 { }
2057 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002058 {
2059 "JUMPS + HOLES",
2060 .u.insns = {
2061 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2062 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
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_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2070 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2071 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2072 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2073 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2074 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2075 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2076 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
2077 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2078 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
2079 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2080 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2081 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
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_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2088 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2089 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2090 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2091 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2092 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2093 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2094 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2095 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2096 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2097 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2098 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2099 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2100 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2101 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2102 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2103 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2104 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2105 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2106 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2107 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2108 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2109 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2110 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2111 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2112 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2113 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2114 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2115 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2116 BPF_STMT(BPF_RET | BPF_A, 0),
2117 BPF_STMT(BPF_RET | BPF_A, 0),
2118 },
2119 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02002120 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2121 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2122 0x08, 0x00,
2123 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2124 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2125 0xc0, 0xa8, 0x33, 0x01,
2126 0xc0, 0xa8, 0x33, 0x02,
2127 0xbb, 0xb6,
2128 0xa9, 0xfa,
2129 0x00, 0x14, 0x00, 0x00,
2130 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2131 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2132 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2133 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2134 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2135 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2136 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2137 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002138 { { 88, 0x001b } }
2139 },
2140 {
2141 "check: RET X",
2142 .u.insns = {
2143 BPF_STMT(BPF_RET | BPF_X, 0),
2144 },
2145 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2146 { },
2147 { },
2148 },
2149 {
2150 "check: LDX + RET X",
2151 .u.insns = {
2152 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2153 BPF_STMT(BPF_RET | BPF_X, 0),
2154 },
2155 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2156 { },
2157 { },
2158 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02002159 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002160 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02002161 .u.insns = {
2162 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2163 BPF_STMT(BPF_STX, 0),
2164 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2165 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2166 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2167 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2168 BPF_STMT(BPF_STX, 1),
2169 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2170 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2171 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2172 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2173 BPF_STMT(BPF_STX, 2),
2174 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2175 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2176 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2177 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2178 BPF_STMT(BPF_STX, 3),
2179 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2180 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2181 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2182 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2183 BPF_STMT(BPF_STX, 4),
2184 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2185 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2186 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2187 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2188 BPF_STMT(BPF_STX, 5),
2189 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2190 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2191 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2192 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2193 BPF_STMT(BPF_STX, 6),
2194 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2195 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2196 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2197 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2198 BPF_STMT(BPF_STX, 7),
2199 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2200 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2201 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2202 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2203 BPF_STMT(BPF_STX, 8),
2204 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2205 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2206 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2207 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2208 BPF_STMT(BPF_STX, 9),
2209 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2210 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2211 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2212 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2213 BPF_STMT(BPF_STX, 10),
2214 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2215 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2216 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2217 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2218 BPF_STMT(BPF_STX, 11),
2219 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2220 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2221 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2222 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2223 BPF_STMT(BPF_STX, 12),
2224 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2225 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2226 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2227 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2228 BPF_STMT(BPF_STX, 13),
2229 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2230 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2231 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2232 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2233 BPF_STMT(BPF_STX, 14),
2234 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2235 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2236 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2237 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2238 BPF_STMT(BPF_STX, 15),
2239 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2240 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2241 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2242 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2243 BPF_STMT(BPF_RET | BPF_A, 0),
2244 },
2245 CLASSIC | FLAG_NO_DATA,
2246 { },
2247 { { 0, 116 } },
2248 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002249 { /* Mainly checking JIT here. */
2250 "M[]: full STX + full LDX",
2251 .u.insns = {
2252 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2253 BPF_STMT(BPF_STX, 0),
2254 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2255 BPF_STMT(BPF_STX, 1),
2256 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2257 BPF_STMT(BPF_STX, 2),
2258 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2259 BPF_STMT(BPF_STX, 3),
2260 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2261 BPF_STMT(BPF_STX, 4),
2262 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2263 BPF_STMT(BPF_STX, 5),
2264 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2265 BPF_STMT(BPF_STX, 6),
2266 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2267 BPF_STMT(BPF_STX, 7),
2268 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2269 BPF_STMT(BPF_STX, 8),
2270 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2271 BPF_STMT(BPF_STX, 9),
2272 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2273 BPF_STMT(BPF_STX, 10),
2274 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2275 BPF_STMT(BPF_STX, 11),
2276 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2277 BPF_STMT(BPF_STX, 12),
2278 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2279 BPF_STMT(BPF_STX, 13),
2280 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2281 BPF_STMT(BPF_STX, 14),
2282 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2283 BPF_STMT(BPF_STX, 15),
2284 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2285 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2286 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2287 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2288 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2289 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2290 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2291 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2292 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2293 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2294 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2295 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2296 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2297 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2298 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2299 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2300 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2301 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2302 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2303 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2304 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2305 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2306 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2307 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2308 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2309 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2310 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2311 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2312 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2313 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2314 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2315 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2316 BPF_STMT(BPF_RET | BPF_A, 0),
2317 },
2318 CLASSIC | FLAG_NO_DATA,
2319 { },
2320 { { 0, 0x2a5a5e5 } },
2321 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002322 {
2323 "check: SKF_AD_MAX",
2324 .u.insns = {
2325 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2326 SKF_AD_OFF + SKF_AD_MAX),
2327 BPF_STMT(BPF_RET | BPF_A, 0),
2328 },
2329 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2330 { },
2331 { },
2332 },
2333 { /* Passes checker but fails during runtime. */
2334 "LD [SKF_AD_OFF-1]",
2335 .u.insns = {
2336 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2337 SKF_AD_OFF - 1),
2338 BPF_STMT(BPF_RET | BPF_K, 1),
2339 },
2340 CLASSIC,
2341 { },
2342 { { 1, 0 } },
2343 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002344 {
2345 "load 64-bit immediate",
2346 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07002347 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002348 BPF_MOV64_REG(R2, R1),
2349 BPF_MOV64_REG(R3, R2),
2350 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2351 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2352 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2353 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2354 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2355 BPF_EXIT_INSN(),
2356 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2357 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04002358 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2359 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002360 BPF_EXIT_INSN(),
2361 },
2362 INTERNAL,
2363 { },
2364 { { 0, 1 } }
2365 },
Alexei Starovoitove21ab362014-10-28 15:11:43 -07002366 {
2367 "nmap reduced",
2368 .u.insns_int = {
2369 BPF_MOV64_REG(R6, R1),
2370 BPF_LD_ABS(BPF_H, 12),
2371 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28),
2372 BPF_LD_ABS(BPF_H, 12),
2373 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26),
2374 BPF_MOV32_IMM(R0, 18),
2375 BPF_STX_MEM(BPF_W, R10, R0, -64),
2376 BPF_LDX_MEM(BPF_W, R7, R10, -64),
2377 BPF_LD_IND(BPF_W, R7, 14),
2378 BPF_STX_MEM(BPF_W, R10, R0, -60),
2379 BPF_MOV32_IMM(R0, 280971478),
2380 BPF_STX_MEM(BPF_W, R10, R0, -56),
2381 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2382 BPF_LDX_MEM(BPF_W, R0, R10, -60),
2383 BPF_ALU32_REG(BPF_SUB, R0, R7),
2384 BPF_JMP_IMM(BPF_JNE, R0, 0, 15),
2385 BPF_LD_ABS(BPF_H, 12),
2386 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13),
2387 BPF_MOV32_IMM(R0, 22),
2388 BPF_STX_MEM(BPF_W, R10, R0, -56),
2389 BPF_LDX_MEM(BPF_W, R7, R10, -56),
2390 BPF_LD_IND(BPF_H, R7, 14),
2391 BPF_STX_MEM(BPF_W, R10, R0, -52),
2392 BPF_MOV32_IMM(R0, 17366),
2393 BPF_STX_MEM(BPF_W, R10, R0, -48),
2394 BPF_LDX_MEM(BPF_W, R7, R10, -48),
2395 BPF_LDX_MEM(BPF_W, R0, R10, -52),
2396 BPF_ALU32_REG(BPF_SUB, R0, R7),
2397 BPF_JMP_IMM(BPF_JNE, R0, 0, 2),
2398 BPF_MOV32_IMM(R0, 256),
2399 BPF_EXIT_INSN(),
2400 BPF_MOV32_IMM(R0, 0),
2401 BPF_EXIT_INSN(),
2402 },
2403 INTERNAL,
2404 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0,
2405 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2406 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6},
Alexei Starovoitov105c0362017-05-30 13:31:32 -07002407 { { 38, 256 } },
2408 .stack_depth = 64,
Alexei Starovoitove21ab362014-10-28 15:11:43 -07002409 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002410 /* BPF_ALU | BPF_MOV | BPF_X */
2411 {
2412 "ALU_MOV_X: dst = 2",
2413 .u.insns_int = {
2414 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2415 BPF_ALU32_REG(BPF_MOV, R0, R1),
2416 BPF_EXIT_INSN(),
2417 },
2418 INTERNAL,
2419 { },
2420 { { 0, 2 } },
2421 },
2422 {
2423 "ALU_MOV_X: dst = 4294967295",
2424 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002425 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002426 BPF_ALU32_REG(BPF_MOV, R0, R1),
2427 BPF_EXIT_INSN(),
2428 },
2429 INTERNAL,
2430 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002431 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002432 },
2433 {
2434 "ALU64_MOV_X: dst = 2",
2435 .u.insns_int = {
2436 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2437 BPF_ALU64_REG(BPF_MOV, R0, R1),
2438 BPF_EXIT_INSN(),
2439 },
2440 INTERNAL,
2441 { },
2442 { { 0, 2 } },
2443 },
2444 {
2445 "ALU64_MOV_X: dst = 4294967295",
2446 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002447 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002448 BPF_ALU64_REG(BPF_MOV, R0, R1),
2449 BPF_EXIT_INSN(),
2450 },
2451 INTERNAL,
2452 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002453 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002454 },
2455 /* BPF_ALU | BPF_MOV | BPF_K */
2456 {
2457 "ALU_MOV_K: dst = 2",
2458 .u.insns_int = {
2459 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2460 BPF_EXIT_INSN(),
2461 },
2462 INTERNAL,
2463 { },
2464 { { 0, 2 } },
2465 },
2466 {
2467 "ALU_MOV_K: dst = 4294967295",
2468 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002469 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002470 BPF_EXIT_INSN(),
2471 },
2472 INTERNAL,
2473 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002474 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002475 },
2476 {
2477 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2478 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002479 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2480 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002481 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2482 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2483 BPF_MOV32_IMM(R0, 2),
2484 BPF_EXIT_INSN(),
2485 BPF_MOV32_IMM(R0, 1),
2486 BPF_EXIT_INSN(),
2487 },
2488 INTERNAL,
2489 { },
2490 { { 0, 0x1 } },
2491 },
2492 {
2493 "ALU64_MOV_K: dst = 2",
2494 .u.insns_int = {
2495 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2496 BPF_EXIT_INSN(),
2497 },
2498 INTERNAL,
2499 { },
2500 { { 0, 2 } },
2501 },
2502 {
2503 "ALU64_MOV_K: dst = 2147483647",
2504 .u.insns_int = {
2505 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2506 BPF_EXIT_INSN(),
2507 },
2508 INTERNAL,
2509 { },
2510 { { 0, 2147483647 } },
2511 },
2512 {
2513 "ALU64_OR_K: dst = 0x0",
2514 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002515 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002516 BPF_LD_IMM64(R3, 0x0),
2517 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2518 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2519 BPF_MOV32_IMM(R0, 2),
2520 BPF_EXIT_INSN(),
2521 BPF_MOV32_IMM(R0, 1),
2522 BPF_EXIT_INSN(),
2523 },
2524 INTERNAL,
2525 { },
2526 { { 0, 0x1 } },
2527 },
2528 {
2529 "ALU64_MOV_K: dst = -1",
2530 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002531 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2532 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002533 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2534 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2535 BPF_MOV32_IMM(R0, 2),
2536 BPF_EXIT_INSN(),
2537 BPF_MOV32_IMM(R0, 1),
2538 BPF_EXIT_INSN(),
2539 },
2540 INTERNAL,
2541 { },
2542 { { 0, 0x1 } },
2543 },
2544 /* BPF_ALU | BPF_ADD | BPF_X */
2545 {
2546 "ALU_ADD_X: 1 + 2 = 3",
2547 .u.insns_int = {
2548 BPF_LD_IMM64(R0, 1),
2549 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2550 BPF_ALU32_REG(BPF_ADD, R0, R1),
2551 BPF_EXIT_INSN(),
2552 },
2553 INTERNAL,
2554 { },
2555 { { 0, 3 } },
2556 },
2557 {
2558 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2559 .u.insns_int = {
2560 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002561 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002562 BPF_ALU32_REG(BPF_ADD, R0, R1),
2563 BPF_EXIT_INSN(),
2564 },
2565 INTERNAL,
2566 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002567 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002568 },
2569 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302570 "ALU_ADD_X: 2 + 4294967294 = 0",
2571 .u.insns_int = {
2572 BPF_LD_IMM64(R0, 2),
2573 BPF_LD_IMM64(R1, 4294967294U),
2574 BPF_ALU32_REG(BPF_ADD, R0, R1),
2575 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2576 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2577 BPF_EXIT_INSN(),
2578 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2579 BPF_EXIT_INSN(),
2580 },
2581 INTERNAL,
2582 { },
2583 { { 0, 1 } },
2584 },
2585 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002586 "ALU64_ADD_X: 1 + 2 = 3",
2587 .u.insns_int = {
2588 BPF_LD_IMM64(R0, 1),
2589 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2590 BPF_ALU64_REG(BPF_ADD, R0, R1),
2591 BPF_EXIT_INSN(),
2592 },
2593 INTERNAL,
2594 { },
2595 { { 0, 3 } },
2596 },
2597 {
2598 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2599 .u.insns_int = {
2600 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002601 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002602 BPF_ALU64_REG(BPF_ADD, R0, R1),
2603 BPF_EXIT_INSN(),
2604 },
2605 INTERNAL,
2606 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002607 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002608 },
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302609 {
2610 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2611 .u.insns_int = {
2612 BPF_LD_IMM64(R0, 2),
2613 BPF_LD_IMM64(R1, 4294967294U),
2614 BPF_LD_IMM64(R2, 4294967296ULL),
2615 BPF_ALU64_REG(BPF_ADD, R0, R1),
2616 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2617 BPF_MOV32_IMM(R0, 0),
2618 BPF_EXIT_INSN(),
2619 BPF_MOV32_IMM(R0, 1),
2620 BPF_EXIT_INSN(),
2621 },
2622 INTERNAL,
2623 { },
2624 { { 0, 1 } },
2625 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002626 /* BPF_ALU | BPF_ADD | BPF_K */
2627 {
2628 "ALU_ADD_K: 1 + 2 = 3",
2629 .u.insns_int = {
2630 BPF_LD_IMM64(R0, 1),
2631 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2632 BPF_EXIT_INSN(),
2633 },
2634 INTERNAL,
2635 { },
2636 { { 0, 3 } },
2637 },
2638 {
2639 "ALU_ADD_K: 3 + 0 = 3",
2640 .u.insns_int = {
2641 BPF_LD_IMM64(R0, 3),
2642 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2643 BPF_EXIT_INSN(),
2644 },
2645 INTERNAL,
2646 { },
2647 { { 0, 3 } },
2648 },
2649 {
2650 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2651 .u.insns_int = {
2652 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002653 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002654 BPF_EXIT_INSN(),
2655 },
2656 INTERNAL,
2657 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002658 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002659 },
2660 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302661 "ALU_ADD_K: 4294967294 + 2 = 0",
2662 .u.insns_int = {
2663 BPF_LD_IMM64(R0, 4294967294U),
2664 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2665 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2666 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2667 BPF_EXIT_INSN(),
2668 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2669 BPF_EXIT_INSN(),
2670 },
2671 INTERNAL,
2672 { },
2673 { { 0, 1 } },
2674 },
2675 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002676 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2677 .u.insns_int = {
2678 BPF_LD_IMM64(R2, 0x0),
2679 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2680 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2681 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2682 BPF_MOV32_IMM(R0, 2),
2683 BPF_EXIT_INSN(),
2684 BPF_MOV32_IMM(R0, 1),
2685 BPF_EXIT_INSN(),
2686 },
2687 INTERNAL,
2688 { },
2689 { { 0, 0x1 } },
2690 },
2691 {
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302692 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2693 .u.insns_int = {
2694 BPF_LD_IMM64(R2, 0x0),
2695 BPF_LD_IMM64(R3, 0xffff),
2696 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2697 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2698 BPF_MOV32_IMM(R0, 2),
2699 BPF_EXIT_INSN(),
2700 BPF_MOV32_IMM(R0, 1),
2701 BPF_EXIT_INSN(),
2702 },
2703 INTERNAL,
2704 { },
2705 { { 0, 0x1 } },
2706 },
2707 {
2708 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2709 .u.insns_int = {
2710 BPF_LD_IMM64(R2, 0x0),
2711 BPF_LD_IMM64(R3, 0x7fffffff),
2712 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2713 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2714 BPF_MOV32_IMM(R0, 2),
2715 BPF_EXIT_INSN(),
2716 BPF_MOV32_IMM(R0, 1),
2717 BPF_EXIT_INSN(),
2718 },
2719 INTERNAL,
2720 { },
2721 { { 0, 0x1 } },
2722 },
2723 {
2724 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2725 .u.insns_int = {
2726 BPF_LD_IMM64(R2, 0x0),
2727 BPF_LD_IMM64(R3, 0x80000000),
2728 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2729 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2730 BPF_MOV32_IMM(R0, 2),
2731 BPF_EXIT_INSN(),
2732 BPF_MOV32_IMM(R0, 1),
2733 BPF_EXIT_INSN(),
2734 },
2735 INTERNAL,
2736 { },
2737 { { 0, 0x1 } },
2738 },
2739 {
2740 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2741 .u.insns_int = {
2742 BPF_LD_IMM64(R2, 0x0),
2743 BPF_LD_IMM64(R3, 0x80008000),
2744 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2745 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2746 BPF_MOV32_IMM(R0, 2),
2747 BPF_EXIT_INSN(),
2748 BPF_MOV32_IMM(R0, 1),
2749 BPF_EXIT_INSN(),
2750 },
2751 INTERNAL,
2752 { },
2753 { { 0, 0x1 } },
2754 },
2755 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002756 "ALU64_ADD_K: 1 + 2 = 3",
2757 .u.insns_int = {
2758 BPF_LD_IMM64(R0, 1),
2759 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2760 BPF_EXIT_INSN(),
2761 },
2762 INTERNAL,
2763 { },
2764 { { 0, 3 } },
2765 },
2766 {
2767 "ALU64_ADD_K: 3 + 0 = 3",
2768 .u.insns_int = {
2769 BPF_LD_IMM64(R0, 3),
2770 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2771 BPF_EXIT_INSN(),
2772 },
2773 INTERNAL,
2774 { },
2775 { { 0, 3 } },
2776 },
2777 {
2778 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2779 .u.insns_int = {
2780 BPF_LD_IMM64(R0, 1),
2781 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2782 BPF_EXIT_INSN(),
2783 },
2784 INTERNAL,
2785 { },
2786 { { 0, 2147483647 } },
2787 },
2788 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302789 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2790 .u.insns_int = {
2791 BPF_LD_IMM64(R0, 4294967294U),
2792 BPF_LD_IMM64(R1, 4294967296ULL),
2793 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2794 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2795 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2796 BPF_EXIT_INSN(),
2797 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2798 BPF_EXIT_INSN(),
2799 },
2800 INTERNAL,
2801 { },
2802 { { 0, 1 } },
2803 },
2804 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002805 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2806 .u.insns_int = {
2807 BPF_LD_IMM64(R0, 2147483646),
2808 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2809 BPF_EXIT_INSN(),
2810 },
2811 INTERNAL,
2812 { },
2813 { { 0, -1 } },
2814 },
2815 {
2816 "ALU64_ADD_K: 1 + 0 = 1",
2817 .u.insns_int = {
2818 BPF_LD_IMM64(R2, 0x1),
2819 BPF_LD_IMM64(R3, 0x1),
2820 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2821 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2822 BPF_MOV32_IMM(R0, 2),
2823 BPF_EXIT_INSN(),
2824 BPF_MOV32_IMM(R0, 1),
2825 BPF_EXIT_INSN(),
2826 },
2827 INTERNAL,
2828 { },
2829 { { 0, 0x1 } },
2830 },
2831 {
2832 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2833 .u.insns_int = {
2834 BPF_LD_IMM64(R2, 0x0),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002835 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002836 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2837 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2838 BPF_MOV32_IMM(R0, 2),
2839 BPF_EXIT_INSN(),
2840 BPF_MOV32_IMM(R0, 1),
2841 BPF_EXIT_INSN(),
2842 },
2843 INTERNAL,
2844 { },
2845 { { 0, 0x1 } },
2846 },
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302847 {
2848 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2849 .u.insns_int = {
2850 BPF_LD_IMM64(R2, 0x0),
2851 BPF_LD_IMM64(R3, 0xffff),
2852 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
2853 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2854 BPF_MOV32_IMM(R0, 2),
2855 BPF_EXIT_INSN(),
2856 BPF_MOV32_IMM(R0, 1),
2857 BPF_EXIT_INSN(),
2858 },
2859 INTERNAL,
2860 { },
2861 { { 0, 0x1 } },
2862 },
2863 {
2864 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2865 .u.insns_int = {
2866 BPF_LD_IMM64(R2, 0x0),
2867 BPF_LD_IMM64(R3, 0x7fffffff),
2868 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
2869 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2870 BPF_MOV32_IMM(R0, 2),
2871 BPF_EXIT_INSN(),
2872 BPF_MOV32_IMM(R0, 1),
2873 BPF_EXIT_INSN(),
2874 },
2875 INTERNAL,
2876 { },
2877 { { 0, 0x1 } },
2878 },
2879 {
2880 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2881 .u.insns_int = {
2882 BPF_LD_IMM64(R2, 0x0),
2883 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
2884 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
2885 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2886 BPF_MOV32_IMM(R0, 2),
2887 BPF_EXIT_INSN(),
2888 BPF_MOV32_IMM(R0, 1),
2889 BPF_EXIT_INSN(),
2890 },
2891 INTERNAL,
2892 { },
2893 { { 0, 0x1 } },
2894 },
2895 {
2896 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2897 .u.insns_int = {
2898 BPF_LD_IMM64(R2, 0x0),
2899 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
2900 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
2901 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2902 BPF_MOV32_IMM(R0, 2),
2903 BPF_EXIT_INSN(),
2904 BPF_MOV32_IMM(R0, 1),
2905 BPF_EXIT_INSN(),
2906 },
2907 INTERNAL,
2908 { },
2909 { { 0, 0x1 } },
2910 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002911 /* BPF_ALU | BPF_SUB | BPF_X */
2912 {
2913 "ALU_SUB_X: 3 - 1 = 2",
2914 .u.insns_int = {
2915 BPF_LD_IMM64(R0, 3),
2916 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2917 BPF_ALU32_REG(BPF_SUB, R0, R1),
2918 BPF_EXIT_INSN(),
2919 },
2920 INTERNAL,
2921 { },
2922 { { 0, 2 } },
2923 },
2924 {
2925 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2926 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002927 BPF_LD_IMM64(R0, 4294967295U),
2928 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002929 BPF_ALU32_REG(BPF_SUB, R0, R1),
2930 BPF_EXIT_INSN(),
2931 },
2932 INTERNAL,
2933 { },
2934 { { 0, 1 } },
2935 },
2936 {
2937 "ALU64_SUB_X: 3 - 1 = 2",
2938 .u.insns_int = {
2939 BPF_LD_IMM64(R0, 3),
2940 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2941 BPF_ALU64_REG(BPF_SUB, R0, R1),
2942 BPF_EXIT_INSN(),
2943 },
2944 INTERNAL,
2945 { },
2946 { { 0, 2 } },
2947 },
2948 {
2949 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2950 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002951 BPF_LD_IMM64(R0, 4294967295U),
2952 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002953 BPF_ALU64_REG(BPF_SUB, R0, R1),
2954 BPF_EXIT_INSN(),
2955 },
2956 INTERNAL,
2957 { },
2958 { { 0, 1 } },
2959 },
2960 /* BPF_ALU | BPF_SUB | BPF_K */
2961 {
2962 "ALU_SUB_K: 3 - 1 = 2",
2963 .u.insns_int = {
2964 BPF_LD_IMM64(R0, 3),
2965 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2966 BPF_EXIT_INSN(),
2967 },
2968 INTERNAL,
2969 { },
2970 { { 0, 2 } },
2971 },
2972 {
2973 "ALU_SUB_K: 3 - 0 = 3",
2974 .u.insns_int = {
2975 BPF_LD_IMM64(R0, 3),
2976 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2977 BPF_EXIT_INSN(),
2978 },
2979 INTERNAL,
2980 { },
2981 { { 0, 3 } },
2982 },
2983 {
2984 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2985 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002986 BPF_LD_IMM64(R0, 4294967295U),
2987 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002988 BPF_EXIT_INSN(),
2989 },
2990 INTERNAL,
2991 { },
2992 { { 0, 1 } },
2993 },
2994 {
2995 "ALU64_SUB_K: 3 - 1 = 2",
2996 .u.insns_int = {
2997 BPF_LD_IMM64(R0, 3),
2998 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2999 BPF_EXIT_INSN(),
3000 },
3001 INTERNAL,
3002 { },
3003 { { 0, 2 } },
3004 },
3005 {
3006 "ALU64_SUB_K: 3 - 0 = 3",
3007 .u.insns_int = {
3008 BPF_LD_IMM64(R0, 3),
3009 BPF_ALU64_IMM(BPF_SUB, R0, 0),
3010 BPF_EXIT_INSN(),
3011 },
3012 INTERNAL,
3013 { },
3014 { { 0, 3 } },
3015 },
3016 {
3017 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
3018 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003019 BPF_LD_IMM64(R0, 4294967294U),
3020 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003021 BPF_EXIT_INSN(),
3022 },
3023 INTERNAL,
3024 { },
3025 { { 0, -1 } },
3026 },
3027 {
3028 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
3029 .u.insns_int = {
3030 BPF_LD_IMM64(R0, 2147483646),
3031 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
3032 BPF_EXIT_INSN(),
3033 },
3034 INTERNAL,
3035 { },
3036 { { 0, -1 } },
3037 },
3038 /* BPF_ALU | BPF_MUL | BPF_X */
3039 {
3040 "ALU_MUL_X: 2 * 3 = 6",
3041 .u.insns_int = {
3042 BPF_LD_IMM64(R0, 2),
3043 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3044 BPF_ALU32_REG(BPF_MUL, R0, R1),
3045 BPF_EXIT_INSN(),
3046 },
3047 INTERNAL,
3048 { },
3049 { { 0, 6 } },
3050 },
3051 {
3052 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3053 .u.insns_int = {
3054 BPF_LD_IMM64(R0, 2),
3055 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
3056 BPF_ALU32_REG(BPF_MUL, R0, R1),
3057 BPF_EXIT_INSN(),
3058 },
3059 INTERNAL,
3060 { },
3061 { { 0, 0xFFFFFFF0 } },
3062 },
3063 {
3064 "ALU_MUL_X: -1 * -1 = 1",
3065 .u.insns_int = {
3066 BPF_LD_IMM64(R0, -1),
3067 BPF_ALU32_IMM(BPF_MOV, R1, -1),
3068 BPF_ALU32_REG(BPF_MUL, R0, R1),
3069 BPF_EXIT_INSN(),
3070 },
3071 INTERNAL,
3072 { },
3073 { { 0, 1 } },
3074 },
3075 {
3076 "ALU64_MUL_X: 2 * 3 = 6",
3077 .u.insns_int = {
3078 BPF_LD_IMM64(R0, 2),
3079 BPF_ALU32_IMM(BPF_MOV, R1, 3),
3080 BPF_ALU64_REG(BPF_MUL, R0, R1),
3081 BPF_EXIT_INSN(),
3082 },
3083 INTERNAL,
3084 { },
3085 { { 0, 6 } },
3086 },
3087 {
3088 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
3089 .u.insns_int = {
3090 BPF_LD_IMM64(R0, 1),
3091 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3092 BPF_ALU64_REG(BPF_MUL, R0, R1),
3093 BPF_EXIT_INSN(),
3094 },
3095 INTERNAL,
3096 { },
3097 { { 0, 2147483647 } },
3098 },
3099 /* BPF_ALU | BPF_MUL | BPF_K */
3100 {
3101 "ALU_MUL_K: 2 * 3 = 6",
3102 .u.insns_int = {
3103 BPF_LD_IMM64(R0, 2),
3104 BPF_ALU32_IMM(BPF_MUL, R0, 3),
3105 BPF_EXIT_INSN(),
3106 },
3107 INTERNAL,
3108 { },
3109 { { 0, 6 } },
3110 },
3111 {
3112 "ALU_MUL_K: 3 * 1 = 3",
3113 .u.insns_int = {
3114 BPF_LD_IMM64(R0, 3),
3115 BPF_ALU32_IMM(BPF_MUL, R0, 1),
3116 BPF_EXIT_INSN(),
3117 },
3118 INTERNAL,
3119 { },
3120 { { 0, 3 } },
3121 },
3122 {
3123 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3124 .u.insns_int = {
3125 BPF_LD_IMM64(R0, 2),
3126 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3127 BPF_EXIT_INSN(),
3128 },
3129 INTERNAL,
3130 { },
3131 { { 0, 0xFFFFFFF0 } },
3132 },
3133 {
3134 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3135 .u.insns_int = {
3136 BPF_LD_IMM64(R2, 0x1),
3137 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3138 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3139 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3140 BPF_MOV32_IMM(R0, 2),
3141 BPF_EXIT_INSN(),
3142 BPF_MOV32_IMM(R0, 1),
3143 BPF_EXIT_INSN(),
3144 },
3145 INTERNAL,
3146 { },
3147 { { 0, 0x1 } },
3148 },
3149 {
3150 "ALU64_MUL_K: 2 * 3 = 6",
3151 .u.insns_int = {
3152 BPF_LD_IMM64(R0, 2),
3153 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3154 BPF_EXIT_INSN(),
3155 },
3156 INTERNAL,
3157 { },
3158 { { 0, 6 } },
3159 },
3160 {
3161 "ALU64_MUL_K: 3 * 1 = 3",
3162 .u.insns_int = {
3163 BPF_LD_IMM64(R0, 3),
3164 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3165 BPF_EXIT_INSN(),
3166 },
3167 INTERNAL,
3168 { },
3169 { { 0, 3 } },
3170 },
3171 {
3172 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3173 .u.insns_int = {
3174 BPF_LD_IMM64(R0, 1),
3175 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3176 BPF_EXIT_INSN(),
3177 },
3178 INTERNAL,
3179 { },
3180 { { 0, 2147483647 } },
3181 },
3182 {
3183 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3184 .u.insns_int = {
3185 BPF_LD_IMM64(R0, 1),
3186 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3187 BPF_EXIT_INSN(),
3188 },
3189 INTERNAL,
3190 { },
3191 { { 0, -2147483647 } },
3192 },
3193 {
3194 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3195 .u.insns_int = {
3196 BPF_LD_IMM64(R2, 0x1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003197 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003198 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3199 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3200 BPF_MOV32_IMM(R0, 2),
3201 BPF_EXIT_INSN(),
3202 BPF_MOV32_IMM(R0, 1),
3203 BPF_EXIT_INSN(),
3204 },
3205 INTERNAL,
3206 { },
3207 { { 0, 0x1 } },
3208 },
3209 /* BPF_ALU | BPF_DIV | BPF_X */
3210 {
3211 "ALU_DIV_X: 6 / 2 = 3",
3212 .u.insns_int = {
3213 BPF_LD_IMM64(R0, 6),
3214 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3215 BPF_ALU32_REG(BPF_DIV, R0, R1),
3216 BPF_EXIT_INSN(),
3217 },
3218 INTERNAL,
3219 { },
3220 { { 0, 3 } },
3221 },
3222 {
3223 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3224 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003225 BPF_LD_IMM64(R0, 4294967295U),
3226 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003227 BPF_ALU32_REG(BPF_DIV, R0, R1),
3228 BPF_EXIT_INSN(),
3229 },
3230 INTERNAL,
3231 { },
3232 { { 0, 1 } },
3233 },
3234 {
3235 "ALU64_DIV_X: 6 / 2 = 3",
3236 .u.insns_int = {
3237 BPF_LD_IMM64(R0, 6),
3238 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3239 BPF_ALU64_REG(BPF_DIV, R0, R1),
3240 BPF_EXIT_INSN(),
3241 },
3242 INTERNAL,
3243 { },
3244 { { 0, 3 } },
3245 },
3246 {
3247 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3248 .u.insns_int = {
3249 BPF_LD_IMM64(R0, 2147483647),
3250 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3251 BPF_ALU64_REG(BPF_DIV, R0, R1),
3252 BPF_EXIT_INSN(),
3253 },
3254 INTERNAL,
3255 { },
3256 { { 0, 1 } },
3257 },
3258 {
3259 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3260 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003261 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3262 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3263 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003264 BPF_ALU64_REG(BPF_DIV, R2, R4),
3265 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3266 BPF_MOV32_IMM(R0, 2),
3267 BPF_EXIT_INSN(),
3268 BPF_MOV32_IMM(R0, 1),
3269 BPF_EXIT_INSN(),
3270 },
3271 INTERNAL,
3272 { },
3273 { { 0, 0x1 } },
3274 },
3275 /* BPF_ALU | BPF_DIV | BPF_K */
3276 {
3277 "ALU_DIV_K: 6 / 2 = 3",
3278 .u.insns_int = {
3279 BPF_LD_IMM64(R0, 6),
3280 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3281 BPF_EXIT_INSN(),
3282 },
3283 INTERNAL,
3284 { },
3285 { { 0, 3 } },
3286 },
3287 {
3288 "ALU_DIV_K: 3 / 1 = 3",
3289 .u.insns_int = {
3290 BPF_LD_IMM64(R0, 3),
3291 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3292 BPF_EXIT_INSN(),
3293 },
3294 INTERNAL,
3295 { },
3296 { { 0, 3 } },
3297 },
3298 {
3299 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3300 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003301 BPF_LD_IMM64(R0, 4294967295U),
3302 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003303 BPF_EXIT_INSN(),
3304 },
3305 INTERNAL,
3306 { },
3307 { { 0, 1 } },
3308 },
3309 {
3310 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3311 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003312 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003313 BPF_LD_IMM64(R3, 0x1UL),
3314 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3315 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3316 BPF_MOV32_IMM(R0, 2),
3317 BPF_EXIT_INSN(),
3318 BPF_MOV32_IMM(R0, 1),
3319 BPF_EXIT_INSN(),
3320 },
3321 INTERNAL,
3322 { },
3323 { { 0, 0x1 } },
3324 },
3325 {
3326 "ALU64_DIV_K: 6 / 2 = 3",
3327 .u.insns_int = {
3328 BPF_LD_IMM64(R0, 6),
3329 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3330 BPF_EXIT_INSN(),
3331 },
3332 INTERNAL,
3333 { },
3334 { { 0, 3 } },
3335 },
3336 {
3337 "ALU64_DIV_K: 3 / 1 = 3",
3338 .u.insns_int = {
3339 BPF_LD_IMM64(R0, 3),
3340 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3341 BPF_EXIT_INSN(),
3342 },
3343 INTERNAL,
3344 { },
3345 { { 0, 3 } },
3346 },
3347 {
3348 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3349 .u.insns_int = {
3350 BPF_LD_IMM64(R0, 2147483647),
3351 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3352 BPF_EXIT_INSN(),
3353 },
3354 INTERNAL,
3355 { },
3356 { { 0, 1 } },
3357 },
3358 {
3359 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3360 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003361 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3362 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003363 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3364 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3365 BPF_MOV32_IMM(R0, 2),
3366 BPF_EXIT_INSN(),
3367 BPF_MOV32_IMM(R0, 1),
3368 BPF_EXIT_INSN(),
3369 },
3370 INTERNAL,
3371 { },
3372 { { 0, 0x1 } },
3373 },
3374 /* BPF_ALU | BPF_MOD | BPF_X */
3375 {
3376 "ALU_MOD_X: 3 % 2 = 1",
3377 .u.insns_int = {
3378 BPF_LD_IMM64(R0, 3),
3379 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3380 BPF_ALU32_REG(BPF_MOD, R0, R1),
3381 BPF_EXIT_INSN(),
3382 },
3383 INTERNAL,
3384 { },
3385 { { 0, 1 } },
3386 },
3387 {
3388 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3389 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003390 BPF_LD_IMM64(R0, 4294967295U),
3391 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003392 BPF_ALU32_REG(BPF_MOD, R0, R1),
3393 BPF_EXIT_INSN(),
3394 },
3395 INTERNAL,
3396 { },
3397 { { 0, 2 } },
3398 },
3399 {
3400 "ALU64_MOD_X: 3 % 2 = 1",
3401 .u.insns_int = {
3402 BPF_LD_IMM64(R0, 3),
3403 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3404 BPF_ALU64_REG(BPF_MOD, R0, R1),
3405 BPF_EXIT_INSN(),
3406 },
3407 INTERNAL,
3408 { },
3409 { { 0, 1 } },
3410 },
3411 {
3412 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3413 .u.insns_int = {
3414 BPF_LD_IMM64(R0, 2147483647),
3415 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3416 BPF_ALU64_REG(BPF_MOD, R0, R1),
3417 BPF_EXIT_INSN(),
3418 },
3419 INTERNAL,
3420 { },
3421 { { 0, 2 } },
3422 },
3423 /* BPF_ALU | BPF_MOD | BPF_K */
3424 {
3425 "ALU_MOD_K: 3 % 2 = 1",
3426 .u.insns_int = {
3427 BPF_LD_IMM64(R0, 3),
3428 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3429 BPF_EXIT_INSN(),
3430 },
3431 INTERNAL,
3432 { },
3433 { { 0, 1 } },
3434 },
3435 {
3436 "ALU_MOD_K: 3 % 1 = 0",
3437 .u.insns_int = {
3438 BPF_LD_IMM64(R0, 3),
3439 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3440 BPF_EXIT_INSN(),
3441 },
3442 INTERNAL,
3443 { },
3444 { { 0, 0 } },
3445 },
3446 {
3447 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3448 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003449 BPF_LD_IMM64(R0, 4294967295U),
3450 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003451 BPF_EXIT_INSN(),
3452 },
3453 INTERNAL,
3454 { },
3455 { { 0, 2 } },
3456 },
3457 {
3458 "ALU64_MOD_K: 3 % 2 = 1",
3459 .u.insns_int = {
3460 BPF_LD_IMM64(R0, 3),
3461 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3462 BPF_EXIT_INSN(),
3463 },
3464 INTERNAL,
3465 { },
3466 { { 0, 1 } },
3467 },
3468 {
3469 "ALU64_MOD_K: 3 % 1 = 0",
3470 .u.insns_int = {
3471 BPF_LD_IMM64(R0, 3),
3472 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3473 BPF_EXIT_INSN(),
3474 },
3475 INTERNAL,
3476 { },
3477 { { 0, 0 } },
3478 },
3479 {
3480 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3481 .u.insns_int = {
3482 BPF_LD_IMM64(R0, 2147483647),
3483 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3484 BPF_EXIT_INSN(),
3485 },
3486 INTERNAL,
3487 { },
3488 { { 0, 2 } },
3489 },
3490 /* BPF_ALU | BPF_AND | BPF_X */
3491 {
3492 "ALU_AND_X: 3 & 2 = 2",
3493 .u.insns_int = {
3494 BPF_LD_IMM64(R0, 3),
3495 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3496 BPF_ALU32_REG(BPF_AND, R0, R1),
3497 BPF_EXIT_INSN(),
3498 },
3499 INTERNAL,
3500 { },
3501 { { 0, 2 } },
3502 },
3503 {
3504 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3505 .u.insns_int = {
3506 BPF_LD_IMM64(R0, 0xffffffff),
3507 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3508 BPF_ALU32_REG(BPF_AND, R0, R1),
3509 BPF_EXIT_INSN(),
3510 },
3511 INTERNAL,
3512 { },
3513 { { 0, 0xffffffff } },
3514 },
3515 {
3516 "ALU64_AND_X: 3 & 2 = 2",
3517 .u.insns_int = {
3518 BPF_LD_IMM64(R0, 3),
3519 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3520 BPF_ALU64_REG(BPF_AND, R0, R1),
3521 BPF_EXIT_INSN(),
3522 },
3523 INTERNAL,
3524 { },
3525 { { 0, 2 } },
3526 },
3527 {
3528 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3529 .u.insns_int = {
3530 BPF_LD_IMM64(R0, 0xffffffff),
3531 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3532 BPF_ALU64_REG(BPF_AND, R0, R1),
3533 BPF_EXIT_INSN(),
3534 },
3535 INTERNAL,
3536 { },
3537 { { 0, 0xffffffff } },
3538 },
3539 /* BPF_ALU | BPF_AND | BPF_K */
3540 {
3541 "ALU_AND_K: 3 & 2 = 2",
3542 .u.insns_int = {
3543 BPF_LD_IMM64(R0, 3),
3544 BPF_ALU32_IMM(BPF_AND, R0, 2),
3545 BPF_EXIT_INSN(),
3546 },
3547 INTERNAL,
3548 { },
3549 { { 0, 2 } },
3550 },
3551 {
3552 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3553 .u.insns_int = {
3554 BPF_LD_IMM64(R0, 0xffffffff),
3555 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3556 BPF_EXIT_INSN(),
3557 },
3558 INTERNAL,
3559 { },
3560 { { 0, 0xffffffff } },
3561 },
3562 {
3563 "ALU64_AND_K: 3 & 2 = 2",
3564 .u.insns_int = {
3565 BPF_LD_IMM64(R0, 3),
3566 BPF_ALU64_IMM(BPF_AND, R0, 2),
3567 BPF_EXIT_INSN(),
3568 },
3569 INTERNAL,
3570 { },
3571 { { 0, 2 } },
3572 },
3573 {
3574 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3575 .u.insns_int = {
3576 BPF_LD_IMM64(R0, 0xffffffff),
3577 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3578 BPF_EXIT_INSN(),
3579 },
3580 INTERNAL,
3581 { },
3582 { { 0, 0xffffffff } },
3583 },
3584 {
3585 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3586 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003587 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3588 BPF_LD_IMM64(R3, 0x0000000000000000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003589 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3590 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3591 BPF_MOV32_IMM(R0, 2),
3592 BPF_EXIT_INSN(),
3593 BPF_MOV32_IMM(R0, 1),
3594 BPF_EXIT_INSN(),
3595 },
3596 INTERNAL,
3597 { },
3598 { { 0, 0x1 } },
3599 },
3600 {
3601 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3602 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003603 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3604 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003605 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3606 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3607 BPF_MOV32_IMM(R0, 2),
3608 BPF_EXIT_INSN(),
3609 BPF_MOV32_IMM(R0, 1),
3610 BPF_EXIT_INSN(),
3611 },
3612 INTERNAL,
3613 { },
3614 { { 0, 0x1 } },
3615 },
3616 {
3617 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3618 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003619 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3620 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003621 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3622 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3623 BPF_MOV32_IMM(R0, 2),
3624 BPF_EXIT_INSN(),
3625 BPF_MOV32_IMM(R0, 1),
3626 BPF_EXIT_INSN(),
3627 },
3628 INTERNAL,
3629 { },
3630 { { 0, 0x1 } },
3631 },
3632 /* BPF_ALU | BPF_OR | BPF_X */
3633 {
3634 "ALU_OR_X: 1 | 2 = 3",
3635 .u.insns_int = {
3636 BPF_LD_IMM64(R0, 1),
3637 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3638 BPF_ALU32_REG(BPF_OR, R0, R1),
3639 BPF_EXIT_INSN(),
3640 },
3641 INTERNAL,
3642 { },
3643 { { 0, 3 } },
3644 },
3645 {
3646 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3647 .u.insns_int = {
3648 BPF_LD_IMM64(R0, 0),
3649 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3650 BPF_ALU32_REG(BPF_OR, R0, R1),
3651 BPF_EXIT_INSN(),
3652 },
3653 INTERNAL,
3654 { },
3655 { { 0, 0xffffffff } },
3656 },
3657 {
3658 "ALU64_OR_X: 1 | 2 = 3",
3659 .u.insns_int = {
3660 BPF_LD_IMM64(R0, 1),
3661 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3662 BPF_ALU64_REG(BPF_OR, R0, R1),
3663 BPF_EXIT_INSN(),
3664 },
3665 INTERNAL,
3666 { },
3667 { { 0, 3 } },
3668 },
3669 {
3670 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3671 .u.insns_int = {
3672 BPF_LD_IMM64(R0, 0),
3673 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3674 BPF_ALU64_REG(BPF_OR, R0, R1),
3675 BPF_EXIT_INSN(),
3676 },
3677 INTERNAL,
3678 { },
3679 { { 0, 0xffffffff } },
3680 },
3681 /* BPF_ALU | BPF_OR | BPF_K */
3682 {
3683 "ALU_OR_K: 1 | 2 = 3",
3684 .u.insns_int = {
3685 BPF_LD_IMM64(R0, 1),
3686 BPF_ALU32_IMM(BPF_OR, R0, 2),
3687 BPF_EXIT_INSN(),
3688 },
3689 INTERNAL,
3690 { },
3691 { { 0, 3 } },
3692 },
3693 {
3694 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3695 .u.insns_int = {
3696 BPF_LD_IMM64(R0, 0),
3697 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3698 BPF_EXIT_INSN(),
3699 },
3700 INTERNAL,
3701 { },
3702 { { 0, 0xffffffff } },
3703 },
3704 {
3705 "ALU64_OR_K: 1 | 2 = 3",
3706 .u.insns_int = {
3707 BPF_LD_IMM64(R0, 1),
3708 BPF_ALU64_IMM(BPF_OR, R0, 2),
3709 BPF_EXIT_INSN(),
3710 },
3711 INTERNAL,
3712 { },
3713 { { 0, 3 } },
3714 },
3715 {
3716 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3717 .u.insns_int = {
3718 BPF_LD_IMM64(R0, 0),
3719 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3720 BPF_EXIT_INSN(),
3721 },
3722 INTERNAL,
3723 { },
3724 { { 0, 0xffffffff } },
3725 },
3726 {
3727 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3728 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003729 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3730 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003731 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3732 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3733 BPF_MOV32_IMM(R0, 2),
3734 BPF_EXIT_INSN(),
3735 BPF_MOV32_IMM(R0, 1),
3736 BPF_EXIT_INSN(),
3737 },
3738 INTERNAL,
3739 { },
3740 { { 0, 0x1 } },
3741 },
3742 {
3743 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3744 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003745 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3746 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003747 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3748 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3749 BPF_MOV32_IMM(R0, 2),
3750 BPF_EXIT_INSN(),
3751 BPF_MOV32_IMM(R0, 1),
3752 BPF_EXIT_INSN(),
3753 },
3754 INTERNAL,
3755 { },
3756 { { 0, 0x1 } },
3757 },
3758 {
3759 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3760 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003761 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3762 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003763 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3764 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3765 BPF_MOV32_IMM(R0, 2),
3766 BPF_EXIT_INSN(),
3767 BPF_MOV32_IMM(R0, 1),
3768 BPF_EXIT_INSN(),
3769 },
3770 INTERNAL,
3771 { },
3772 { { 0, 0x1 } },
3773 },
3774 /* BPF_ALU | BPF_XOR | BPF_X */
3775 {
3776 "ALU_XOR_X: 5 ^ 6 = 3",
3777 .u.insns_int = {
3778 BPF_LD_IMM64(R0, 5),
3779 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3780 BPF_ALU32_REG(BPF_XOR, R0, R1),
3781 BPF_EXIT_INSN(),
3782 },
3783 INTERNAL,
3784 { },
3785 { { 0, 3 } },
3786 },
3787 {
3788 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3789 .u.insns_int = {
3790 BPF_LD_IMM64(R0, 1),
3791 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3792 BPF_ALU32_REG(BPF_XOR, R0, R1),
3793 BPF_EXIT_INSN(),
3794 },
3795 INTERNAL,
3796 { },
3797 { { 0, 0xfffffffe } },
3798 },
3799 {
3800 "ALU64_XOR_X: 5 ^ 6 = 3",
3801 .u.insns_int = {
3802 BPF_LD_IMM64(R0, 5),
3803 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3804 BPF_ALU64_REG(BPF_XOR, R0, R1),
3805 BPF_EXIT_INSN(),
3806 },
3807 INTERNAL,
3808 { },
3809 { { 0, 3 } },
3810 },
3811 {
3812 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3813 .u.insns_int = {
3814 BPF_LD_IMM64(R0, 1),
3815 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3816 BPF_ALU64_REG(BPF_XOR, R0, R1),
3817 BPF_EXIT_INSN(),
3818 },
3819 INTERNAL,
3820 { },
3821 { { 0, 0xfffffffe } },
3822 },
3823 /* BPF_ALU | BPF_XOR | BPF_K */
3824 {
3825 "ALU_XOR_K: 5 ^ 6 = 3",
3826 .u.insns_int = {
3827 BPF_LD_IMM64(R0, 5),
3828 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3829 BPF_EXIT_INSN(),
3830 },
3831 INTERNAL,
3832 { },
3833 { { 0, 3 } },
3834 },
3835 {
3836 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3837 .u.insns_int = {
3838 BPF_LD_IMM64(R0, 1),
3839 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3840 BPF_EXIT_INSN(),
3841 },
3842 INTERNAL,
3843 { },
3844 { { 0, 0xfffffffe } },
3845 },
3846 {
3847 "ALU64_XOR_K: 5 ^ 6 = 3",
3848 .u.insns_int = {
3849 BPF_LD_IMM64(R0, 5),
3850 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3851 BPF_EXIT_INSN(),
3852 },
3853 INTERNAL,
3854 { },
3855 { { 0, 3 } },
3856 },
3857 {
3858 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3859 .u.insns_int = {
3860 BPF_LD_IMM64(R0, 1),
3861 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3862 BPF_EXIT_INSN(),
3863 },
3864 INTERNAL,
3865 { },
3866 { { 0, 0xfffffffe } },
3867 },
3868 {
3869 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3870 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003871 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3872 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003873 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3874 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3875 BPF_MOV32_IMM(R0, 2),
3876 BPF_EXIT_INSN(),
3877 BPF_MOV32_IMM(R0, 1),
3878 BPF_EXIT_INSN(),
3879 },
3880 INTERNAL,
3881 { },
3882 { { 0, 0x1 } },
3883 },
3884 {
3885 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3886 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003887 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3888 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003889 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3890 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3891 BPF_MOV32_IMM(R0, 2),
3892 BPF_EXIT_INSN(),
3893 BPF_MOV32_IMM(R0, 1),
3894 BPF_EXIT_INSN(),
3895 },
3896 INTERNAL,
3897 { },
3898 { { 0, 0x1 } },
3899 },
3900 {
3901 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3902 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003903 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3904 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003905 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3906 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3907 BPF_MOV32_IMM(R0, 2),
3908 BPF_EXIT_INSN(),
3909 BPF_MOV32_IMM(R0, 1),
3910 BPF_EXIT_INSN(),
3911 },
3912 INTERNAL,
3913 { },
3914 { { 0, 0x1 } },
3915 },
3916 /* BPF_ALU | BPF_LSH | BPF_X */
3917 {
3918 "ALU_LSH_X: 1 << 1 = 2",
3919 .u.insns_int = {
3920 BPF_LD_IMM64(R0, 1),
3921 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3922 BPF_ALU32_REG(BPF_LSH, R0, R1),
3923 BPF_EXIT_INSN(),
3924 },
3925 INTERNAL,
3926 { },
3927 { { 0, 2 } },
3928 },
3929 {
3930 "ALU_LSH_X: 1 << 31 = 0x80000000",
3931 .u.insns_int = {
3932 BPF_LD_IMM64(R0, 1),
3933 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3934 BPF_ALU32_REG(BPF_LSH, R0, R1),
3935 BPF_EXIT_INSN(),
3936 },
3937 INTERNAL,
3938 { },
3939 { { 0, 0x80000000 } },
3940 },
3941 {
3942 "ALU64_LSH_X: 1 << 1 = 2",
3943 .u.insns_int = {
3944 BPF_LD_IMM64(R0, 1),
3945 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3946 BPF_ALU64_REG(BPF_LSH, R0, R1),
3947 BPF_EXIT_INSN(),
3948 },
3949 INTERNAL,
3950 { },
3951 { { 0, 2 } },
3952 },
3953 {
3954 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3955 .u.insns_int = {
3956 BPF_LD_IMM64(R0, 1),
3957 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3958 BPF_ALU64_REG(BPF_LSH, R0, R1),
3959 BPF_EXIT_INSN(),
3960 },
3961 INTERNAL,
3962 { },
3963 { { 0, 0x80000000 } },
3964 },
3965 /* BPF_ALU | BPF_LSH | BPF_K */
3966 {
3967 "ALU_LSH_K: 1 << 1 = 2",
3968 .u.insns_int = {
3969 BPF_LD_IMM64(R0, 1),
3970 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3971 BPF_EXIT_INSN(),
3972 },
3973 INTERNAL,
3974 { },
3975 { { 0, 2 } },
3976 },
3977 {
3978 "ALU_LSH_K: 1 << 31 = 0x80000000",
3979 .u.insns_int = {
3980 BPF_LD_IMM64(R0, 1),
3981 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3982 BPF_EXIT_INSN(),
3983 },
3984 INTERNAL,
3985 { },
3986 { { 0, 0x80000000 } },
3987 },
3988 {
3989 "ALU64_LSH_K: 1 << 1 = 2",
3990 .u.insns_int = {
3991 BPF_LD_IMM64(R0, 1),
3992 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3993 BPF_EXIT_INSN(),
3994 },
3995 INTERNAL,
3996 { },
3997 { { 0, 2 } },
3998 },
3999 {
4000 "ALU64_LSH_K: 1 << 31 = 0x80000000",
4001 .u.insns_int = {
4002 BPF_LD_IMM64(R0, 1),
4003 BPF_ALU64_IMM(BPF_LSH, R0, 31),
4004 BPF_EXIT_INSN(),
4005 },
4006 INTERNAL,
4007 { },
4008 { { 0, 0x80000000 } },
4009 },
4010 /* BPF_ALU | BPF_RSH | BPF_X */
4011 {
4012 "ALU_RSH_X: 2 >> 1 = 1",
4013 .u.insns_int = {
4014 BPF_LD_IMM64(R0, 2),
4015 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4016 BPF_ALU32_REG(BPF_RSH, R0, R1),
4017 BPF_EXIT_INSN(),
4018 },
4019 INTERNAL,
4020 { },
4021 { { 0, 1 } },
4022 },
4023 {
4024 "ALU_RSH_X: 0x80000000 >> 31 = 1",
4025 .u.insns_int = {
4026 BPF_LD_IMM64(R0, 0x80000000),
4027 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4028 BPF_ALU32_REG(BPF_RSH, R0, R1),
4029 BPF_EXIT_INSN(),
4030 },
4031 INTERNAL,
4032 { },
4033 { { 0, 1 } },
4034 },
4035 {
4036 "ALU64_RSH_X: 2 >> 1 = 1",
4037 .u.insns_int = {
4038 BPF_LD_IMM64(R0, 2),
4039 BPF_ALU32_IMM(BPF_MOV, R1, 1),
4040 BPF_ALU64_REG(BPF_RSH, R0, R1),
4041 BPF_EXIT_INSN(),
4042 },
4043 INTERNAL,
4044 { },
4045 { { 0, 1 } },
4046 },
4047 {
4048 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
4049 .u.insns_int = {
4050 BPF_LD_IMM64(R0, 0x80000000),
4051 BPF_ALU32_IMM(BPF_MOV, R1, 31),
4052 BPF_ALU64_REG(BPF_RSH, R0, R1),
4053 BPF_EXIT_INSN(),
4054 },
4055 INTERNAL,
4056 { },
4057 { { 0, 1 } },
4058 },
4059 /* BPF_ALU | BPF_RSH | BPF_K */
4060 {
4061 "ALU_RSH_K: 2 >> 1 = 1",
4062 .u.insns_int = {
4063 BPF_LD_IMM64(R0, 2),
4064 BPF_ALU32_IMM(BPF_RSH, R0, 1),
4065 BPF_EXIT_INSN(),
4066 },
4067 INTERNAL,
4068 { },
4069 { { 0, 1 } },
4070 },
4071 {
4072 "ALU_RSH_K: 0x80000000 >> 31 = 1",
4073 .u.insns_int = {
4074 BPF_LD_IMM64(R0, 0x80000000),
4075 BPF_ALU32_IMM(BPF_RSH, R0, 31),
4076 BPF_EXIT_INSN(),
4077 },
4078 INTERNAL,
4079 { },
4080 { { 0, 1 } },
4081 },
4082 {
4083 "ALU64_RSH_K: 2 >> 1 = 1",
4084 .u.insns_int = {
4085 BPF_LD_IMM64(R0, 2),
4086 BPF_ALU64_IMM(BPF_RSH, R0, 1),
4087 BPF_EXIT_INSN(),
4088 },
4089 INTERNAL,
4090 { },
4091 { { 0, 1 } },
4092 },
4093 {
4094 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
4095 .u.insns_int = {
4096 BPF_LD_IMM64(R0, 0x80000000),
4097 BPF_ALU64_IMM(BPF_RSH, R0, 31),
4098 BPF_EXIT_INSN(),
4099 },
4100 INTERNAL,
4101 { },
4102 { { 0, 1 } },
4103 },
4104 /* BPF_ALU | BPF_ARSH | BPF_X */
4105 {
4106 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4107 .u.insns_int = {
4108 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4109 BPF_ALU32_IMM(BPF_MOV, R1, 40),
4110 BPF_ALU64_REG(BPF_ARSH, R0, R1),
4111 BPF_EXIT_INSN(),
4112 },
4113 INTERNAL,
4114 { },
4115 { { 0, 0xffff00ff } },
4116 },
4117 /* BPF_ALU | BPF_ARSH | BPF_K */
4118 {
4119 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
4120 .u.insns_int = {
4121 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4122 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
4123 BPF_EXIT_INSN(),
4124 },
4125 INTERNAL,
4126 { },
4127 { { 0, 0xffff00ff } },
4128 },
4129 /* BPF_ALU | BPF_NEG */
4130 {
4131 "ALU_NEG: -(3) = -3",
4132 .u.insns_int = {
4133 BPF_ALU32_IMM(BPF_MOV, R0, 3),
4134 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4135 BPF_EXIT_INSN(),
4136 },
4137 INTERNAL,
4138 { },
4139 { { 0, -3 } },
4140 },
4141 {
4142 "ALU_NEG: -(-3) = 3",
4143 .u.insns_int = {
4144 BPF_ALU32_IMM(BPF_MOV, R0, -3),
4145 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4146 BPF_EXIT_INSN(),
4147 },
4148 INTERNAL,
4149 { },
4150 { { 0, 3 } },
4151 },
4152 {
4153 "ALU64_NEG: -(3) = -3",
4154 .u.insns_int = {
4155 BPF_LD_IMM64(R0, 3),
4156 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4157 BPF_EXIT_INSN(),
4158 },
4159 INTERNAL,
4160 { },
4161 { { 0, -3 } },
4162 },
4163 {
4164 "ALU64_NEG: -(-3) = 3",
4165 .u.insns_int = {
4166 BPF_LD_IMM64(R0, -3),
4167 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4168 BPF_EXIT_INSN(),
4169 },
4170 INTERNAL,
4171 { },
4172 { { 0, 3 } },
4173 },
4174 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4175 {
4176 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4177 .u.insns_int = {
4178 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4179 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
4180 BPF_EXIT_INSN(),
4181 },
4182 INTERNAL,
4183 { },
4184 { { 0, cpu_to_be16(0xcdef) } },
4185 },
4186 {
4187 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4188 .u.insns_int = {
4189 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4190 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07004191 BPF_ALU64_REG(BPF_MOV, R1, R0),
4192 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4193 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07004194 BPF_EXIT_INSN(),
4195 },
4196 INTERNAL,
4197 { },
4198 { { 0, cpu_to_be32(0x89abcdef) } },
4199 },
4200 {
4201 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4202 .u.insns_int = {
4203 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4204 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
4205 BPF_EXIT_INSN(),
4206 },
4207 INTERNAL,
4208 { },
4209 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
4210 },
4211 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4212 {
4213 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4214 .u.insns_int = {
4215 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4216 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
4217 BPF_EXIT_INSN(),
4218 },
4219 INTERNAL,
4220 { },
4221 { { 0, cpu_to_le16(0xcdef) } },
4222 },
4223 {
4224 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4225 .u.insns_int = {
4226 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4227 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07004228 BPF_ALU64_REG(BPF_MOV, R1, R0),
4229 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4230 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07004231 BPF_EXIT_INSN(),
4232 },
4233 INTERNAL,
4234 { },
4235 { { 0, cpu_to_le32(0x89abcdef) } },
4236 },
4237 {
4238 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4239 .u.insns_int = {
4240 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4241 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
4242 BPF_EXIT_INSN(),
4243 },
4244 INTERNAL,
4245 { },
4246 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
4247 },
4248 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4249 {
4250 "ST_MEM_B: Store/Load byte: max negative",
4251 .u.insns_int = {
4252 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4253 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
4254 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4255 BPF_EXIT_INSN(),
4256 },
4257 INTERNAL,
4258 { },
4259 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004260 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004261 },
4262 {
4263 "ST_MEM_B: Store/Load byte: max positive",
4264 .u.insns_int = {
4265 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4266 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
4267 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4268 BPF_EXIT_INSN(),
4269 },
4270 INTERNAL,
4271 { },
4272 { { 0, 0x7f } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004273 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004274 },
4275 {
4276 "STX_MEM_B: Store/Load byte: max negative",
4277 .u.insns_int = {
4278 BPF_LD_IMM64(R0, 0),
4279 BPF_LD_IMM64(R1, 0xffLL),
4280 BPF_STX_MEM(BPF_B, R10, R1, -40),
4281 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4282 BPF_EXIT_INSN(),
4283 },
4284 INTERNAL,
4285 { },
4286 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004287 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004288 },
4289 {
4290 "ST_MEM_H: Store/Load half word: max negative",
4291 .u.insns_int = {
4292 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4293 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
4294 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4295 BPF_EXIT_INSN(),
4296 },
4297 INTERNAL,
4298 { },
4299 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004300 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004301 },
4302 {
4303 "ST_MEM_H: Store/Load half word: max positive",
4304 .u.insns_int = {
4305 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4306 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
4307 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4308 BPF_EXIT_INSN(),
4309 },
4310 INTERNAL,
4311 { },
4312 { { 0, 0x7fff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004313 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004314 },
4315 {
4316 "STX_MEM_H: Store/Load half word: max negative",
4317 .u.insns_int = {
4318 BPF_LD_IMM64(R0, 0),
4319 BPF_LD_IMM64(R1, 0xffffLL),
4320 BPF_STX_MEM(BPF_H, R10, R1, -40),
4321 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4322 BPF_EXIT_INSN(),
4323 },
4324 INTERNAL,
4325 { },
4326 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004327 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004328 },
4329 {
4330 "ST_MEM_W: Store/Load word: max negative",
4331 .u.insns_int = {
4332 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4333 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
4334 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4335 BPF_EXIT_INSN(),
4336 },
4337 INTERNAL,
4338 { },
4339 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004340 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004341 },
4342 {
4343 "ST_MEM_W: Store/Load word: max positive",
4344 .u.insns_int = {
4345 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4346 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
4347 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4348 BPF_EXIT_INSN(),
4349 },
4350 INTERNAL,
4351 { },
4352 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004353 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004354 },
4355 {
4356 "STX_MEM_W: Store/Load word: max negative",
4357 .u.insns_int = {
4358 BPF_LD_IMM64(R0, 0),
4359 BPF_LD_IMM64(R1, 0xffffffffLL),
4360 BPF_STX_MEM(BPF_W, R10, R1, -40),
4361 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4362 BPF_EXIT_INSN(),
4363 },
4364 INTERNAL,
4365 { },
4366 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004367 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004368 },
4369 {
4370 "ST_MEM_DW: Store/Load double word: max negative",
4371 .u.insns_int = {
4372 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4373 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4374 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4375 BPF_EXIT_INSN(),
4376 },
4377 INTERNAL,
4378 { },
4379 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004380 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004381 },
4382 {
4383 "ST_MEM_DW: Store/Load double word: max negative 2",
4384 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004385 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
4386 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004387 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4388 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
4389 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4390 BPF_MOV32_IMM(R0, 2),
4391 BPF_EXIT_INSN(),
4392 BPF_MOV32_IMM(R0, 1),
4393 BPF_EXIT_INSN(),
4394 },
4395 INTERNAL,
4396 { },
4397 { { 0, 0x1 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004398 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004399 },
4400 {
4401 "ST_MEM_DW: Store/Load double word: max positive",
4402 .u.insns_int = {
4403 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4404 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
4405 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4406 BPF_EXIT_INSN(),
4407 },
4408 INTERNAL,
4409 { },
4410 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004411 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004412 },
4413 {
4414 "STX_MEM_DW: Store/Load double word: max negative",
4415 .u.insns_int = {
4416 BPF_LD_IMM64(R0, 0),
4417 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4418 BPF_STX_MEM(BPF_W, R10, R1, -40),
4419 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4420 BPF_EXIT_INSN(),
4421 },
4422 INTERNAL,
4423 { },
4424 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004425 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004426 },
4427 /* BPF_STX | BPF_XADD | BPF_W/DW */
4428 {
4429 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4430 .u.insns_int = {
4431 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4432 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4433 BPF_STX_XADD(BPF_W, R10, R0, -40),
4434 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4435 BPF_EXIT_INSN(),
4436 },
4437 INTERNAL,
4438 { },
4439 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004440 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004441 },
4442 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004443 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4444 .u.insns_int = {
4445 BPF_ALU64_REG(BPF_MOV, R1, R10),
4446 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4447 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4448 BPF_STX_XADD(BPF_W, R10, R0, -40),
4449 BPF_ALU64_REG(BPF_MOV, R0, R10),
4450 BPF_ALU64_REG(BPF_SUB, R0, R1),
4451 BPF_EXIT_INSN(),
4452 },
4453 INTERNAL,
4454 { },
4455 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004456 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004457 },
4458 {
4459 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4460 .u.insns_int = {
4461 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4462 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4463 BPF_STX_XADD(BPF_W, R10, R0, -40),
4464 BPF_EXIT_INSN(),
4465 },
4466 INTERNAL,
4467 { },
4468 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004469 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004470 },
4471 {
4472 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4473 { },
4474 INTERNAL,
4475 { },
4476 { { 0, 4134 } },
4477 .fill_helper = bpf_fill_stxw,
4478 },
4479 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004480 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4481 .u.insns_int = {
4482 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4483 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4484 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4485 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4486 BPF_EXIT_INSN(),
4487 },
4488 INTERNAL,
4489 { },
4490 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004491 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004492 },
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004493 {
4494 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4495 .u.insns_int = {
4496 BPF_ALU64_REG(BPF_MOV, R1, R10),
4497 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4498 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4499 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4500 BPF_ALU64_REG(BPF_MOV, R0, R10),
4501 BPF_ALU64_REG(BPF_SUB, R0, R1),
4502 BPF_EXIT_INSN(),
4503 },
4504 INTERNAL,
4505 { },
4506 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004507 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004508 },
4509 {
4510 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4511 .u.insns_int = {
4512 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4513 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4514 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4515 BPF_EXIT_INSN(),
4516 },
4517 INTERNAL,
4518 { },
4519 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004520 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004521 },
4522 {
4523 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4524 { },
4525 INTERNAL,
4526 { },
4527 { { 0, 4134 } },
4528 .fill_helper = bpf_fill_stxdw,
4529 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004530 /* BPF_JMP | BPF_EXIT */
4531 {
4532 "JMP_EXIT",
4533 .u.insns_int = {
4534 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4535 BPF_EXIT_INSN(),
4536 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4537 },
4538 INTERNAL,
4539 { },
4540 { { 0, 0x4711 } },
4541 },
4542 /* BPF_JMP | BPF_JA */
4543 {
4544 "JMP_JA: Unconditional jump: if (true) return 1",
4545 .u.insns_int = {
4546 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4547 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4548 BPF_EXIT_INSN(),
4549 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4550 BPF_EXIT_INSN(),
4551 },
4552 INTERNAL,
4553 { },
4554 { { 0, 1 } },
4555 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004556 /* BPF_JMP | BPF_JSLT | BPF_K */
4557 {
4558 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4559 .u.insns_int = {
4560 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4561 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4562 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4563 BPF_EXIT_INSN(),
4564 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4565 BPF_EXIT_INSN(),
4566 },
4567 INTERNAL,
4568 { },
4569 { { 0, 1 } },
4570 },
4571 {
4572 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4573 .u.insns_int = {
4574 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4575 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4576 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4577 BPF_EXIT_INSN(),
4578 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4579 BPF_EXIT_INSN(),
4580 },
4581 INTERNAL,
4582 { },
4583 { { 0, 1 } },
4584 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004585 /* BPF_JMP | BPF_JSGT | BPF_K */
4586 {
4587 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4588 .u.insns_int = {
4589 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4590 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4591 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4592 BPF_EXIT_INSN(),
4593 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4594 BPF_EXIT_INSN(),
4595 },
4596 INTERNAL,
4597 { },
4598 { { 0, 1 } },
4599 },
4600 {
4601 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4602 .u.insns_int = {
4603 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4604 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4605 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4606 BPF_EXIT_INSN(),
4607 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4608 BPF_EXIT_INSN(),
4609 },
4610 INTERNAL,
4611 { },
4612 { { 0, 1 } },
4613 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004614 /* BPF_JMP | BPF_JSLE | BPF_K */
4615 {
4616 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4617 .u.insns_int = {
4618 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4619 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4620 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
4621 BPF_EXIT_INSN(),
4622 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4623 BPF_EXIT_INSN(),
4624 },
4625 INTERNAL,
4626 { },
4627 { { 0, 1 } },
4628 },
4629 {
4630 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4631 .u.insns_int = {
4632 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4633 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4634 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
4635 BPF_EXIT_INSN(),
4636 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4637 BPF_EXIT_INSN(),
4638 },
4639 INTERNAL,
4640 { },
4641 { { 0, 1 } },
4642 },
4643 {
4644 "JMP_JSLE_K: Signed jump: value walk 1",
4645 .u.insns_int = {
4646 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4647 BPF_LD_IMM64(R1, 3),
4648 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
4649 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4650 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
4651 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4652 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
4653 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4654 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
4655 BPF_EXIT_INSN(), /* bad exit */
4656 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4657 BPF_EXIT_INSN(),
4658 },
4659 INTERNAL,
4660 { },
4661 { { 0, 1 } },
4662 },
4663 {
4664 "JMP_JSLE_K: Signed jump: value walk 2",
4665 .u.insns_int = {
4666 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4667 BPF_LD_IMM64(R1, 3),
4668 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
4669 BPF_ALU64_IMM(BPF_SUB, R1, 2),
4670 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
4671 BPF_ALU64_IMM(BPF_SUB, R1, 2),
4672 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
4673 BPF_EXIT_INSN(), /* bad exit */
4674 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4675 BPF_EXIT_INSN(),
4676 },
4677 INTERNAL,
4678 { },
4679 { { 0, 1 } },
4680 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004681 /* BPF_JMP | BPF_JSGE | BPF_K */
4682 {
4683 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4684 .u.insns_int = {
4685 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4686 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4687 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4688 BPF_EXIT_INSN(),
4689 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4690 BPF_EXIT_INSN(),
4691 },
4692 INTERNAL,
4693 { },
4694 { { 0, 1 } },
4695 },
4696 {
4697 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4698 .u.insns_int = {
4699 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4700 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4701 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4702 BPF_EXIT_INSN(),
4703 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4704 BPF_EXIT_INSN(),
4705 },
4706 INTERNAL,
4707 { },
4708 { { 0, 1 } },
4709 },
David Daney791caeb2017-05-24 16:35:49 -07004710 {
4711 "JMP_JSGE_K: Signed jump: value walk 1",
4712 .u.insns_int = {
4713 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4714 BPF_LD_IMM64(R1, -3),
4715 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
4716 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4717 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4718 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4719 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4720 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4721 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4722 BPF_EXIT_INSN(), /* bad exit */
4723 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4724 BPF_EXIT_INSN(),
4725 },
4726 INTERNAL,
4727 { },
4728 { { 0, 1 } },
4729 },
4730 {
4731 "JMP_JSGE_K: Signed jump: value walk 2",
4732 .u.insns_int = {
4733 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4734 BPF_LD_IMM64(R1, -3),
4735 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4736 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4737 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4738 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4739 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4740 BPF_EXIT_INSN(), /* bad exit */
4741 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4742 BPF_EXIT_INSN(),
4743 },
4744 INTERNAL,
4745 { },
4746 { { 0, 1 } },
4747 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004748 /* BPF_JMP | BPF_JGT | BPF_K */
4749 {
4750 "JMP_JGT_K: if (3 > 2) return 1",
4751 .u.insns_int = {
4752 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4753 BPF_LD_IMM64(R1, 3),
4754 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4755 BPF_EXIT_INSN(),
4756 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4757 BPF_EXIT_INSN(),
4758 },
4759 INTERNAL,
4760 { },
4761 { { 0, 1 } },
4762 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05304763 {
4764 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4765 .u.insns_int = {
4766 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4767 BPF_LD_IMM64(R1, -1),
4768 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
4769 BPF_EXIT_INSN(),
4770 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4771 BPF_EXIT_INSN(),
4772 },
4773 INTERNAL,
4774 { },
4775 { { 0, 1 } },
4776 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004777 /* BPF_JMP | BPF_JLT | BPF_K */
4778 {
4779 "JMP_JLT_K: if (2 < 3) return 1",
4780 .u.insns_int = {
4781 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4782 BPF_LD_IMM64(R1, 2),
4783 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
4784 BPF_EXIT_INSN(),
4785 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4786 BPF_EXIT_INSN(),
4787 },
4788 INTERNAL,
4789 { },
4790 { { 0, 1 } },
4791 },
4792 {
4793 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4794 .u.insns_int = {
4795 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4796 BPF_LD_IMM64(R1, 1),
4797 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
4798 BPF_EXIT_INSN(),
4799 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4800 BPF_EXIT_INSN(),
4801 },
4802 INTERNAL,
4803 { },
4804 { { 0, 1 } },
4805 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004806 /* BPF_JMP | BPF_JGE | BPF_K */
4807 {
4808 "JMP_JGE_K: if (3 >= 2) return 1",
4809 .u.insns_int = {
4810 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4811 BPF_LD_IMM64(R1, 3),
4812 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4813 BPF_EXIT_INSN(),
4814 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4815 BPF_EXIT_INSN(),
4816 },
4817 INTERNAL,
4818 { },
4819 { { 0, 1 } },
4820 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004821 /* BPF_JMP | BPF_JLE | BPF_K */
4822 {
4823 "JMP_JLE_K: if (2 <= 3) return 1",
4824 .u.insns_int = {
4825 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4826 BPF_LD_IMM64(R1, 2),
4827 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
4828 BPF_EXIT_INSN(),
4829 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4830 BPF_EXIT_INSN(),
4831 },
4832 INTERNAL,
4833 { },
4834 { { 0, 1 } },
4835 },
Michael Holzheufe593842015-05-22 08:36:40 -07004836 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4837 {
4838 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4839 .u.insns_int = {
4840 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4841 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4842 BPF_EXIT_INSN(),
4843 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4844 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4845 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4846 BPF_EXIT_INSN(),
4847 },
4848 INTERNAL,
4849 { },
4850 { { 0, 1 } },
4851 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004852 {
4853 "JMP_JGE_K: if (3 >= 3) return 1",
4854 .u.insns_int = {
4855 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4856 BPF_LD_IMM64(R1, 3),
4857 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4858 BPF_EXIT_INSN(),
4859 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4860 BPF_EXIT_INSN(),
4861 },
4862 INTERNAL,
4863 { },
4864 { { 0, 1 } },
4865 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004866 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4867 {
4868 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4869 .u.insns_int = {
4870 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4871 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4872 BPF_EXIT_INSN(),
4873 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4874 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
4875 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
4876 BPF_EXIT_INSN(),
4877 },
4878 INTERNAL,
4879 { },
4880 { { 0, 1 } },
4881 },
4882 {
4883 "JMP_JLE_K: if (3 <= 3) return 1",
4884 .u.insns_int = {
4885 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4886 BPF_LD_IMM64(R1, 3),
4887 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
4888 BPF_EXIT_INSN(),
4889 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4890 BPF_EXIT_INSN(),
4891 },
4892 INTERNAL,
4893 { },
4894 { { 0, 1 } },
4895 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004896 /* BPF_JMP | BPF_JNE | BPF_K */
4897 {
4898 "JMP_JNE_K: if (3 != 2) return 1",
4899 .u.insns_int = {
4900 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4901 BPF_LD_IMM64(R1, 3),
4902 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4903 BPF_EXIT_INSN(),
4904 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4905 BPF_EXIT_INSN(),
4906 },
4907 INTERNAL,
4908 { },
4909 { { 0, 1 } },
4910 },
4911 /* BPF_JMP | BPF_JEQ | BPF_K */
4912 {
4913 "JMP_JEQ_K: if (3 == 3) return 1",
4914 .u.insns_int = {
4915 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4916 BPF_LD_IMM64(R1, 3),
4917 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4918 BPF_EXIT_INSN(),
4919 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4920 BPF_EXIT_INSN(),
4921 },
4922 INTERNAL,
4923 { },
4924 { { 0, 1 } },
4925 },
4926 /* BPF_JMP | BPF_JSET | BPF_K */
4927 {
4928 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4929 .u.insns_int = {
4930 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4931 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05304932 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07004933 BPF_EXIT_INSN(),
4934 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4935 BPF_EXIT_INSN(),
4936 },
4937 INTERNAL,
4938 { },
4939 { { 0, 1 } },
4940 },
4941 {
4942 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4943 .u.insns_int = {
4944 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4945 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05304946 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07004947 BPF_EXIT_INSN(),
4948 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4949 BPF_EXIT_INSN(),
4950 },
4951 INTERNAL,
4952 { },
4953 { { 0, 1 } },
4954 },
4955 /* BPF_JMP | BPF_JSGT | BPF_X */
4956 {
4957 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4958 .u.insns_int = {
4959 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4960 BPF_LD_IMM64(R1, -1),
4961 BPF_LD_IMM64(R2, -2),
4962 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4963 BPF_EXIT_INSN(),
4964 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4965 BPF_EXIT_INSN(),
4966 },
4967 INTERNAL,
4968 { },
4969 { { 0, 1 } },
4970 },
4971 {
4972 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4973 .u.insns_int = {
4974 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4975 BPF_LD_IMM64(R1, -1),
4976 BPF_LD_IMM64(R2, -1),
4977 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4978 BPF_EXIT_INSN(),
4979 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4980 BPF_EXIT_INSN(),
4981 },
4982 INTERNAL,
4983 { },
4984 { { 0, 1 } },
4985 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004986 /* BPF_JMP | BPF_JSLT | BPF_X */
4987 {
4988 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
4989 .u.insns_int = {
4990 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4991 BPF_LD_IMM64(R1, -1),
4992 BPF_LD_IMM64(R2, -2),
4993 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
4994 BPF_EXIT_INSN(),
4995 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4996 BPF_EXIT_INSN(),
4997 },
4998 INTERNAL,
4999 { },
5000 { { 0, 1 } },
5001 },
5002 {
5003 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
5004 .u.insns_int = {
5005 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5006 BPF_LD_IMM64(R1, -1),
5007 BPF_LD_IMM64(R2, -1),
5008 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
5009 BPF_EXIT_INSN(),
5010 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5011 BPF_EXIT_INSN(),
5012 },
5013 INTERNAL,
5014 { },
5015 { { 0, 1 } },
5016 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005017 /* BPF_JMP | BPF_JSGE | BPF_X */
5018 {
5019 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
5020 .u.insns_int = {
5021 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5022 BPF_LD_IMM64(R1, -1),
5023 BPF_LD_IMM64(R2, -2),
5024 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
5025 BPF_EXIT_INSN(),
5026 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5027 BPF_EXIT_INSN(),
5028 },
5029 INTERNAL,
5030 { },
5031 { { 0, 1 } },
5032 },
5033 {
5034 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
5035 .u.insns_int = {
5036 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5037 BPF_LD_IMM64(R1, -1),
5038 BPF_LD_IMM64(R2, -1),
5039 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
5040 BPF_EXIT_INSN(),
5041 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5042 BPF_EXIT_INSN(),
5043 },
5044 INTERNAL,
5045 { },
5046 { { 0, 1 } },
5047 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005048 /* BPF_JMP | BPF_JSLE | BPF_X */
5049 {
5050 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
5051 .u.insns_int = {
5052 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5053 BPF_LD_IMM64(R1, -1),
5054 BPF_LD_IMM64(R2, -2),
5055 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
5056 BPF_EXIT_INSN(),
5057 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5058 BPF_EXIT_INSN(),
5059 },
5060 INTERNAL,
5061 { },
5062 { { 0, 1 } },
5063 },
5064 {
5065 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
5066 .u.insns_int = {
5067 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5068 BPF_LD_IMM64(R1, -1),
5069 BPF_LD_IMM64(R2, -1),
5070 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
5071 BPF_EXIT_INSN(),
5072 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5073 BPF_EXIT_INSN(),
5074 },
5075 INTERNAL,
5076 { },
5077 { { 0, 1 } },
5078 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005079 /* BPF_JMP | BPF_JGT | BPF_X */
5080 {
5081 "JMP_JGT_X: if (3 > 2) return 1",
5082 .u.insns_int = {
5083 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5084 BPF_LD_IMM64(R1, 3),
5085 BPF_LD_IMM64(R2, 2),
5086 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
5087 BPF_EXIT_INSN(),
5088 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5089 BPF_EXIT_INSN(),
5090 },
5091 INTERNAL,
5092 { },
5093 { { 0, 1 } },
5094 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05305095 {
5096 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
5097 .u.insns_int = {
5098 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5099 BPF_LD_IMM64(R1, -1),
5100 BPF_LD_IMM64(R2, 1),
5101 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
5102 BPF_EXIT_INSN(),
5103 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5104 BPF_EXIT_INSN(),
5105 },
5106 INTERNAL,
5107 { },
5108 { { 0, 1 } },
5109 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005110 /* BPF_JMP | BPF_JLT | BPF_X */
5111 {
5112 "JMP_JLT_X: if (2 < 3) return 1",
5113 .u.insns_int = {
5114 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5115 BPF_LD_IMM64(R1, 3),
5116 BPF_LD_IMM64(R2, 2),
5117 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
5118 BPF_EXIT_INSN(),
5119 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5120 BPF_EXIT_INSN(),
5121 },
5122 INTERNAL,
5123 { },
5124 { { 0, 1 } },
5125 },
5126 {
5127 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5128 .u.insns_int = {
5129 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5130 BPF_LD_IMM64(R1, -1),
5131 BPF_LD_IMM64(R2, 1),
5132 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
5133 BPF_EXIT_INSN(),
5134 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5135 BPF_EXIT_INSN(),
5136 },
5137 INTERNAL,
5138 { },
5139 { { 0, 1 } },
5140 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005141 /* BPF_JMP | BPF_JGE | BPF_X */
5142 {
5143 "JMP_JGE_X: if (3 >= 2) return 1",
5144 .u.insns_int = {
5145 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5146 BPF_LD_IMM64(R1, 3),
5147 BPF_LD_IMM64(R2, 2),
5148 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5149 BPF_EXIT_INSN(),
5150 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5151 BPF_EXIT_INSN(),
5152 },
5153 INTERNAL,
5154 { },
5155 { { 0, 1 } },
5156 },
5157 {
5158 "JMP_JGE_X: if (3 >= 3) return 1",
5159 .u.insns_int = {
5160 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5161 BPF_LD_IMM64(R1, 3),
5162 BPF_LD_IMM64(R2, 3),
5163 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5164 BPF_EXIT_INSN(),
5165 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5166 BPF_EXIT_INSN(),
5167 },
5168 INTERNAL,
5169 { },
5170 { { 0, 1 } },
5171 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005172 /* BPF_JMP | BPF_JLE | BPF_X */
5173 {
5174 "JMP_JLE_X: if (2 <= 3) return 1",
5175 .u.insns_int = {
5176 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5177 BPF_LD_IMM64(R1, 3),
5178 BPF_LD_IMM64(R2, 2),
5179 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
5180 BPF_EXIT_INSN(),
5181 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5182 BPF_EXIT_INSN(),
5183 },
5184 INTERNAL,
5185 { },
5186 { { 0, 1 } },
5187 },
5188 {
5189 "JMP_JLE_X: if (3 <= 3) return 1",
5190 .u.insns_int = {
5191 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5192 BPF_LD_IMM64(R1, 3),
5193 BPF_LD_IMM64(R2, 3),
5194 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
5195 BPF_EXIT_INSN(),
5196 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5197 BPF_EXIT_INSN(),
5198 },
5199 INTERNAL,
5200 { },
5201 { { 0, 1 } },
5202 },
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005203 {
5204 /* Mainly testing JIT + imm64 here. */
5205 "JMP_JGE_X: ldimm64 test 1",
5206 .u.insns_int = {
5207 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5208 BPF_LD_IMM64(R1, 3),
5209 BPF_LD_IMM64(R2, 2),
5210 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005211 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5212 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005213 BPF_EXIT_INSN(),
5214 },
5215 INTERNAL,
5216 { },
5217 { { 0, 0xeeeeeeeeU } },
5218 },
5219 {
5220 "JMP_JGE_X: ldimm64 test 2",
5221 .u.insns_int = {
5222 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5223 BPF_LD_IMM64(R1, 3),
5224 BPF_LD_IMM64(R2, 2),
5225 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005226 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005227 BPF_EXIT_INSN(),
5228 },
5229 INTERNAL,
5230 { },
5231 { { 0, 0xffffffffU } },
5232 },
5233 {
5234 "JMP_JGE_X: ldimm64 test 3",
5235 .u.insns_int = {
5236 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5237 BPF_LD_IMM64(R1, 3),
5238 BPF_LD_IMM64(R2, 2),
5239 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005240 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5241 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005242 BPF_EXIT_INSN(),
5243 },
5244 INTERNAL,
5245 { },
5246 { { 0, 1 } },
5247 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005248 {
5249 "JMP_JLE_X: ldimm64 test 1",
5250 .u.insns_int = {
5251 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5252 BPF_LD_IMM64(R1, 3),
5253 BPF_LD_IMM64(R2, 2),
5254 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
5255 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5256 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5257 BPF_EXIT_INSN(),
5258 },
5259 INTERNAL,
5260 { },
5261 { { 0, 0xeeeeeeeeU } },
5262 },
5263 {
5264 "JMP_JLE_X: ldimm64 test 2",
5265 .u.insns_int = {
5266 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5267 BPF_LD_IMM64(R1, 3),
5268 BPF_LD_IMM64(R2, 2),
5269 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
5270 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5271 BPF_EXIT_INSN(),
5272 },
5273 INTERNAL,
5274 { },
5275 { { 0, 0xffffffffU } },
5276 },
5277 {
5278 "JMP_JLE_X: ldimm64 test 3",
5279 .u.insns_int = {
5280 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5281 BPF_LD_IMM64(R1, 3),
5282 BPF_LD_IMM64(R2, 2),
5283 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
5284 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5285 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5286 BPF_EXIT_INSN(),
5287 },
5288 INTERNAL,
5289 { },
5290 { { 0, 1 } },
5291 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005292 /* BPF_JMP | BPF_JNE | BPF_X */
5293 {
5294 "JMP_JNE_X: if (3 != 2) return 1",
5295 .u.insns_int = {
5296 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5297 BPF_LD_IMM64(R1, 3),
5298 BPF_LD_IMM64(R2, 2),
5299 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
5300 BPF_EXIT_INSN(),
5301 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5302 BPF_EXIT_INSN(),
5303 },
5304 INTERNAL,
5305 { },
5306 { { 0, 1 } },
5307 },
5308 /* BPF_JMP | BPF_JEQ | BPF_X */
5309 {
5310 "JMP_JEQ_X: if (3 == 3) return 1",
5311 .u.insns_int = {
5312 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5313 BPF_LD_IMM64(R1, 3),
5314 BPF_LD_IMM64(R2, 3),
5315 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
5316 BPF_EXIT_INSN(),
5317 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5318 BPF_EXIT_INSN(),
5319 },
5320 INTERNAL,
5321 { },
5322 { { 0, 1 } },
5323 },
5324 /* BPF_JMP | BPF_JSET | BPF_X */
5325 {
5326 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5327 .u.insns_int = {
5328 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5329 BPF_LD_IMM64(R1, 3),
5330 BPF_LD_IMM64(R2, 2),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05305331 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07005332 BPF_EXIT_INSN(),
5333 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5334 BPF_EXIT_INSN(),
5335 },
5336 INTERNAL,
5337 { },
5338 { { 0, 1 } },
5339 },
5340 {
5341 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5342 .u.insns_int = {
5343 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5344 BPF_LD_IMM64(R1, 3),
5345 BPF_LD_IMM64(R2, 0xffffffff),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05305346 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07005347 BPF_EXIT_INSN(),
5348 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5349 BPF_EXIT_INSN(),
5350 },
5351 INTERNAL,
5352 { },
5353 { { 0, 1 } },
5354 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005355 {
5356 "JMP_JA: Jump, gap, jump, ...",
5357 { },
5358 CLASSIC | FLAG_NO_DATA,
5359 { },
5360 { { 0, 0xababcbac } },
5361 .fill_helper = bpf_fill_ja,
5362 },
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005363 { /* Mainly checking JIT here. */
5364 "BPF_MAXINSNS: Maximum possible literals",
5365 { },
5366 CLASSIC | FLAG_NO_DATA,
5367 { },
5368 { { 0, 0xffffffff } },
5369 .fill_helper = bpf_fill_maxinsns1,
5370 },
5371 { /* Mainly checking JIT here. */
5372 "BPF_MAXINSNS: Single literal",
5373 { },
5374 CLASSIC | FLAG_NO_DATA,
5375 { },
5376 { { 0, 0xfefefefe } },
5377 .fill_helper = bpf_fill_maxinsns2,
5378 },
5379 { /* Mainly checking JIT here. */
5380 "BPF_MAXINSNS: Run/add until end",
5381 { },
5382 CLASSIC | FLAG_NO_DATA,
5383 { },
5384 { { 0, 0x947bf368 } },
5385 .fill_helper = bpf_fill_maxinsns3,
5386 },
5387 {
5388 "BPF_MAXINSNS: Too many instructions",
5389 { },
5390 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5391 { },
5392 { },
5393 .fill_helper = bpf_fill_maxinsns4,
5394 },
5395 { /* Mainly checking JIT here. */
5396 "BPF_MAXINSNS: Very long jump",
5397 { },
5398 CLASSIC | FLAG_NO_DATA,
5399 { },
5400 { { 0, 0xabababab } },
5401 .fill_helper = bpf_fill_maxinsns5,
5402 },
5403 { /* Mainly checking JIT here. */
5404 "BPF_MAXINSNS: Ctx heavy transformations",
5405 { },
5406 CLASSIC,
5407 { },
5408 {
5409 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
5410 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
5411 },
5412 .fill_helper = bpf_fill_maxinsns6,
5413 },
5414 { /* Mainly checking JIT here. */
5415 "BPF_MAXINSNS: Call heavy transformations",
5416 { },
5417 CLASSIC | FLAG_NO_DATA,
5418 { },
5419 { { 1, 0 }, { 10, 0 } },
5420 .fill_helper = bpf_fill_maxinsns7,
5421 },
5422 { /* Mainly checking JIT here. */
5423 "BPF_MAXINSNS: Jump heavy test",
5424 { },
5425 CLASSIC | FLAG_NO_DATA,
5426 { },
5427 { { 0, 0xffffffff } },
5428 .fill_helper = bpf_fill_maxinsns8,
5429 },
Daniel Borkmann3b529602015-05-23 01:10:07 +02005430 { /* Mainly checking JIT here. */
5431 "BPF_MAXINSNS: Very long jump backwards",
5432 { },
5433 INTERNAL | FLAG_NO_DATA,
5434 { },
5435 { { 0, 0xcbababab } },
5436 .fill_helper = bpf_fill_maxinsns9,
5437 },
5438 { /* Mainly checking JIT here. */
5439 "BPF_MAXINSNS: Edge hopping nuthouse",
5440 { },
5441 INTERNAL | FLAG_NO_DATA,
5442 { },
5443 { { 0, 0xabababac } },
5444 .fill_helper = bpf_fill_maxinsns10,
5445 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005446 {
5447 "BPF_MAXINSNS: Jump, gap, jump, ...",
5448 { },
5449 CLASSIC | FLAG_NO_DATA,
5450 { },
5451 { { 0, 0xababcbac } },
5452 .fill_helper = bpf_fill_maxinsns11,
5453 },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005454 {
5455 "BPF_MAXINSNS: ld_abs+get_processor_id",
5456 { },
5457 CLASSIC,
5458 { },
5459 { { 1, 0xbee } },
5460 .fill_helper = bpf_fill_ld_abs_get_processor_id,
5461 },
5462 {
5463 "BPF_MAXINSNS: ld_abs+vlan_push/pop",
5464 { },
5465 INTERNAL,
5466 { 0x34 },
Daniel Borkmann0d906b12016-10-20 17:13:53 +02005467 { { ETH_HLEN, 0xbef } },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005468 .fill_helper = bpf_fill_ld_abs_vlan_push_pop,
5469 },
David Daneyb7127cf2017-06-13 16:49:36 -07005470 {
5471 "BPF_MAXINSNS: jump around ld_abs",
5472 { },
5473 INTERNAL,
5474 { 10, 11 },
5475 { { 2, 10 } },
5476 .fill_helper = bpf_fill_jump_around_ld_abs,
5477 },
Nicolas Schichan2cf1ad72015-08-04 15:19:09 +02005478 /*
5479 * LD_IND / LD_ABS on fragmented SKBs
5480 */
5481 {
5482 "LD_IND byte frag",
5483 .u.insns = {
5484 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5485 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
5486 BPF_STMT(BPF_RET | BPF_A, 0x0),
5487 },
5488 CLASSIC | FLAG_SKB_FRAG,
5489 { },
5490 { {0x40, 0x42} },
5491 .frag_data = {
5492 0x42, 0x00, 0x00, 0x00,
5493 0x43, 0x44, 0x00, 0x00,
5494 0x21, 0x07, 0x19, 0x83,
5495 },
5496 },
5497 {
5498 "LD_IND halfword frag",
5499 .u.insns = {
5500 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5501 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
5502 BPF_STMT(BPF_RET | BPF_A, 0x0),
5503 },
5504 CLASSIC | FLAG_SKB_FRAG,
5505 { },
5506 { {0x40, 0x4344} },
5507 .frag_data = {
5508 0x42, 0x00, 0x00, 0x00,
5509 0x43, 0x44, 0x00, 0x00,
5510 0x21, 0x07, 0x19, 0x83,
5511 },
5512 },
5513 {
5514 "LD_IND word frag",
5515 .u.insns = {
5516 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5517 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
5518 BPF_STMT(BPF_RET | BPF_A, 0x0),
5519 },
5520 CLASSIC | FLAG_SKB_FRAG,
5521 { },
5522 { {0x40, 0x21071983} },
5523 .frag_data = {
5524 0x42, 0x00, 0x00, 0x00,
5525 0x43, 0x44, 0x00, 0x00,
5526 0x21, 0x07, 0x19, 0x83,
5527 },
5528 },
5529 {
5530 "LD_IND halfword mixed head/frag",
5531 .u.insns = {
5532 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5533 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5534 BPF_STMT(BPF_RET | BPF_A, 0x0),
5535 },
5536 CLASSIC | FLAG_SKB_FRAG,
5537 { [0x3e] = 0x25, [0x3f] = 0x05, },
5538 { {0x40, 0x0519} },
5539 .frag_data = { 0x19, 0x82 },
5540 },
5541 {
5542 "LD_IND word mixed head/frag",
5543 .u.insns = {
5544 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5545 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5546 BPF_STMT(BPF_RET | BPF_A, 0x0),
5547 },
5548 CLASSIC | FLAG_SKB_FRAG,
5549 { [0x3e] = 0x25, [0x3f] = 0x05, },
5550 { {0x40, 0x25051982} },
5551 .frag_data = { 0x19, 0x82 },
5552 },
5553 {
5554 "LD_ABS byte frag",
5555 .u.insns = {
5556 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
5557 BPF_STMT(BPF_RET | BPF_A, 0x0),
5558 },
5559 CLASSIC | FLAG_SKB_FRAG,
5560 { },
5561 { {0x40, 0x42} },
5562 .frag_data = {
5563 0x42, 0x00, 0x00, 0x00,
5564 0x43, 0x44, 0x00, 0x00,
5565 0x21, 0x07, 0x19, 0x83,
5566 },
5567 },
5568 {
5569 "LD_ABS halfword frag",
5570 .u.insns = {
5571 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
5572 BPF_STMT(BPF_RET | BPF_A, 0x0),
5573 },
5574 CLASSIC | FLAG_SKB_FRAG,
5575 { },
5576 { {0x40, 0x4344} },
5577 .frag_data = {
5578 0x42, 0x00, 0x00, 0x00,
5579 0x43, 0x44, 0x00, 0x00,
5580 0x21, 0x07, 0x19, 0x83,
5581 },
5582 },
5583 {
5584 "LD_ABS word frag",
5585 .u.insns = {
5586 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
5587 BPF_STMT(BPF_RET | BPF_A, 0x0),
5588 },
5589 CLASSIC | FLAG_SKB_FRAG,
5590 { },
5591 { {0x40, 0x21071983} },
5592 .frag_data = {
5593 0x42, 0x00, 0x00, 0x00,
5594 0x43, 0x44, 0x00, 0x00,
5595 0x21, 0x07, 0x19, 0x83,
5596 },
5597 },
5598 {
5599 "LD_ABS halfword mixed head/frag",
5600 .u.insns = {
5601 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
5602 BPF_STMT(BPF_RET | BPF_A, 0x0),
5603 },
5604 CLASSIC | FLAG_SKB_FRAG,
5605 { [0x3e] = 0x25, [0x3f] = 0x05, },
5606 { {0x40, 0x0519} },
5607 .frag_data = { 0x19, 0x82 },
5608 },
5609 {
5610 "LD_ABS word mixed head/frag",
5611 .u.insns = {
5612 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
5613 BPF_STMT(BPF_RET | BPF_A, 0x0),
5614 },
5615 CLASSIC | FLAG_SKB_FRAG,
5616 { [0x3e] = 0x25, [0x3f] = 0x05, },
5617 { {0x40, 0x25051982} },
5618 .frag_data = { 0x19, 0x82 },
5619 },
Nicolas Schichan08fcb082015-08-04 15:19:11 +02005620 /*
5621 * LD_IND / LD_ABS on non fragmented SKBs
5622 */
5623 {
5624 /*
5625 * this tests that the JIT/interpreter correctly resets X
5626 * before using it in an LD_IND instruction.
5627 */
5628 "LD_IND byte default X",
5629 .u.insns = {
5630 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5631 BPF_STMT(BPF_RET | BPF_A, 0x0),
5632 },
5633 CLASSIC,
5634 { [0x1] = 0x42 },
5635 { {0x40, 0x42 } },
5636 },
5637 {
5638 "LD_IND byte positive offset",
5639 .u.insns = {
5640 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5641 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5642 BPF_STMT(BPF_RET | BPF_A, 0x0),
5643 },
5644 CLASSIC,
5645 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5646 { {0x40, 0x82 } },
5647 },
5648 {
5649 "LD_IND byte negative offset",
5650 .u.insns = {
5651 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5652 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
5653 BPF_STMT(BPF_RET | BPF_A, 0x0),
5654 },
5655 CLASSIC,
5656 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5657 { {0x40, 0x05 } },
5658 },
5659 {
5660 "LD_IND halfword positive offset",
5661 .u.insns = {
5662 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5663 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
5664 BPF_STMT(BPF_RET | BPF_A, 0x0),
5665 },
5666 CLASSIC,
5667 {
5668 [0x1c] = 0xaa, [0x1d] = 0x55,
5669 [0x1e] = 0xbb, [0x1f] = 0x66,
5670 [0x20] = 0xcc, [0x21] = 0x77,
5671 [0x22] = 0xdd, [0x23] = 0x88,
5672 },
5673 { {0x40, 0xdd88 } },
5674 },
5675 {
5676 "LD_IND halfword negative offset",
5677 .u.insns = {
5678 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5679 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
5680 BPF_STMT(BPF_RET | BPF_A, 0x0),
5681 },
5682 CLASSIC,
5683 {
5684 [0x1c] = 0xaa, [0x1d] = 0x55,
5685 [0x1e] = 0xbb, [0x1f] = 0x66,
5686 [0x20] = 0xcc, [0x21] = 0x77,
5687 [0x22] = 0xdd, [0x23] = 0x88,
5688 },
5689 { {0x40, 0xbb66 } },
5690 },
5691 {
5692 "LD_IND halfword unaligned",
5693 .u.insns = {
5694 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5695 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5696 BPF_STMT(BPF_RET | BPF_A, 0x0),
5697 },
5698 CLASSIC,
5699 {
5700 [0x1c] = 0xaa, [0x1d] = 0x55,
5701 [0x1e] = 0xbb, [0x1f] = 0x66,
5702 [0x20] = 0xcc, [0x21] = 0x77,
5703 [0x22] = 0xdd, [0x23] = 0x88,
5704 },
5705 { {0x40, 0x66cc } },
5706 },
5707 {
5708 "LD_IND word positive offset",
5709 .u.insns = {
5710 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5711 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
5712 BPF_STMT(BPF_RET | BPF_A, 0x0),
5713 },
5714 CLASSIC,
5715 {
5716 [0x1c] = 0xaa, [0x1d] = 0x55,
5717 [0x1e] = 0xbb, [0x1f] = 0x66,
5718 [0x20] = 0xcc, [0x21] = 0x77,
5719 [0x22] = 0xdd, [0x23] = 0x88,
5720 [0x24] = 0xee, [0x25] = 0x99,
5721 [0x26] = 0xff, [0x27] = 0xaa,
5722 },
5723 { {0x40, 0xee99ffaa } },
5724 },
5725 {
5726 "LD_IND word negative offset",
5727 .u.insns = {
5728 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5729 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
5730 BPF_STMT(BPF_RET | BPF_A, 0x0),
5731 },
5732 CLASSIC,
5733 {
5734 [0x1c] = 0xaa, [0x1d] = 0x55,
5735 [0x1e] = 0xbb, [0x1f] = 0x66,
5736 [0x20] = 0xcc, [0x21] = 0x77,
5737 [0x22] = 0xdd, [0x23] = 0x88,
5738 [0x24] = 0xee, [0x25] = 0x99,
5739 [0x26] = 0xff, [0x27] = 0xaa,
5740 },
5741 { {0x40, 0xaa55bb66 } },
5742 },
5743 {
5744 "LD_IND word unaligned (addr & 3 == 2)",
5745 .u.insns = {
5746 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5747 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5748 BPF_STMT(BPF_RET | BPF_A, 0x0),
5749 },
5750 CLASSIC,
5751 {
5752 [0x1c] = 0xaa, [0x1d] = 0x55,
5753 [0x1e] = 0xbb, [0x1f] = 0x66,
5754 [0x20] = 0xcc, [0x21] = 0x77,
5755 [0x22] = 0xdd, [0x23] = 0x88,
5756 [0x24] = 0xee, [0x25] = 0x99,
5757 [0x26] = 0xff, [0x27] = 0xaa,
5758 },
5759 { {0x40, 0xbb66cc77 } },
5760 },
5761 {
5762 "LD_IND word unaligned (addr & 3 == 1)",
5763 .u.insns = {
5764 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5765 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
5766 BPF_STMT(BPF_RET | BPF_A, 0x0),
5767 },
5768 CLASSIC,
5769 {
5770 [0x1c] = 0xaa, [0x1d] = 0x55,
5771 [0x1e] = 0xbb, [0x1f] = 0x66,
5772 [0x20] = 0xcc, [0x21] = 0x77,
5773 [0x22] = 0xdd, [0x23] = 0x88,
5774 [0x24] = 0xee, [0x25] = 0x99,
5775 [0x26] = 0xff, [0x27] = 0xaa,
5776 },
5777 { {0x40, 0x55bb66cc } },
5778 },
5779 {
5780 "LD_IND word unaligned (addr & 3 == 3)",
5781 .u.insns = {
5782 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5783 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
5784 BPF_STMT(BPF_RET | BPF_A, 0x0),
5785 },
5786 CLASSIC,
5787 {
5788 [0x1c] = 0xaa, [0x1d] = 0x55,
5789 [0x1e] = 0xbb, [0x1f] = 0x66,
5790 [0x20] = 0xcc, [0x21] = 0x77,
5791 [0x22] = 0xdd, [0x23] = 0x88,
5792 [0x24] = 0xee, [0x25] = 0x99,
5793 [0x26] = 0xff, [0x27] = 0xaa,
5794 },
5795 { {0x40, 0x66cc77dd } },
5796 },
5797 {
5798 "LD_ABS byte",
5799 .u.insns = {
5800 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
5801 BPF_STMT(BPF_RET | BPF_A, 0x0),
5802 },
5803 CLASSIC,
5804 {
5805 [0x1c] = 0xaa, [0x1d] = 0x55,
5806 [0x1e] = 0xbb, [0x1f] = 0x66,
5807 [0x20] = 0xcc, [0x21] = 0x77,
5808 [0x22] = 0xdd, [0x23] = 0x88,
5809 [0x24] = 0xee, [0x25] = 0x99,
5810 [0x26] = 0xff, [0x27] = 0xaa,
5811 },
5812 { {0x40, 0xcc } },
5813 },
5814 {
5815 "LD_ABS halfword",
5816 .u.insns = {
5817 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
5818 BPF_STMT(BPF_RET | BPF_A, 0x0),
5819 },
5820 CLASSIC,
5821 {
5822 [0x1c] = 0xaa, [0x1d] = 0x55,
5823 [0x1e] = 0xbb, [0x1f] = 0x66,
5824 [0x20] = 0xcc, [0x21] = 0x77,
5825 [0x22] = 0xdd, [0x23] = 0x88,
5826 [0x24] = 0xee, [0x25] = 0x99,
5827 [0x26] = 0xff, [0x27] = 0xaa,
5828 },
5829 { {0x40, 0xdd88 } },
5830 },
5831 {
5832 "LD_ABS halfword unaligned",
5833 .u.insns = {
5834 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
5835 BPF_STMT(BPF_RET | BPF_A, 0x0),
5836 },
5837 CLASSIC,
5838 {
5839 [0x1c] = 0xaa, [0x1d] = 0x55,
5840 [0x1e] = 0xbb, [0x1f] = 0x66,
5841 [0x20] = 0xcc, [0x21] = 0x77,
5842 [0x22] = 0xdd, [0x23] = 0x88,
5843 [0x24] = 0xee, [0x25] = 0x99,
5844 [0x26] = 0xff, [0x27] = 0xaa,
5845 },
5846 { {0x40, 0x99ff } },
5847 },
5848 {
5849 "LD_ABS word",
5850 .u.insns = {
5851 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
5852 BPF_STMT(BPF_RET | BPF_A, 0x0),
5853 },
5854 CLASSIC,
5855 {
5856 [0x1c] = 0xaa, [0x1d] = 0x55,
5857 [0x1e] = 0xbb, [0x1f] = 0x66,
5858 [0x20] = 0xcc, [0x21] = 0x77,
5859 [0x22] = 0xdd, [0x23] = 0x88,
5860 [0x24] = 0xee, [0x25] = 0x99,
5861 [0x26] = 0xff, [0x27] = 0xaa,
5862 },
5863 { {0x40, 0xaa55bb66 } },
5864 },
5865 {
5866 "LD_ABS word unaligned (addr & 3 == 2)",
5867 .u.insns = {
5868 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
5869 BPF_STMT(BPF_RET | BPF_A, 0x0),
5870 },
5871 CLASSIC,
5872 {
5873 [0x1c] = 0xaa, [0x1d] = 0x55,
5874 [0x1e] = 0xbb, [0x1f] = 0x66,
5875 [0x20] = 0xcc, [0x21] = 0x77,
5876 [0x22] = 0xdd, [0x23] = 0x88,
5877 [0x24] = 0xee, [0x25] = 0x99,
5878 [0x26] = 0xff, [0x27] = 0xaa,
5879 },
5880 { {0x40, 0xdd88ee99 } },
5881 },
5882 {
5883 "LD_ABS word unaligned (addr & 3 == 1)",
5884 .u.insns = {
5885 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
5886 BPF_STMT(BPF_RET | BPF_A, 0x0),
5887 },
5888 CLASSIC,
5889 {
5890 [0x1c] = 0xaa, [0x1d] = 0x55,
5891 [0x1e] = 0xbb, [0x1f] = 0x66,
5892 [0x20] = 0xcc, [0x21] = 0x77,
5893 [0x22] = 0xdd, [0x23] = 0x88,
5894 [0x24] = 0xee, [0x25] = 0x99,
5895 [0x26] = 0xff, [0x27] = 0xaa,
5896 },
5897 { {0x40, 0x77dd88ee } },
5898 },
5899 {
5900 "LD_ABS word unaligned (addr & 3 == 3)",
5901 .u.insns = {
5902 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
5903 BPF_STMT(BPF_RET | BPF_A, 0x0),
5904 },
5905 CLASSIC,
5906 {
5907 [0x1c] = 0xaa, [0x1d] = 0x55,
5908 [0x1e] = 0xbb, [0x1f] = 0x66,
5909 [0x20] = 0xcc, [0x21] = 0x77,
5910 [0x22] = 0xdd, [0x23] = 0x88,
5911 [0x24] = 0xee, [0x25] = 0x99,
5912 [0x26] = 0xff, [0x27] = 0xaa,
5913 },
5914 { {0x40, 0x88ee99ff } },
5915 },
Nicolas Schichan86bf1722015-08-04 15:19:12 +02005916 /*
5917 * verify that the interpreter or JIT correctly sets A and X
5918 * to 0.
5919 */
5920 {
5921 "ADD default X",
5922 .u.insns = {
5923 /*
5924 * A = 0x42
5925 * A = A + X
5926 * ret A
5927 */
5928 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5929 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
5930 BPF_STMT(BPF_RET | BPF_A, 0x0),
5931 },
5932 CLASSIC | FLAG_NO_DATA,
5933 {},
5934 { {0x1, 0x42 } },
5935 },
5936 {
5937 "ADD default A",
5938 .u.insns = {
5939 /*
5940 * A = A + 0x42
5941 * ret A
5942 */
5943 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
5944 BPF_STMT(BPF_RET | BPF_A, 0x0),
5945 },
5946 CLASSIC | FLAG_NO_DATA,
5947 {},
5948 { {0x1, 0x42 } },
5949 },
5950 {
5951 "SUB default X",
5952 .u.insns = {
5953 /*
5954 * A = 0x66
5955 * A = A - X
5956 * ret A
5957 */
5958 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
5959 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
5960 BPF_STMT(BPF_RET | BPF_A, 0x0),
5961 },
5962 CLASSIC | FLAG_NO_DATA,
5963 {},
5964 { {0x1, 0x66 } },
5965 },
5966 {
5967 "SUB default A",
5968 .u.insns = {
5969 /*
5970 * A = A - -0x66
5971 * ret A
5972 */
5973 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
5974 BPF_STMT(BPF_RET | BPF_A, 0x0),
5975 },
5976 CLASSIC | FLAG_NO_DATA,
5977 {},
5978 { {0x1, 0x66 } },
5979 },
5980 {
5981 "MUL default X",
5982 .u.insns = {
5983 /*
5984 * A = 0x42
5985 * A = A * X
5986 * ret A
5987 */
5988 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
5989 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
5990 BPF_STMT(BPF_RET | BPF_A, 0x0),
5991 },
5992 CLASSIC | FLAG_NO_DATA,
5993 {},
5994 { {0x1, 0x0 } },
5995 },
5996 {
5997 "MUL default A",
5998 .u.insns = {
5999 /*
6000 * A = A * 0x66
6001 * ret A
6002 */
6003 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
6004 BPF_STMT(BPF_RET | BPF_A, 0x0),
6005 },
6006 CLASSIC | FLAG_NO_DATA,
6007 {},
6008 { {0x1, 0x0 } },
6009 },
6010 {
6011 "DIV default X",
6012 .u.insns = {
6013 /*
6014 * A = 0x42
6015 * A = A / X ; this halt the filter execution if X is 0
6016 * ret 0x42
6017 */
6018 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6019 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
6020 BPF_STMT(BPF_RET | BPF_K, 0x42),
6021 },
6022 CLASSIC | FLAG_NO_DATA,
6023 {},
6024 { {0x1, 0x0 } },
6025 },
6026 {
6027 "DIV default A",
6028 .u.insns = {
6029 /*
6030 * A = A / 1
6031 * ret A
6032 */
6033 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
6034 BPF_STMT(BPF_RET | BPF_A, 0x0),
6035 },
6036 CLASSIC | FLAG_NO_DATA,
6037 {},
6038 { {0x1, 0x0 } },
6039 },
6040 {
Yang Shid4e4bc12015-11-04 11:36:37 -08006041 "MOD default X",
6042 .u.insns = {
6043 /*
6044 * A = 0x42
6045 * A = A mod X ; this halt the filter execution if X is 0
6046 * ret 0x42
6047 */
6048 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6049 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
6050 BPF_STMT(BPF_RET | BPF_K, 0x42),
6051 },
6052 CLASSIC | FLAG_NO_DATA,
6053 {},
6054 { {0x1, 0x0 } },
6055 },
6056 {
6057 "MOD default A",
6058 .u.insns = {
6059 /*
6060 * A = A mod 1
6061 * ret A
6062 */
6063 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
6064 BPF_STMT(BPF_RET | BPF_A, 0x0),
6065 },
6066 CLASSIC | FLAG_NO_DATA,
6067 {},
6068 { {0x1, 0x0 } },
6069 },
6070 {
Nicolas Schichan86bf1722015-08-04 15:19:12 +02006071 "JMP EQ default A",
6072 .u.insns = {
6073 /*
6074 * cmp A, 0x0, 0, 1
6075 * ret 0x42
6076 * ret 0x66
6077 */
6078 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
6079 BPF_STMT(BPF_RET | BPF_K, 0x42),
6080 BPF_STMT(BPF_RET | BPF_K, 0x66),
6081 },
6082 CLASSIC | FLAG_NO_DATA,
6083 {},
6084 { {0x1, 0x42 } },
6085 },
6086 {
6087 "JMP EQ default X",
6088 .u.insns = {
6089 /*
6090 * A = 0x0
6091 * cmp A, X, 0, 1
6092 * ret 0x42
6093 * ret 0x66
6094 */
6095 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
6096 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
6097 BPF_STMT(BPF_RET | BPF_K, 0x42),
6098 BPF_STMT(BPF_RET | BPF_K, 0x66),
6099 },
6100 CLASSIC | FLAG_NO_DATA,
6101 {},
6102 { {0x1, 0x42 } },
6103 },
Daniel Borkmann87ab8192017-12-14 21:07:27 +01006104 {
6105 "LD_ABS with helper changing skb data",
6106 { },
6107 INTERNAL,
6108 { 0x34 },
6109 { { ETH_HLEN, 42 } },
6110 .fill_helper = bpf_fill_ld_abs_vlan_push_pop2,
6111 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006112};
6113
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006114static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006115
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006116static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006117{
6118 struct sk_buff *skb;
6119
6120 if (size >= MAX_DATA)
6121 return NULL;
6122
6123 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
6124 if (!skb)
6125 return NULL;
6126
yuan linyude77b962017-06-18 22:48:17 +08006127 __skb_put_data(skb, buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006128
6129 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006130 skb_reset_mac_header(skb);
6131 skb->protocol = htons(ETH_P_IP);
6132 skb->pkt_type = SKB_TYPE;
6133 skb->mark = SKB_MARK;
6134 skb->hash = SKB_HASH;
6135 skb->queue_mapping = SKB_QUEUE_MAP;
6136 skb->vlan_tci = SKB_VLAN_TCI;
Jakub Kicinski5c0ca3f2016-09-12 13:04:57 +01006137 skb->vlan_proto = htons(ETH_P_IP);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006138 skb->dev = &dev;
6139 skb->dev->ifindex = SKB_DEV_IFINDEX;
6140 skb->dev->type = SKB_DEV_TYPE;
6141 skb_set_network_header(skb, min(size, ETH_HLEN));
6142
6143 return skb;
6144}
6145
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006146static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006147{
Nicolas Schichanbac142a2015-08-04 15:19:08 +02006148 struct sk_buff *skb;
6149 struct page *page;
6150
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006151 if (test->aux & FLAG_NO_DATA)
6152 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006153
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006154 /* Test case expects an skb, so populate one. Various
6155 * subtests generate skbs of different sizes based on
6156 * the same data.
6157 */
Nicolas Schichanbac142a2015-08-04 15:19:08 +02006158 skb = populate_skb(test->data, test->test[sub].data_size);
6159 if (!skb)
6160 return NULL;
6161
6162 if (test->aux & FLAG_SKB_FRAG) {
6163 /*
6164 * when the test requires a fragmented skb, add a
6165 * single fragment to the skb, filled with
6166 * test->frag_data.
6167 */
6168 void *ptr;
6169
6170 page = alloc_page(GFP_KERNEL);
6171
6172 if (!page)
6173 goto err_kfree_skb;
6174
6175 ptr = kmap(page);
6176 if (!ptr)
6177 goto err_free_page;
6178 memcpy(ptr, test->frag_data, MAX_DATA);
6179 kunmap(page);
6180 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
6181 }
6182
6183 return skb;
6184
6185err_free_page:
6186 __free_page(page);
6187err_kfree_skb:
6188 kfree_skb(skb);
6189 return NULL;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006190}
6191
6192static void release_test_data(const struct bpf_test *test, void *data)
6193{
6194 if (test->aux & FLAG_NO_DATA)
6195 return;
6196
6197 kfree_skb(data);
6198}
6199
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006200static int filter_length(int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006201{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006202 struct sock_filter *fp;
6203 int len;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006204
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006205 if (tests[which].fill_helper)
6206 return tests[which].u.ptr.len;
6207
6208 fp = tests[which].u.insns;
Chema Gonzaleze9d94502014-05-30 10:15:12 -07006209 for (len = MAX_INSNS - 1; len > 0; --len)
6210 if (fp[len].code != 0 || fp[len].k != 0)
6211 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006212
Chema Gonzaleze9d94502014-05-30 10:15:12 -07006213 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006214}
6215
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006216static void *filter_pointer(int which)
6217{
6218 if (tests[which].fill_helper)
6219 return tests[which].u.ptr.insns;
6220 else
6221 return tests[which].u.insns;
6222}
6223
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006224static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006225{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006226 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006227 unsigned int flen = filter_length(which);
6228 void *fptr = filter_pointer(which);
6229 struct sock_fprog_kern fprog;
6230 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006231
6232 switch (test_type) {
6233 case CLASSIC:
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006234 fprog.filter = fptr;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006235 fprog.len = flen;
6236
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006237 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006238 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
6239 if (*err == -EINVAL) {
6240 pr_cont("PASS\n");
6241 /* Verifier rejected filter as expected. */
6242 *err = 0;
6243 return NULL;
6244 } else {
6245 pr_cont("UNEXPECTED_PASS\n");
6246 /* Verifier didn't reject the test that's
6247 * bad enough, just return!
6248 */
6249 *err = -EINVAL;
6250 return NULL;
6251 }
6252 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006253 if (*err) {
Alexei Starovoitov290af862018-01-09 10:04:29 -08006254 pr_cont("FAIL to prog_create err=%d len=%d\n",
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006255 *err, fprog.len);
6256 return NULL;
6257 }
6258 break;
6259
6260 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02006261 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006262 if (fp == NULL) {
6263 pr_cont("UNEXPECTED_FAIL no memory left\n");
6264 *err = -ENOMEM;
6265 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006266 }
6267
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006268 fp->len = flen;
Daniel Borkmann4962fa12015-07-30 12:42:46 +02006269 /* Type doesn't really matter here as long as it's not unspec. */
6270 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006271 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov105c0362017-05-30 13:31:32 -07006272 fp->aux->stack_depth = tests[which].stack_depth;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006273
Daniel Borkmannd1c55ab2016-05-13 19:08:31 +02006274 /* We cannot error here as we don't need type compatibility
6275 * checks.
6276 */
6277 fp = bpf_prog_select_runtime(fp, err);
Alexei Starovoitov290af862018-01-09 10:04:29 -08006278 if (*err) {
6279 pr_cont("FAIL to select_runtime err=%d\n", *err);
6280 return NULL;
6281 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006282 break;
6283 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006284
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006285 *err = 0;
6286 return fp;
6287}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006288
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006289static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006290{
6291 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006292
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006293 switch (test_type) {
6294 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006295 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006296 break;
6297 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006298 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006299 break;
6300 }
6301}
6302
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006303static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006304 int runs, u64 *duration)
6305{
6306 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07006307 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006308
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07006309 start = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006310
6311 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006312 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006313
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07006314 finish = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006315
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07006316 *duration = finish - start;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006317 do_div(*duration, runs);
6318
6319 return ret;
6320}
6321
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006322static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006323{
6324 int err_cnt = 0, i, runs = MAX_TESTRUNS;
6325
6326 for (i = 0; i < MAX_SUBTESTS; i++) {
6327 void *data;
6328 u64 duration;
6329 u32 ret;
6330
6331 if (test->test[i].data_size == 0 &&
6332 test->test[i].result == 0)
6333 break;
6334
6335 data = generate_test_data(test, i);
Nicolas Schichane34684f2015-08-04 15:19:07 +02006336 if (!data && !(test->aux & FLAG_NO_DATA)) {
6337 pr_cont("data generation failed ");
6338 err_cnt++;
6339 break;
6340 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006341 ret = __run_one(fp, data, runs, &duration);
6342 release_test_data(test, data);
6343
6344 if (ret == test->test[i].result) {
6345 pr_cont("%lld ", duration);
6346 } else {
6347 pr_cont("ret %d != %d ", ret,
6348 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006349 err_cnt++;
6350 }
6351 }
6352
6353 return err_cnt;
6354}
6355
Nicolas Schichand2648d42015-08-04 15:19:10 +02006356static char test_name[64];
6357module_param_string(test_name, test_name, sizeof(test_name), 0);
6358
6359static int test_id = -1;
6360module_param(test_id, int, 0);
6361
6362static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
6363module_param_array(test_range, int, NULL, 0);
6364
6365static __init int find_test_index(const char *test_name)
6366{
6367 int i;
6368
6369 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6370 if (!strcmp(tests[i].descr, test_name))
6371 return i;
6372 }
6373 return -1;
6374}
6375
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006376static __init int prepare_bpf_tests(void)
6377{
6378 int i;
6379
Nicolas Schichand2648d42015-08-04 15:19:10 +02006380 if (test_id >= 0) {
6381 /*
6382 * if a test_id was specified, use test_range to
6383 * cover only that test.
6384 */
6385 if (test_id >= ARRAY_SIZE(tests)) {
6386 pr_err("test_bpf: invalid test_id specified.\n");
6387 return -EINVAL;
6388 }
6389
6390 test_range[0] = test_id;
6391 test_range[1] = test_id;
6392 } else if (*test_name) {
6393 /*
6394 * if a test_name was specified, find it and setup
6395 * test_range to cover only that test.
6396 */
6397 int idx = find_test_index(test_name);
6398
6399 if (idx < 0) {
6400 pr_err("test_bpf: no test named '%s' found.\n",
6401 test_name);
6402 return -EINVAL;
6403 }
6404 test_range[0] = idx;
6405 test_range[1] = idx;
6406 } else {
6407 /*
6408 * check that the supplied test_range is valid.
6409 */
6410 if (test_range[0] >= ARRAY_SIZE(tests) ||
6411 test_range[1] >= ARRAY_SIZE(tests) ||
6412 test_range[0] < 0 || test_range[1] < 0) {
6413 pr_err("test_bpf: test_range is out of bound.\n");
6414 return -EINVAL;
6415 }
6416
6417 if (test_range[1] < test_range[0]) {
6418 pr_err("test_bpf: test_range is ending before it starts.\n");
6419 return -EINVAL;
6420 }
6421 }
6422
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006423 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6424 if (tests[i].fill_helper &&
6425 tests[i].fill_helper(&tests[i]) < 0)
6426 return -ENOMEM;
6427 }
6428
6429 return 0;
6430}
6431
6432static __init void destroy_bpf_tests(void)
6433{
6434 int i;
6435
6436 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6437 if (tests[i].fill_helper)
6438 kfree(tests[i].u.ptr.insns);
6439 }
6440}
6441
Nicolas Schichand2648d42015-08-04 15:19:10 +02006442static bool exclude_test(int test_id)
6443{
6444 return test_id < test_range[0] || test_id > test_range[1];
6445}
6446
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006447static __init int test_bpf(void)
6448{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006449 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02006450 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006451
6452 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006453 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006454 int err;
6455
Nicolas Schichand2648d42015-08-04 15:19:10 +02006456 if (exclude_test(i))
6457 continue;
6458
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006459 pr_info("#%d %s ", i, tests[i].descr);
6460
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006461 fp = generate_filter(i, &err);
6462 if (fp == NULL) {
6463 if (err == 0) {
6464 pass_cnt++;
6465 continue;
6466 }
Alexei Starovoitov290af862018-01-09 10:04:29 -08006467 err_cnt++;
6468 continue;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006469 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02006470
6471 pr_cont("jited:%u ", fp->jited);
6472
6473 run_cnt++;
6474 if (fp->jited)
6475 jit_cnt++;
6476
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006477 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006478 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006479
6480 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006481 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006482 err_cnt++;
6483 } else {
6484 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006485 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006486 }
6487 }
6488
Daniel Borkmann327941f2015-04-30 16:17:27 +02006489 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6490 pass_cnt, err_cnt, jit_cnt, run_cnt);
6491
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006492 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006493}
6494
6495static int __init test_bpf_init(void)
6496{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006497 int ret;
6498
6499 ret = prepare_bpf_tests();
6500 if (ret < 0)
6501 return ret;
6502
6503 ret = test_bpf();
6504
6505 destroy_bpf_tests();
6506 return ret;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006507}
6508
6509static void __exit test_bpf_exit(void)
6510{
6511}
6512
6513module_init(test_bpf_init);
6514module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006515
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006516MODULE_LICENSE("GPL");