blob: 08d3d59dca17343c1a91def02d0a7da931c1c0f0 [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>
Eric Dumazetd40bc962018-02-26 10:52:46 -080027#include <linux/sched.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070028
Daniel Borkmann10f18e02014-05-23 18:44:00 +020029/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070030#define MAX_SUBTESTS 3
Eric Dumazet9960d762018-02-28 08:39:20 -080031#define MAX_TESTRUNS 1000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070032#define MAX_DATA 128
33#define MAX_INSNS 512
34#define MAX_K 0xffffFFFF
35
Daniel Borkmann10f18e02014-05-23 18:44:00 +020036/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070037#define SKB_TYPE 3
38#define SKB_MARK 0x1234aaaa
39#define SKB_HASH 0x1234aaab
40#define SKB_QUEUE_MAP 123
41#define SKB_VLAN_TCI 0xffff
42#define SKB_DEV_IFINDEX 577
43#define SKB_DEV_TYPE 588
44
Daniel Borkmann10f18e02014-05-23 18:44:00 +020045/* Redefine REGs to make tests less verbose */
46#define R0 BPF_REG_0
47#define R1 BPF_REG_1
48#define R2 BPF_REG_2
49#define R3 BPF_REG_3
50#define R4 BPF_REG_4
51#define R5 BPF_REG_5
52#define R6 BPF_REG_6
53#define R7 BPF_REG_7
54#define R8 BPF_REG_8
55#define R9 BPF_REG_9
56#define R10 BPF_REG_10
57
58/* Flags that can be passed to test cases */
59#define FLAG_NO_DATA BIT(0)
60#define FLAG_EXPECTED_FAIL BIT(1)
Nicolas Schichanbac142a2015-08-04 15:19:08 +020061#define FLAG_SKB_FRAG BIT(2)
Daniel Borkmann10f18e02014-05-23 18:44:00 +020062
63enum {
64 CLASSIC = BIT(6), /* Old BPF instructions only. */
65 INTERNAL = BIT(7), /* Extended instruction set. */
66};
67
68#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070069
70struct bpf_test {
71 const char *descr;
72 union {
73 struct sock_filter insns[MAX_INSNS];
Alexei Starovoitov2695fb52014-07-24 16:38:21 -070074 struct bpf_insn insns_int[MAX_INSNS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020075 struct {
76 void *insns;
77 unsigned int len;
78 } ptr;
Andrew Mortonece80492014-05-22 10:16:46 -070079 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020080 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070081 __u8 data[MAX_DATA];
82 struct {
83 int data_size;
84 __u32 result;
85 } test[MAX_SUBTESTS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020086 int (*fill_helper)(struct bpf_test *self);
Yonghong Song09584b42018-02-02 22:37:15 -080087 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
Nicolas Schichanbac142a2015-08-04 15:19:08 +020088 __u8 frag_data[MAX_DATA];
Alexei Starovoitov105c0362017-05-30 13:31:32 -070089 int stack_depth; /* for eBPF only, since tests don't call verifier */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070090};
91
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020092/* Large test cases need separate allocation and fill handler. */
93
94static int bpf_fill_maxinsns1(struct bpf_test *self)
95{
96 unsigned int len = BPF_MAXINSNS;
97 struct sock_filter *insn;
98 __u32 k = ~0;
99 int i;
100
101 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
102 if (!insn)
103 return -ENOMEM;
104
105 for (i = 0; i < len; i++, k--)
106 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
107
108 self->u.ptr.insns = insn;
109 self->u.ptr.len = len;
110
111 return 0;
112}
113
114static int bpf_fill_maxinsns2(struct bpf_test *self)
115{
116 unsigned int len = BPF_MAXINSNS;
117 struct sock_filter *insn;
118 int i;
119
120 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
121 if (!insn)
122 return -ENOMEM;
123
124 for (i = 0; i < len; i++)
125 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
126
127 self->u.ptr.insns = insn;
128 self->u.ptr.len = len;
129
130 return 0;
131}
132
133static int bpf_fill_maxinsns3(struct bpf_test *self)
134{
135 unsigned int len = BPF_MAXINSNS;
136 struct sock_filter *insn;
137 struct rnd_state rnd;
138 int i;
139
140 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
141 if (!insn)
142 return -ENOMEM;
143
144 prandom_seed_state(&rnd, 3141592653589793238ULL);
145
146 for (i = 0; i < len - 1; i++) {
147 __u32 k = prandom_u32_state(&rnd);
148
149 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
150 }
151
152 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
153
154 self->u.ptr.insns = insn;
155 self->u.ptr.len = len;
156
157 return 0;
158}
159
160static int bpf_fill_maxinsns4(struct bpf_test *self)
161{
162 unsigned int len = BPF_MAXINSNS + 1;
163 struct sock_filter *insn;
164 int i;
165
166 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
167 if (!insn)
168 return -ENOMEM;
169
170 for (i = 0; i < len; i++)
171 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
172
173 self->u.ptr.insns = insn;
174 self->u.ptr.len = len;
175
176 return 0;
177}
178
179static int bpf_fill_maxinsns5(struct bpf_test *self)
180{
181 unsigned int len = BPF_MAXINSNS;
182 struct sock_filter *insn;
183 int i;
184
185 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
186 if (!insn)
187 return -ENOMEM;
188
189 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
190
191 for (i = 1; i < len - 1; i++)
192 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
193
194 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
195
196 self->u.ptr.insns = insn;
197 self->u.ptr.len = len;
198
199 return 0;
200}
201
202static int bpf_fill_maxinsns6(struct bpf_test *self)
203{
204 unsigned int len = BPF_MAXINSNS;
205 struct sock_filter *insn;
206 int i;
207
208 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
209 if (!insn)
210 return -ENOMEM;
211
212 for (i = 0; i < len - 1; i++)
213 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
214 SKF_AD_VLAN_TAG_PRESENT);
215
216 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
217
218 self->u.ptr.insns = insn;
219 self->u.ptr.len = len;
220
221 return 0;
222}
223
224static int bpf_fill_maxinsns7(struct bpf_test *self)
225{
226 unsigned int len = BPF_MAXINSNS;
227 struct sock_filter *insn;
228 int i;
229
230 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
231 if (!insn)
232 return -ENOMEM;
233
234 for (i = 0; i < len - 4; i++)
235 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
236 SKF_AD_CPU);
237
238 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
239 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
240 SKF_AD_CPU);
241 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
242 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
243
244 self->u.ptr.insns = insn;
245 self->u.ptr.len = len;
246
247 return 0;
248}
249
250static int bpf_fill_maxinsns8(struct bpf_test *self)
251{
252 unsigned int len = BPF_MAXINSNS;
253 struct sock_filter *insn;
254 int i, jmp_off = len - 3;
255
256 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
257 if (!insn)
258 return -ENOMEM;
259
260 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
261
262 for (i = 1; i < len - 1; i++)
263 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
264
265 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
266
267 self->u.ptr.insns = insn;
268 self->u.ptr.len = len;
269
270 return 0;
271}
272
Daniel Borkmann3b529602015-05-23 01:10:07 +0200273static int bpf_fill_maxinsns9(struct bpf_test *self)
274{
275 unsigned int len = BPF_MAXINSNS;
276 struct bpf_insn *insn;
277 int i;
278
279 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
280 if (!insn)
281 return -ENOMEM;
282
283 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
284 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
285 insn[2] = BPF_EXIT_INSN();
286
287 for (i = 3; i < len - 2; i++)
288 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
289
290 insn[len - 2] = BPF_EXIT_INSN();
291 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
292
293 self->u.ptr.insns = insn;
294 self->u.ptr.len = len;
295
296 return 0;
297}
298
299static int bpf_fill_maxinsns10(struct bpf_test *self)
300{
301 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
302 struct bpf_insn *insn;
303 int i;
304
305 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
306 if (!insn)
307 return -ENOMEM;
308
309 for (i = 0; i < hlen / 2; i++)
310 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
311 for (i = hlen - 1; i > hlen / 2; i--)
312 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
313
314 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
315 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
316 insn[hlen + 1] = BPF_EXIT_INSN();
317
318 self->u.ptr.insns = insn;
319 self->u.ptr.len = len;
320
321 return 0;
322}
323
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200324static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
325 unsigned int plen)
326{
327 struct sock_filter *insn;
328 unsigned int rlen;
329 int i, j;
330
331 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
332 if (!insn)
333 return -ENOMEM;
334
335 rlen = (len % plen) - 1;
336
337 for (i = 0; i + plen < len; i += plen)
338 for (j = 0; j < plen; j++)
339 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
340 plen - 1 - j, 0, 0);
341 for (j = 0; j < rlen; j++)
342 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
343 0, 0);
344
345 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
346
347 self->u.ptr.insns = insn;
348 self->u.ptr.len = len;
349
350 return 0;
351}
352
353static int bpf_fill_maxinsns11(struct bpf_test *self)
354{
355 /* Hits 70 passes on x86_64, so cannot get JITed there. */
356 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
357}
358
Daniel Borkmannbe088152018-06-02 23:06:32 +0200359static int bpf_fill_maxinsns12(struct bpf_test *self)
360{
361 unsigned int len = BPF_MAXINSNS;
362 struct sock_filter *insn;
363 int i = 0;
364
365 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
366 if (!insn)
367 return -ENOMEM;
368
369 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
370
371 for (i = 1; i < len - 1; i++)
372 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
373
374 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
375
376 self->u.ptr.insns = insn;
377 self->u.ptr.len = len;
378
379 return 0;
380}
381
382static int bpf_fill_maxinsns13(struct bpf_test *self)
383{
384 unsigned int len = BPF_MAXINSNS;
385 struct sock_filter *insn;
386 int i = 0;
387
388 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
389 if (!insn)
390 return -ENOMEM;
391
392 for (i = 0; i < len - 3; i++)
393 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
394
395 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab);
396 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0);
397 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
398
399 self->u.ptr.insns = insn;
400 self->u.ptr.len = len;
401
402 return 0;
403}
404
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200405static int bpf_fill_ja(struct bpf_test *self)
406{
407 /* Hits exactly 11 passes on x86_64 JIT. */
408 return __bpf_fill_ja(self, 12, 9);
409}
410
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -0700411static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
412{
413 unsigned int len = BPF_MAXINSNS;
414 struct sock_filter *insn;
415 int i;
416
417 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
418 if (!insn)
419 return -ENOMEM;
420
421 for (i = 0; i < len - 1; i += 2) {
422 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
423 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
424 SKF_AD_OFF + SKF_AD_CPU);
425 }
426
427 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
428
429 self->u.ptr.insns = insn;
430 self->u.ptr.len = len;
431
432 return 0;
433}
434
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200435static int __bpf_fill_stxdw(struct bpf_test *self, int size)
436{
437 unsigned int len = BPF_MAXINSNS;
438 struct bpf_insn *insn;
439 int i;
440
441 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
442 if (!insn)
443 return -ENOMEM;
444
445 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
446 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
447
448 for (i = 2; i < len - 2; i++)
449 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
450
451 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
452 insn[len - 1] = BPF_EXIT_INSN();
453
454 self->u.ptr.insns = insn;
455 self->u.ptr.len = len;
Alexei Starovoitov105c0362017-05-30 13:31:32 -0700456 self->stack_depth = 40;
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200457
458 return 0;
459}
460
461static int bpf_fill_stxw(struct bpf_test *self)
462{
463 return __bpf_fill_stxdw(self, BPF_W);
464}
465
466static int bpf_fill_stxdw(struct bpf_test *self)
467{
468 return __bpf_fill_stxdw(self, BPF_DW);
469}
470
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700471static struct bpf_test tests[] = {
472 {
473 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -0700474 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700475 BPF_STMT(BPF_LD | BPF_IMM, 1),
476 BPF_STMT(BPF_MISC | BPF_TAX, 0),
477 BPF_STMT(BPF_LD | BPF_IMM, 2),
478 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
479 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
480 BPF_STMT(BPF_MISC | BPF_TAX, 0),
481 BPF_STMT(BPF_LD | BPF_LEN, 0),
482 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
483 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
484 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
485 BPF_STMT(BPF_RET | BPF_A, 0)
486 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200487 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700488 { 10, 20, 30, 40, 50 },
489 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
490 },
491 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700492 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700493 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700494 BPF_STMT(BPF_LDX | BPF_LEN, 0),
495 BPF_STMT(BPF_MISC | BPF_TXA, 0),
496 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
497 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
498 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200499 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700500 { 10, 20, 30, 40, 50 },
501 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
502 },
503 {
504 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700505 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700506 BPF_STMT(BPF_LD | BPF_IMM, 1),
507 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
508 BPF_STMT(BPF_LDX | BPF_IMM, 3),
509 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
510 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
511 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
512 BPF_STMT(BPF_RET | BPF_A, 0)
513 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200514 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700515 { },
516 { { 0, 0xfffffffd } }
517 },
518 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300519 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700520 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700521 BPF_STMT(BPF_LD | BPF_IMM, 8),
522 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
523 BPF_STMT(BPF_MISC | BPF_TAX, 0),
524 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
525 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
526 BPF_STMT(BPF_MISC | BPF_TAX, 0),
527 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
528 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300529 BPF_STMT(BPF_MISC | BPF_TAX, 0),
530 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
531 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
532 BPF_STMT(BPF_MISC | BPF_TAX, 0),
533 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
534 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700535 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
536 BPF_STMT(BPF_RET | BPF_A, 0)
537 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200538 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700539 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300540 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700541 },
542 {
543 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700544 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700545 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
546 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
547 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
548 BPF_STMT(BPF_MISC | BPF_TAX, 0),
549 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
550 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
551 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
552 BPF_STMT(BPF_RET | BPF_A, 0)
553 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200554 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700555 { },
556 { { 0, 0x800000ff }, { 1, 0x800000ff } },
557 },
558 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700559 "LD_IMM_0",
560 .u.insns = {
561 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
562 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
563 BPF_STMT(BPF_RET | BPF_K, 0),
564 BPF_STMT(BPF_RET | BPF_K, 1),
565 },
566 CLASSIC,
567 { },
568 { { 1, 1 } },
569 },
570 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700571 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700572 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700573 BPF_STMT(BPF_LDX | BPF_LEN, 0),
574 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
575 BPF_STMT(BPF_RET | BPF_K, 1)
576 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200577 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700578 { },
579 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
580 },
581 {
582 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700583 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700584 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
585 BPF_STMT(BPF_RET | BPF_K, 1)
586 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200587 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700588 { },
589 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
590 },
591 {
592 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700593 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700594 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
595 BPF_STMT(BPF_MISC | BPF_TAX, 0),
596 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
597 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,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700601 { 1, 2, 3 },
602 { { 1, 0 }, { 2, 3 } },
603 },
604 {
605 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700606 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700607 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
608 BPF_STMT(BPF_LDX | BPF_LEN, 0),
609 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
610 BPF_STMT(BPF_MISC | BPF_TAX, 0),
611 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
612 BPF_STMT(BPF_RET | BPF_A, 0)
613 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200614 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700615 { 1, 2, 3, 0xff },
616 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
617 },
618 {
619 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700620 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700621 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
622 BPF_STMT(BPF_MISC | BPF_TAX, 0),
623 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
624 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
625 BPF_STMT(BPF_RET | BPF_A, 0)
626 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200627 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700628 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
629 { { 15, 0 }, { 16, 3 } },
630 },
631 {
632 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700633 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700634 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
635 BPF_STMT(BPF_LDX | BPF_LEN, 0),
636 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
637 BPF_STMT(BPF_MISC | BPF_TAX, 0),
638 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
639 BPF_STMT(BPF_RET | BPF_A, 0)
640 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200641 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700642 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
643 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
644 },
645 {
646 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700647 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700648 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
649 SKF_AD_OFF + SKF_AD_PKTTYPE),
650 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
651 BPF_STMT(BPF_RET | BPF_K, 1),
652 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
653 SKF_AD_OFF + SKF_AD_PKTTYPE),
654 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
655 BPF_STMT(BPF_RET | BPF_K, 1),
656 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
657 SKF_AD_OFF + SKF_AD_PKTTYPE),
658 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
659 BPF_STMT(BPF_RET | BPF_K, 1),
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 { },
664 { { 1, 3 }, { 10, 3 } },
665 },
666 {
667 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700668 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700669 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
670 SKF_AD_OFF + SKF_AD_MARK),
671 BPF_STMT(BPF_RET | BPF_A, 0)
672 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200673 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700674 { },
675 { { 1, SKB_MARK}, { 10, SKB_MARK} },
676 },
677 {
678 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700679 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700680 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
681 SKF_AD_OFF + SKF_AD_RXHASH),
682 BPF_STMT(BPF_RET | BPF_A, 0)
683 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200684 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700685 { },
686 { { 1, SKB_HASH}, { 10, SKB_HASH} },
687 },
688 {
689 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700690 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700691 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
692 SKF_AD_OFF + SKF_AD_QUEUE),
693 BPF_STMT(BPF_RET | BPF_A, 0)
694 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200695 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700696 { },
697 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
698 },
699 {
700 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700701 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700702 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
703 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
704 BPF_STMT(BPF_RET | BPF_K, 0),
705 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
706 SKF_AD_OFF + SKF_AD_PROTOCOL),
707 BPF_STMT(BPF_MISC | BPF_TAX, 0),
708 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
709 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
710 BPF_STMT(BPF_RET | BPF_K, 0),
711 BPF_STMT(BPF_MISC | BPF_TXA, 0),
712 BPF_STMT(BPF_RET | BPF_A, 0)
713 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200714 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700715 { 10, 20, 30 },
716 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
717 },
718 {
719 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700720 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700721 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
722 SKF_AD_OFF + SKF_AD_VLAN_TAG),
723 BPF_STMT(BPF_RET | BPF_A, 0)
724 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200725 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700726 { },
727 {
728 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
729 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
730 },
731 },
732 {
733 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700734 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700735 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
736 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
737 BPF_STMT(BPF_RET | BPF_A, 0)
738 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200739 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700740 { },
741 {
742 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
743 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
744 },
745 },
746 {
747 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700748 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700749 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
750 SKF_AD_OFF + SKF_AD_IFINDEX),
751 BPF_STMT(BPF_RET | BPF_A, 0)
752 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200753 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700754 { },
755 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
756 },
757 {
758 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700759 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700760 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
761 SKF_AD_OFF + SKF_AD_HATYPE),
762 BPF_STMT(BPF_RET | BPF_A, 0)
763 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200764 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700765 { },
766 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
767 },
768 {
769 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700770 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700771 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
772 SKF_AD_OFF + SKF_AD_CPU),
773 BPF_STMT(BPF_MISC | BPF_TAX, 0),
774 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
775 SKF_AD_OFF + SKF_AD_CPU),
776 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
777 BPF_STMT(BPF_RET | BPF_A, 0)
778 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200779 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700780 { },
781 { { 1, 0 }, { 10, 0 } },
782 },
783 {
784 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700785 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700786 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700787 BPF_STMT(BPF_MISC | BPF_TXA, 0),
788 BPF_STMT(BPF_LDX | BPF_IMM, 3),
789 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
790 SKF_AD_OFF + SKF_AD_NLATTR),
791 BPF_STMT(BPF_RET | BPF_A, 0)
792 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200793 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700794#ifdef __BIG_ENDIAN
795 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
796#else
797 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
798#endif
799 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700800 },
801 {
802 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700803 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700804 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700805 BPF_STMT(BPF_LDX | BPF_IMM, 3),
806 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
807 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700808 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700809 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
810 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700811 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700812 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
813 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700814 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700815 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
816 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700817 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700818 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
819 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700820 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700821 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
822 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700823 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700824 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
825 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700826 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700827 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
828 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
829 BPF_STMT(BPF_RET | BPF_A, 0)
830 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200831 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700832#ifdef __BIG_ENDIAN
833 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
834#else
835 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
836#endif
837 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700838 },
839 {
840 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700841 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700842 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
843 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
844 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
845 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
846 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
847 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
848 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
849 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
850 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
851 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
852 BPF_STMT(BPF_RET | BPF_A, 0)
853 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200854 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700855 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
856 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
857 * id 9737, seq 1, length 64
858 */
859 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
860 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
861 0x08, 0x00,
862 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
863 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
864 { { 30, 0 }, { 100, 42 } },
865 },
866 {
867 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700868 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700869 BPF_STMT(BPF_LD | BPF_IMM, 10),
870 BPF_STMT(BPF_LDX | BPF_IMM, 300),
871 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
872 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
873 BPF_STMT(BPF_RET | BPF_A, 0)
874 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200875 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700876 { },
877 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
878 },
879 {
880 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700881 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700882 BPF_STMT(BPF_LDX | BPF_LEN, 0),
883 BPF_STMT(BPF_LD | BPF_IMM, 2),
884 BPF_STMT(BPF_ALU | BPF_RSH, 1),
885 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
886 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
887 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
888 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
889 BPF_STMT(BPF_STX, 15), /* M3 = len */
890 BPF_STMT(BPF_LDX | BPF_MEM, 1),
891 BPF_STMT(BPF_LD | BPF_MEM, 2),
892 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
893 BPF_STMT(BPF_LDX | BPF_MEM, 15),
894 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
895 BPF_STMT(BPF_RET | BPF_A, 0)
896 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200897 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700898 { },
899 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
900 },
901 {
902 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700903 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700904 BPF_STMT(BPF_LDX | BPF_LEN, 0),
905 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
906 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
907 BPF_STMT(BPF_RET | BPF_K, 1),
908 BPF_STMT(BPF_RET | BPF_K, MAX_K)
909 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200910 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700911 { 3, 3, 3, 3, 3 },
912 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
913 },
914 {
915 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700916 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700917 BPF_STMT(BPF_LDX | BPF_LEN, 0),
918 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
919 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
920 BPF_STMT(BPF_RET | BPF_K, 1),
921 BPF_STMT(BPF_RET | BPF_K, MAX_K)
922 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200923 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700924 { 4, 4, 4, 3, 3 },
925 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
926 },
927 {
Daniel Borkmann92b31a92017-08-10 01:39:55 +0200928 "JGE (jt 0), test 1",
929 .u.insns = {
930 BPF_STMT(BPF_LDX | BPF_LEN, 0),
931 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
932 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
933 BPF_STMT(BPF_RET | BPF_K, 1),
934 BPF_STMT(BPF_RET | BPF_K, MAX_K)
935 },
936 CLASSIC,
937 { 4, 4, 4, 3, 3 },
938 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
939 },
940 {
941 "JGE (jt 0), test 2",
942 .u.insns = {
943 BPF_STMT(BPF_LDX | BPF_LEN, 0),
944 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
945 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
946 BPF_STMT(BPF_RET | BPF_K, 1),
947 BPF_STMT(BPF_RET | BPF_K, MAX_K)
948 },
949 CLASSIC,
950 { 4, 4, 5, 3, 3 },
951 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
952 },
953 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700954 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700955 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700956 BPF_STMT(BPF_LDX | BPF_LEN, 0),
957 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
958 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
959 BPF_STMT(BPF_RET | BPF_K, 10),
960 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
961 BPF_STMT(BPF_RET | BPF_K, 20),
962 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
963 BPF_STMT(BPF_RET | BPF_K, 30),
964 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
965 BPF_STMT(BPF_RET | BPF_K, 40),
966 BPF_STMT(BPF_RET | BPF_K, MAX_K)
967 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200968 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700969 { 1, 2, 3, 4, 5 },
970 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
971 },
972 {
973 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -0700974 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700975 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
976 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
977 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
978 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
979 BPF_STMT(BPF_LDX | BPF_LEN, 0),
980 BPF_STMT(BPF_MISC | BPF_TXA, 0),
981 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
982 BPF_STMT(BPF_MISC | BPF_TAX, 0),
983 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
984 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
985 BPF_STMT(BPF_RET | BPF_K, 10),
986 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
987 BPF_STMT(BPF_RET | BPF_K, 20),
988 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
989 BPF_STMT(BPF_RET | BPF_K, 30),
990 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
991 BPF_STMT(BPF_RET | BPF_K, 30),
992 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
993 BPF_STMT(BPF_RET | BPF_K, 30),
994 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
995 BPF_STMT(BPF_RET | BPF_K, 30),
996 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
997 BPF_STMT(BPF_RET | BPF_K, 30),
998 BPF_STMT(BPF_RET | BPF_K, MAX_K)
999 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001000 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001001 { 0, 0xAA, 0x55, 1 },
1002 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
1003 },
1004 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001005 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -07001006 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +02001007 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1008 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1009 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1010 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1011 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1012 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1013 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1014 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1015 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1016 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1017 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1018 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1019 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1020 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1021 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1022 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1023 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1024 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1025 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1026 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1027 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1028 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1029 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1030 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001031 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001032 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001033 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1034 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1035 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1036 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1037 */
1038 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1039 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1040 0x08, 0x00,
1041 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1042 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1043 0x0a, 0x01, 0x01, 0x95, /* ip src */
1044 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1045 0xc2, 0x24,
1046 0x00, 0x16 /* dst port */ },
1047 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1048 },
1049 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001050 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -07001051 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001052 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1053 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1054 * (len > 115 or len < 30000000000)' -d
1055 */
Daniel Borkmannce25b682014-05-26 20:17:35 +02001056 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1057 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1058 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1059 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1060 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1061 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1062 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1063 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1064 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1065 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1066 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1067 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1068 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1069 BPF_STMT(BPF_ST, 1),
1070 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1071 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1072 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1073 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1074 BPF_STMT(BPF_LD | BPF_MEM, 1),
1075 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1076 BPF_STMT(BPF_ST, 5),
1077 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1078 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1079 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1080 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1081 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1082 BPF_STMT(BPF_LD | BPF_MEM, 5),
1083 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1084 BPF_STMT(BPF_LD | BPF_LEN, 0),
1085 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1086 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1087 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1088 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001089 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001090 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001091 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1092 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1093 0x08, 0x00,
1094 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1095 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1096 0x0a, 0x01, 0x01, 0x95, /* ip src */
1097 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1098 0xc2, 0x24,
1099 0x00, 0x16 /* dst port */ },
1100 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1101 },
1102 {
1103 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -07001104 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001105 /* check that unitialized X and A contain zeros */
1106 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1107 BPF_STMT(BPF_RET | BPF_A, 0)
1108 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001109 CLASSIC,
1110 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001111 { {1, 0}, {2, 0} },
1112 },
1113 {
1114 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -07001115 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001116 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1117 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1118 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1119 BPF_ALU64_REG(BPF_SUB, R1, R2),
1120 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1121 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1122 BPF_ALU64_REG(BPF_MOV, R0, R1),
1123 BPF_EXIT_INSN(),
1124 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001125 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001126 { },
1127 { { 0, 0xfffffffd } }
1128 },
1129 {
1130 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001131 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001132 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1133 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1134 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1135 BPF_ALU64_REG(BPF_MUL, R1, R2),
1136 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1137 BPF_EXIT_INSN(),
1138 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1139 BPF_EXIT_INSN(),
1140 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001141 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001142 { },
1143 { { 0, 1 } }
1144 },
1145 {
1146 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -07001147 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001148 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1149 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1150 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1151 BPF_ALU64_REG(BPF_MUL, R1, R2),
1152 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1153 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1154 BPF_EXIT_INSN(),
1155 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1156 BPF_EXIT_INSN(),
1157 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001158 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001159 { },
1160 { { 0, 1 } }
1161 },
1162 {
1163 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001164 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001165 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1166 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1167 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1168 BPF_ALU32_REG(BPF_MUL, R1, R2),
1169 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1170 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1171 BPF_EXIT_INSN(),
1172 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1173 BPF_EXIT_INSN(),
1174 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001175 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001176 { },
1177 { { 0, 1 } }
1178 },
1179 {
1180 /* Have to test all register combinations, since
1181 * JITing of different registers will produce
1182 * different asm code.
1183 */
1184 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001185 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001186 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1187 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1188 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1189 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1190 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1191 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1192 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1193 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1194 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1195 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1196 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1197 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1198 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1199 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1200 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1201 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1202 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1203 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1204 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1205 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1206 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1207 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1208 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1209 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1210 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1211 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1212 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1213 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1214 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1215 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1216 BPF_ALU64_REG(BPF_ADD, R0, R0),
1217 BPF_ALU64_REG(BPF_ADD, R0, R1),
1218 BPF_ALU64_REG(BPF_ADD, R0, R2),
1219 BPF_ALU64_REG(BPF_ADD, R0, R3),
1220 BPF_ALU64_REG(BPF_ADD, R0, R4),
1221 BPF_ALU64_REG(BPF_ADD, R0, R5),
1222 BPF_ALU64_REG(BPF_ADD, R0, R6),
1223 BPF_ALU64_REG(BPF_ADD, R0, R7),
1224 BPF_ALU64_REG(BPF_ADD, R0, R8),
1225 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1226 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1227 BPF_EXIT_INSN(),
1228 BPF_ALU64_REG(BPF_ADD, R1, R0),
1229 BPF_ALU64_REG(BPF_ADD, R1, R1),
1230 BPF_ALU64_REG(BPF_ADD, R1, R2),
1231 BPF_ALU64_REG(BPF_ADD, R1, R3),
1232 BPF_ALU64_REG(BPF_ADD, R1, R4),
1233 BPF_ALU64_REG(BPF_ADD, R1, R5),
1234 BPF_ALU64_REG(BPF_ADD, R1, R6),
1235 BPF_ALU64_REG(BPF_ADD, R1, R7),
1236 BPF_ALU64_REG(BPF_ADD, R1, R8),
1237 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1238 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1239 BPF_EXIT_INSN(),
1240 BPF_ALU64_REG(BPF_ADD, R2, R0),
1241 BPF_ALU64_REG(BPF_ADD, R2, R1),
1242 BPF_ALU64_REG(BPF_ADD, R2, R2),
1243 BPF_ALU64_REG(BPF_ADD, R2, R3),
1244 BPF_ALU64_REG(BPF_ADD, R2, R4),
1245 BPF_ALU64_REG(BPF_ADD, R2, R5),
1246 BPF_ALU64_REG(BPF_ADD, R2, R6),
1247 BPF_ALU64_REG(BPF_ADD, R2, R7),
1248 BPF_ALU64_REG(BPF_ADD, R2, R8),
1249 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1250 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1251 BPF_EXIT_INSN(),
1252 BPF_ALU64_REG(BPF_ADD, R3, R0),
1253 BPF_ALU64_REG(BPF_ADD, R3, R1),
1254 BPF_ALU64_REG(BPF_ADD, R3, R2),
1255 BPF_ALU64_REG(BPF_ADD, R3, R3),
1256 BPF_ALU64_REG(BPF_ADD, R3, R4),
1257 BPF_ALU64_REG(BPF_ADD, R3, R5),
1258 BPF_ALU64_REG(BPF_ADD, R3, R6),
1259 BPF_ALU64_REG(BPF_ADD, R3, R7),
1260 BPF_ALU64_REG(BPF_ADD, R3, R8),
1261 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1262 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1263 BPF_EXIT_INSN(),
1264 BPF_ALU64_REG(BPF_ADD, R4, R0),
1265 BPF_ALU64_REG(BPF_ADD, R4, R1),
1266 BPF_ALU64_REG(BPF_ADD, R4, R2),
1267 BPF_ALU64_REG(BPF_ADD, R4, R3),
1268 BPF_ALU64_REG(BPF_ADD, R4, R4),
1269 BPF_ALU64_REG(BPF_ADD, R4, R5),
1270 BPF_ALU64_REG(BPF_ADD, R4, R6),
1271 BPF_ALU64_REG(BPF_ADD, R4, R7),
1272 BPF_ALU64_REG(BPF_ADD, R4, R8),
1273 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1274 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1275 BPF_EXIT_INSN(),
1276 BPF_ALU64_REG(BPF_ADD, R5, R0),
1277 BPF_ALU64_REG(BPF_ADD, R5, R1),
1278 BPF_ALU64_REG(BPF_ADD, R5, R2),
1279 BPF_ALU64_REG(BPF_ADD, R5, R3),
1280 BPF_ALU64_REG(BPF_ADD, R5, R4),
1281 BPF_ALU64_REG(BPF_ADD, R5, R5),
1282 BPF_ALU64_REG(BPF_ADD, R5, R6),
1283 BPF_ALU64_REG(BPF_ADD, R5, R7),
1284 BPF_ALU64_REG(BPF_ADD, R5, R8),
1285 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1286 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1287 BPF_EXIT_INSN(),
1288 BPF_ALU64_REG(BPF_ADD, R6, R0),
1289 BPF_ALU64_REG(BPF_ADD, R6, R1),
1290 BPF_ALU64_REG(BPF_ADD, R6, R2),
1291 BPF_ALU64_REG(BPF_ADD, R6, R3),
1292 BPF_ALU64_REG(BPF_ADD, R6, R4),
1293 BPF_ALU64_REG(BPF_ADD, R6, R5),
1294 BPF_ALU64_REG(BPF_ADD, R6, R6),
1295 BPF_ALU64_REG(BPF_ADD, R6, R7),
1296 BPF_ALU64_REG(BPF_ADD, R6, R8),
1297 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1298 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1299 BPF_EXIT_INSN(),
1300 BPF_ALU64_REG(BPF_ADD, R7, R0),
1301 BPF_ALU64_REG(BPF_ADD, R7, R1),
1302 BPF_ALU64_REG(BPF_ADD, R7, R2),
1303 BPF_ALU64_REG(BPF_ADD, R7, R3),
1304 BPF_ALU64_REG(BPF_ADD, R7, R4),
1305 BPF_ALU64_REG(BPF_ADD, R7, R5),
1306 BPF_ALU64_REG(BPF_ADD, R7, R6),
1307 BPF_ALU64_REG(BPF_ADD, R7, R7),
1308 BPF_ALU64_REG(BPF_ADD, R7, R8),
1309 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1310 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1311 BPF_EXIT_INSN(),
1312 BPF_ALU64_REG(BPF_ADD, R8, R0),
1313 BPF_ALU64_REG(BPF_ADD, R8, R1),
1314 BPF_ALU64_REG(BPF_ADD, R8, R2),
1315 BPF_ALU64_REG(BPF_ADD, R8, R3),
1316 BPF_ALU64_REG(BPF_ADD, R8, R4),
1317 BPF_ALU64_REG(BPF_ADD, R8, R5),
1318 BPF_ALU64_REG(BPF_ADD, R8, R6),
1319 BPF_ALU64_REG(BPF_ADD, R8, R7),
1320 BPF_ALU64_REG(BPF_ADD, R8, R8),
1321 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1322 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1323 BPF_EXIT_INSN(),
1324 BPF_ALU64_REG(BPF_ADD, R9, R0),
1325 BPF_ALU64_REG(BPF_ADD, R9, R1),
1326 BPF_ALU64_REG(BPF_ADD, R9, R2),
1327 BPF_ALU64_REG(BPF_ADD, R9, R3),
1328 BPF_ALU64_REG(BPF_ADD, R9, R4),
1329 BPF_ALU64_REG(BPF_ADD, R9, R5),
1330 BPF_ALU64_REG(BPF_ADD, R9, R6),
1331 BPF_ALU64_REG(BPF_ADD, R9, R7),
1332 BPF_ALU64_REG(BPF_ADD, R9, R8),
1333 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1334 BPF_ALU64_REG(BPF_MOV, R0, R9),
1335 BPF_EXIT_INSN(),
1336 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001337 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001338 { },
1339 { { 0, 2957380 } }
1340 },
1341 {
1342 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001343 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001344 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1345 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1346 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1347 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1348 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1349 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1350 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1351 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1352 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1353 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1354 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1355 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1356 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1357 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1358 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1359 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1360 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1361 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1362 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1363 BPF_ALU32_REG(BPF_ADD, R0, R1),
1364 BPF_ALU32_REG(BPF_ADD, R0, R2),
1365 BPF_ALU32_REG(BPF_ADD, R0, R3),
1366 BPF_ALU32_REG(BPF_ADD, R0, R4),
1367 BPF_ALU32_REG(BPF_ADD, R0, R5),
1368 BPF_ALU32_REG(BPF_ADD, R0, R6),
1369 BPF_ALU32_REG(BPF_ADD, R0, R7),
1370 BPF_ALU32_REG(BPF_ADD, R0, R8),
1371 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1372 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1373 BPF_EXIT_INSN(),
1374 BPF_ALU32_REG(BPF_ADD, R1, R0),
1375 BPF_ALU32_REG(BPF_ADD, R1, R1),
1376 BPF_ALU32_REG(BPF_ADD, R1, R2),
1377 BPF_ALU32_REG(BPF_ADD, R1, R3),
1378 BPF_ALU32_REG(BPF_ADD, R1, R4),
1379 BPF_ALU32_REG(BPF_ADD, R1, R5),
1380 BPF_ALU32_REG(BPF_ADD, R1, R6),
1381 BPF_ALU32_REG(BPF_ADD, R1, R7),
1382 BPF_ALU32_REG(BPF_ADD, R1, R8),
1383 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1384 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1385 BPF_EXIT_INSN(),
1386 BPF_ALU32_REG(BPF_ADD, R2, R0),
1387 BPF_ALU32_REG(BPF_ADD, R2, R1),
1388 BPF_ALU32_REG(BPF_ADD, R2, R2),
1389 BPF_ALU32_REG(BPF_ADD, R2, R3),
1390 BPF_ALU32_REG(BPF_ADD, R2, R4),
1391 BPF_ALU32_REG(BPF_ADD, R2, R5),
1392 BPF_ALU32_REG(BPF_ADD, R2, R6),
1393 BPF_ALU32_REG(BPF_ADD, R2, R7),
1394 BPF_ALU32_REG(BPF_ADD, R2, R8),
1395 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1396 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1397 BPF_EXIT_INSN(),
1398 BPF_ALU32_REG(BPF_ADD, R3, R0),
1399 BPF_ALU32_REG(BPF_ADD, R3, R1),
1400 BPF_ALU32_REG(BPF_ADD, R3, R2),
1401 BPF_ALU32_REG(BPF_ADD, R3, R3),
1402 BPF_ALU32_REG(BPF_ADD, R3, R4),
1403 BPF_ALU32_REG(BPF_ADD, R3, R5),
1404 BPF_ALU32_REG(BPF_ADD, R3, R6),
1405 BPF_ALU32_REG(BPF_ADD, R3, R7),
1406 BPF_ALU32_REG(BPF_ADD, R3, R8),
1407 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1408 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1409 BPF_EXIT_INSN(),
1410 BPF_ALU32_REG(BPF_ADD, R4, R0),
1411 BPF_ALU32_REG(BPF_ADD, R4, R1),
1412 BPF_ALU32_REG(BPF_ADD, R4, R2),
1413 BPF_ALU32_REG(BPF_ADD, R4, R3),
1414 BPF_ALU32_REG(BPF_ADD, R4, R4),
1415 BPF_ALU32_REG(BPF_ADD, R4, R5),
1416 BPF_ALU32_REG(BPF_ADD, R4, R6),
1417 BPF_ALU32_REG(BPF_ADD, R4, R7),
1418 BPF_ALU32_REG(BPF_ADD, R4, R8),
1419 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1420 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1421 BPF_EXIT_INSN(),
1422 BPF_ALU32_REG(BPF_ADD, R5, R0),
1423 BPF_ALU32_REG(BPF_ADD, R5, R1),
1424 BPF_ALU32_REG(BPF_ADD, R5, R2),
1425 BPF_ALU32_REG(BPF_ADD, R5, R3),
1426 BPF_ALU32_REG(BPF_ADD, R5, R4),
1427 BPF_ALU32_REG(BPF_ADD, R5, R5),
1428 BPF_ALU32_REG(BPF_ADD, R5, R6),
1429 BPF_ALU32_REG(BPF_ADD, R5, R7),
1430 BPF_ALU32_REG(BPF_ADD, R5, R8),
1431 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1432 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1433 BPF_EXIT_INSN(),
1434 BPF_ALU32_REG(BPF_ADD, R6, R0),
1435 BPF_ALU32_REG(BPF_ADD, R6, R1),
1436 BPF_ALU32_REG(BPF_ADD, R6, R2),
1437 BPF_ALU32_REG(BPF_ADD, R6, R3),
1438 BPF_ALU32_REG(BPF_ADD, R6, R4),
1439 BPF_ALU32_REG(BPF_ADD, R6, R5),
1440 BPF_ALU32_REG(BPF_ADD, R6, R6),
1441 BPF_ALU32_REG(BPF_ADD, R6, R7),
1442 BPF_ALU32_REG(BPF_ADD, R6, R8),
1443 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1444 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1445 BPF_EXIT_INSN(),
1446 BPF_ALU32_REG(BPF_ADD, R7, R0),
1447 BPF_ALU32_REG(BPF_ADD, R7, R1),
1448 BPF_ALU32_REG(BPF_ADD, R7, R2),
1449 BPF_ALU32_REG(BPF_ADD, R7, R3),
1450 BPF_ALU32_REG(BPF_ADD, R7, R4),
1451 BPF_ALU32_REG(BPF_ADD, R7, R5),
1452 BPF_ALU32_REG(BPF_ADD, R7, R6),
1453 BPF_ALU32_REG(BPF_ADD, R7, R7),
1454 BPF_ALU32_REG(BPF_ADD, R7, R8),
1455 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1456 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1457 BPF_EXIT_INSN(),
1458 BPF_ALU32_REG(BPF_ADD, R8, R0),
1459 BPF_ALU32_REG(BPF_ADD, R8, R1),
1460 BPF_ALU32_REG(BPF_ADD, R8, R2),
1461 BPF_ALU32_REG(BPF_ADD, R8, R3),
1462 BPF_ALU32_REG(BPF_ADD, R8, R4),
1463 BPF_ALU32_REG(BPF_ADD, R8, R5),
1464 BPF_ALU32_REG(BPF_ADD, R8, R6),
1465 BPF_ALU32_REG(BPF_ADD, R8, R7),
1466 BPF_ALU32_REG(BPF_ADD, R8, R8),
1467 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1468 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1469 BPF_EXIT_INSN(),
1470 BPF_ALU32_REG(BPF_ADD, R9, R0),
1471 BPF_ALU32_REG(BPF_ADD, R9, R1),
1472 BPF_ALU32_REG(BPF_ADD, R9, R2),
1473 BPF_ALU32_REG(BPF_ADD, R9, R3),
1474 BPF_ALU32_REG(BPF_ADD, R9, R4),
1475 BPF_ALU32_REG(BPF_ADD, R9, R5),
1476 BPF_ALU32_REG(BPF_ADD, R9, R6),
1477 BPF_ALU32_REG(BPF_ADD, R9, R7),
1478 BPF_ALU32_REG(BPF_ADD, R9, R8),
1479 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1480 BPF_ALU32_REG(BPF_MOV, R0, R9),
1481 BPF_EXIT_INSN(),
1482 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001483 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001484 { },
1485 { { 0, 2957380 } }
1486 },
1487 { /* Mainly checking JIT here. */
1488 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001489 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001490 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1491 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1492 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1493 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1494 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1495 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1496 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1497 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1498 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1499 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1500 BPF_ALU64_REG(BPF_SUB, R0, R0),
1501 BPF_ALU64_REG(BPF_SUB, R0, R1),
1502 BPF_ALU64_REG(BPF_SUB, R0, R2),
1503 BPF_ALU64_REG(BPF_SUB, R0, R3),
1504 BPF_ALU64_REG(BPF_SUB, R0, R4),
1505 BPF_ALU64_REG(BPF_SUB, R0, R5),
1506 BPF_ALU64_REG(BPF_SUB, R0, R6),
1507 BPF_ALU64_REG(BPF_SUB, R0, R7),
1508 BPF_ALU64_REG(BPF_SUB, R0, R8),
1509 BPF_ALU64_REG(BPF_SUB, R0, R9),
1510 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1511 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1512 BPF_EXIT_INSN(),
1513 BPF_ALU64_REG(BPF_SUB, R1, R0),
1514 BPF_ALU64_REG(BPF_SUB, R1, R2),
1515 BPF_ALU64_REG(BPF_SUB, R1, R3),
1516 BPF_ALU64_REG(BPF_SUB, R1, R4),
1517 BPF_ALU64_REG(BPF_SUB, R1, R5),
1518 BPF_ALU64_REG(BPF_SUB, R1, R6),
1519 BPF_ALU64_REG(BPF_SUB, R1, R7),
1520 BPF_ALU64_REG(BPF_SUB, R1, R8),
1521 BPF_ALU64_REG(BPF_SUB, R1, R9),
1522 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1523 BPF_ALU64_REG(BPF_SUB, R2, R0),
1524 BPF_ALU64_REG(BPF_SUB, R2, R1),
1525 BPF_ALU64_REG(BPF_SUB, R2, R3),
1526 BPF_ALU64_REG(BPF_SUB, R2, R4),
1527 BPF_ALU64_REG(BPF_SUB, R2, R5),
1528 BPF_ALU64_REG(BPF_SUB, R2, R6),
1529 BPF_ALU64_REG(BPF_SUB, R2, R7),
1530 BPF_ALU64_REG(BPF_SUB, R2, R8),
1531 BPF_ALU64_REG(BPF_SUB, R2, R9),
1532 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1533 BPF_ALU64_REG(BPF_SUB, R3, R0),
1534 BPF_ALU64_REG(BPF_SUB, R3, R1),
1535 BPF_ALU64_REG(BPF_SUB, R3, R2),
1536 BPF_ALU64_REG(BPF_SUB, R3, R4),
1537 BPF_ALU64_REG(BPF_SUB, R3, R5),
1538 BPF_ALU64_REG(BPF_SUB, R3, R6),
1539 BPF_ALU64_REG(BPF_SUB, R3, R7),
1540 BPF_ALU64_REG(BPF_SUB, R3, R8),
1541 BPF_ALU64_REG(BPF_SUB, R3, R9),
1542 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1543 BPF_ALU64_REG(BPF_SUB, R4, R0),
1544 BPF_ALU64_REG(BPF_SUB, R4, R1),
1545 BPF_ALU64_REG(BPF_SUB, R4, R2),
1546 BPF_ALU64_REG(BPF_SUB, R4, R3),
1547 BPF_ALU64_REG(BPF_SUB, R4, R5),
1548 BPF_ALU64_REG(BPF_SUB, R4, R6),
1549 BPF_ALU64_REG(BPF_SUB, R4, R7),
1550 BPF_ALU64_REG(BPF_SUB, R4, R8),
1551 BPF_ALU64_REG(BPF_SUB, R4, R9),
1552 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1553 BPF_ALU64_REG(BPF_SUB, R5, R0),
1554 BPF_ALU64_REG(BPF_SUB, R5, R1),
1555 BPF_ALU64_REG(BPF_SUB, R5, R2),
1556 BPF_ALU64_REG(BPF_SUB, R5, R3),
1557 BPF_ALU64_REG(BPF_SUB, R5, R4),
1558 BPF_ALU64_REG(BPF_SUB, R5, R6),
1559 BPF_ALU64_REG(BPF_SUB, R5, R7),
1560 BPF_ALU64_REG(BPF_SUB, R5, R8),
1561 BPF_ALU64_REG(BPF_SUB, R5, R9),
1562 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1563 BPF_ALU64_REG(BPF_SUB, R6, R0),
1564 BPF_ALU64_REG(BPF_SUB, R6, R1),
1565 BPF_ALU64_REG(BPF_SUB, R6, R2),
1566 BPF_ALU64_REG(BPF_SUB, R6, R3),
1567 BPF_ALU64_REG(BPF_SUB, R6, R4),
1568 BPF_ALU64_REG(BPF_SUB, R6, R5),
1569 BPF_ALU64_REG(BPF_SUB, R6, R7),
1570 BPF_ALU64_REG(BPF_SUB, R6, R8),
1571 BPF_ALU64_REG(BPF_SUB, R6, R9),
1572 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1573 BPF_ALU64_REG(BPF_SUB, R7, R0),
1574 BPF_ALU64_REG(BPF_SUB, R7, R1),
1575 BPF_ALU64_REG(BPF_SUB, R7, R2),
1576 BPF_ALU64_REG(BPF_SUB, R7, R3),
1577 BPF_ALU64_REG(BPF_SUB, R7, R4),
1578 BPF_ALU64_REG(BPF_SUB, R7, R5),
1579 BPF_ALU64_REG(BPF_SUB, R7, R6),
1580 BPF_ALU64_REG(BPF_SUB, R7, R8),
1581 BPF_ALU64_REG(BPF_SUB, R7, R9),
1582 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1583 BPF_ALU64_REG(BPF_SUB, R8, R0),
1584 BPF_ALU64_REG(BPF_SUB, R8, R1),
1585 BPF_ALU64_REG(BPF_SUB, R8, R2),
1586 BPF_ALU64_REG(BPF_SUB, R8, R3),
1587 BPF_ALU64_REG(BPF_SUB, R8, R4),
1588 BPF_ALU64_REG(BPF_SUB, R8, R5),
1589 BPF_ALU64_REG(BPF_SUB, R8, R6),
1590 BPF_ALU64_REG(BPF_SUB, R8, R7),
1591 BPF_ALU64_REG(BPF_SUB, R8, R9),
1592 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1593 BPF_ALU64_REG(BPF_SUB, R9, R0),
1594 BPF_ALU64_REG(BPF_SUB, R9, R1),
1595 BPF_ALU64_REG(BPF_SUB, R9, R2),
1596 BPF_ALU64_REG(BPF_SUB, R9, R3),
1597 BPF_ALU64_REG(BPF_SUB, R9, R4),
1598 BPF_ALU64_REG(BPF_SUB, R9, R5),
1599 BPF_ALU64_REG(BPF_SUB, R9, R6),
1600 BPF_ALU64_REG(BPF_SUB, R9, R7),
1601 BPF_ALU64_REG(BPF_SUB, R9, R8),
1602 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1603 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1604 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1605 BPF_ALU64_REG(BPF_SUB, R0, R1),
1606 BPF_ALU64_REG(BPF_SUB, R0, R2),
1607 BPF_ALU64_REG(BPF_SUB, R0, R3),
1608 BPF_ALU64_REG(BPF_SUB, R0, R4),
1609 BPF_ALU64_REG(BPF_SUB, R0, R5),
1610 BPF_ALU64_REG(BPF_SUB, R0, R6),
1611 BPF_ALU64_REG(BPF_SUB, R0, R7),
1612 BPF_ALU64_REG(BPF_SUB, R0, R8),
1613 BPF_ALU64_REG(BPF_SUB, R0, R9),
1614 BPF_EXIT_INSN(),
1615 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001616 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001617 { },
1618 { { 0, 11 } }
1619 },
1620 { /* Mainly checking JIT here. */
1621 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001622 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001623 BPF_ALU64_REG(BPF_SUB, R0, R0),
1624 BPF_ALU64_REG(BPF_XOR, R1, R1),
1625 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1626 BPF_EXIT_INSN(),
1627 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1628 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1629 BPF_ALU64_REG(BPF_SUB, R1, R1),
1630 BPF_ALU64_REG(BPF_XOR, R2, R2),
1631 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1632 BPF_EXIT_INSN(),
1633 BPF_ALU64_REG(BPF_SUB, R2, R2),
1634 BPF_ALU64_REG(BPF_XOR, R3, R3),
1635 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1636 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1637 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1638 BPF_EXIT_INSN(),
1639 BPF_ALU64_REG(BPF_SUB, R3, R3),
1640 BPF_ALU64_REG(BPF_XOR, R4, R4),
1641 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1642 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1643 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1644 BPF_EXIT_INSN(),
1645 BPF_ALU64_REG(BPF_SUB, R4, R4),
1646 BPF_ALU64_REG(BPF_XOR, R5, R5),
1647 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1648 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1649 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1650 BPF_EXIT_INSN(),
1651 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1652 BPF_ALU64_REG(BPF_SUB, R5, R5),
1653 BPF_ALU64_REG(BPF_XOR, R6, R6),
1654 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1655 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1656 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1657 BPF_EXIT_INSN(),
1658 BPF_ALU64_REG(BPF_SUB, R6, R6),
1659 BPF_ALU64_REG(BPF_XOR, R7, R7),
1660 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1661 BPF_EXIT_INSN(),
1662 BPF_ALU64_REG(BPF_SUB, R7, R7),
1663 BPF_ALU64_REG(BPF_XOR, R8, R8),
1664 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1665 BPF_EXIT_INSN(),
1666 BPF_ALU64_REG(BPF_SUB, R8, R8),
1667 BPF_ALU64_REG(BPF_XOR, R9, R9),
1668 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1669 BPF_EXIT_INSN(),
1670 BPF_ALU64_REG(BPF_SUB, R9, R9),
1671 BPF_ALU64_REG(BPF_XOR, R0, R0),
1672 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1673 BPF_EXIT_INSN(),
1674 BPF_ALU64_REG(BPF_SUB, R1, R1),
1675 BPF_ALU64_REG(BPF_XOR, R0, R0),
1676 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1677 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1678 BPF_EXIT_INSN(),
1679 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1680 BPF_EXIT_INSN(),
1681 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001682 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001683 { },
1684 { { 0, 1 } }
1685 },
1686 { /* Mainly checking JIT here. */
1687 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001688 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001689 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1690 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1691 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1692 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1693 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1694 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1695 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1696 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1697 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1698 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1699 BPF_ALU64_REG(BPF_MUL, R0, R0),
1700 BPF_ALU64_REG(BPF_MUL, R0, R1),
1701 BPF_ALU64_REG(BPF_MUL, R0, R2),
1702 BPF_ALU64_REG(BPF_MUL, R0, R3),
1703 BPF_ALU64_REG(BPF_MUL, R0, R4),
1704 BPF_ALU64_REG(BPF_MUL, R0, R5),
1705 BPF_ALU64_REG(BPF_MUL, R0, R6),
1706 BPF_ALU64_REG(BPF_MUL, R0, R7),
1707 BPF_ALU64_REG(BPF_MUL, R0, R8),
1708 BPF_ALU64_REG(BPF_MUL, R0, R9),
1709 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1710 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1711 BPF_EXIT_INSN(),
1712 BPF_ALU64_REG(BPF_MUL, R1, R0),
1713 BPF_ALU64_REG(BPF_MUL, R1, R2),
1714 BPF_ALU64_REG(BPF_MUL, R1, R3),
1715 BPF_ALU64_REG(BPF_MUL, R1, R4),
1716 BPF_ALU64_REG(BPF_MUL, R1, R5),
1717 BPF_ALU64_REG(BPF_MUL, R1, R6),
1718 BPF_ALU64_REG(BPF_MUL, R1, R7),
1719 BPF_ALU64_REG(BPF_MUL, R1, R8),
1720 BPF_ALU64_REG(BPF_MUL, R1, R9),
1721 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1722 BPF_ALU64_REG(BPF_MOV, R2, R1),
1723 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1724 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1725 BPF_EXIT_INSN(),
1726 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1727 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1728 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1729 BPF_EXIT_INSN(),
1730 BPF_ALU64_REG(BPF_MUL, R2, R0),
1731 BPF_ALU64_REG(BPF_MUL, R2, R1),
1732 BPF_ALU64_REG(BPF_MUL, R2, R3),
1733 BPF_ALU64_REG(BPF_MUL, R2, R4),
1734 BPF_ALU64_REG(BPF_MUL, R2, R5),
1735 BPF_ALU64_REG(BPF_MUL, R2, R6),
1736 BPF_ALU64_REG(BPF_MUL, R2, R7),
1737 BPF_ALU64_REG(BPF_MUL, R2, R8),
1738 BPF_ALU64_REG(BPF_MUL, R2, R9),
1739 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1740 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1741 BPF_ALU64_REG(BPF_MOV, R0, R2),
1742 BPF_EXIT_INSN(),
1743 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001744 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001745 { },
1746 { { 0, 0x35d97ef2 } }
1747 },
Daniel Borkmann9dd2af82015-12-17 23:51:57 +01001748 { /* Mainly checking JIT here. */
1749 "MOV REG64",
1750 .u.insns_int = {
1751 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1752 BPF_MOV64_REG(R1, R0),
1753 BPF_MOV64_REG(R2, R1),
1754 BPF_MOV64_REG(R3, R2),
1755 BPF_MOV64_REG(R4, R3),
1756 BPF_MOV64_REG(R5, R4),
1757 BPF_MOV64_REG(R6, R5),
1758 BPF_MOV64_REG(R7, R6),
1759 BPF_MOV64_REG(R8, R7),
1760 BPF_MOV64_REG(R9, R8),
1761 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1762 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1763 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1764 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1765 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1766 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1767 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1768 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1769 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1770 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1771 BPF_ALU64_REG(BPF_ADD, R0, R0),
1772 BPF_ALU64_REG(BPF_ADD, R0, R1),
1773 BPF_ALU64_REG(BPF_ADD, R0, R2),
1774 BPF_ALU64_REG(BPF_ADD, R0, R3),
1775 BPF_ALU64_REG(BPF_ADD, R0, R4),
1776 BPF_ALU64_REG(BPF_ADD, R0, R5),
1777 BPF_ALU64_REG(BPF_ADD, R0, R6),
1778 BPF_ALU64_REG(BPF_ADD, R0, R7),
1779 BPF_ALU64_REG(BPF_ADD, R0, R8),
1780 BPF_ALU64_REG(BPF_ADD, R0, R9),
1781 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1782 BPF_EXIT_INSN(),
1783 },
1784 INTERNAL,
1785 { },
1786 { { 0, 0xfefe } }
1787 },
1788 { /* Mainly checking JIT here. */
1789 "MOV REG32",
1790 .u.insns_int = {
1791 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1792 BPF_MOV64_REG(R1, R0),
1793 BPF_MOV64_REG(R2, R1),
1794 BPF_MOV64_REG(R3, R2),
1795 BPF_MOV64_REG(R4, R3),
1796 BPF_MOV64_REG(R5, R4),
1797 BPF_MOV64_REG(R6, R5),
1798 BPF_MOV64_REG(R7, R6),
1799 BPF_MOV64_REG(R8, R7),
1800 BPF_MOV64_REG(R9, R8),
1801 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1802 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1803 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1804 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1805 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1806 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1807 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1808 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1809 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1810 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1811 BPF_ALU64_REG(BPF_ADD, R0, R0),
1812 BPF_ALU64_REG(BPF_ADD, R0, R1),
1813 BPF_ALU64_REG(BPF_ADD, R0, R2),
1814 BPF_ALU64_REG(BPF_ADD, R0, R3),
1815 BPF_ALU64_REG(BPF_ADD, R0, R4),
1816 BPF_ALU64_REG(BPF_ADD, R0, R5),
1817 BPF_ALU64_REG(BPF_ADD, R0, R6),
1818 BPF_ALU64_REG(BPF_ADD, R0, R7),
1819 BPF_ALU64_REG(BPF_ADD, R0, R8),
1820 BPF_ALU64_REG(BPF_ADD, R0, R9),
1821 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1822 BPF_EXIT_INSN(),
1823 },
1824 INTERNAL,
1825 { },
1826 { { 0, 0xfefe } }
1827 },
1828 { /* Mainly checking JIT here. */
1829 "LD IMM64",
1830 .u.insns_int = {
1831 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1832 BPF_MOV64_REG(R1, R0),
1833 BPF_MOV64_REG(R2, R1),
1834 BPF_MOV64_REG(R3, R2),
1835 BPF_MOV64_REG(R4, R3),
1836 BPF_MOV64_REG(R5, R4),
1837 BPF_MOV64_REG(R6, R5),
1838 BPF_MOV64_REG(R7, R6),
1839 BPF_MOV64_REG(R8, R7),
1840 BPF_MOV64_REG(R9, R8),
1841 BPF_LD_IMM64(R0, 0x0LL),
1842 BPF_LD_IMM64(R1, 0x0LL),
1843 BPF_LD_IMM64(R2, 0x0LL),
1844 BPF_LD_IMM64(R3, 0x0LL),
1845 BPF_LD_IMM64(R4, 0x0LL),
1846 BPF_LD_IMM64(R5, 0x0LL),
1847 BPF_LD_IMM64(R6, 0x0LL),
1848 BPF_LD_IMM64(R7, 0x0LL),
1849 BPF_LD_IMM64(R8, 0x0LL),
1850 BPF_LD_IMM64(R9, 0x0LL),
1851 BPF_ALU64_REG(BPF_ADD, R0, R0),
1852 BPF_ALU64_REG(BPF_ADD, R0, R1),
1853 BPF_ALU64_REG(BPF_ADD, R0, R2),
1854 BPF_ALU64_REG(BPF_ADD, R0, R3),
1855 BPF_ALU64_REG(BPF_ADD, R0, R4),
1856 BPF_ALU64_REG(BPF_ADD, R0, R5),
1857 BPF_ALU64_REG(BPF_ADD, R0, R6),
1858 BPF_ALU64_REG(BPF_ADD, R0, R7),
1859 BPF_ALU64_REG(BPF_ADD, R0, R8),
1860 BPF_ALU64_REG(BPF_ADD, R0, R9),
1861 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1862 BPF_EXIT_INSN(),
1863 },
1864 INTERNAL,
1865 { },
1866 { { 0, 0xfefe } }
1867 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001868 {
1869 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001870 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001871 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1872 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1873 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1874 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1875 BPF_ALU64_REG(BPF_DIV, R0, R2),
1876 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1877 BPF_EXIT_INSN(),
1878 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1879 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1880 BPF_EXIT_INSN(),
1881 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1882 BPF_EXIT_INSN(),
1883 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001884 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001885 { },
1886 { { 0, -1 } }
1887 },
1888 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001889 "INT: shifts by register",
1890 .u.insns_int = {
1891 BPF_MOV64_IMM(R0, -1234),
1892 BPF_MOV64_IMM(R1, 1),
1893 BPF_ALU32_REG(BPF_RSH, R0, R1),
1894 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1895 BPF_EXIT_INSN(),
1896 BPF_MOV64_IMM(R2, 1),
1897 BPF_ALU64_REG(BPF_LSH, R0, R2),
1898 BPF_MOV32_IMM(R4, -1234),
1899 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1900 BPF_EXIT_INSN(),
1901 BPF_ALU64_IMM(BPF_AND, R4, 63),
1902 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1903 BPF_MOV64_IMM(R3, 47),
1904 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1905 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1906 BPF_EXIT_INSN(),
1907 BPF_MOV64_IMM(R2, 1),
1908 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1909 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1910 BPF_EXIT_INSN(),
1911 BPF_MOV64_IMM(R4, 4),
1912 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1913 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1914 BPF_EXIT_INSN(),
1915 BPF_MOV64_IMM(R4, 5),
1916 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1917 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1918 BPF_EXIT_INSN(),
1919 BPF_MOV64_IMM(R0, -1),
1920 BPF_EXIT_INSN(),
1921 },
1922 INTERNAL,
1923 { },
1924 { { 0, -1 } }
1925 },
1926 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001927 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07001928 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001929 BPF_STMT(BPF_LD | BPF_IMM, 1),
1930 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001931 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001932 { },
Yonghong Song09584b42018-02-02 22:37:15 -08001933 { },
1934 .fill_helper = NULL,
1935 .expected_errcode = -EINVAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001936 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001937 {
1938 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07001939 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001940 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1941 BPF_STMT(BPF_RET | BPF_K, 0)
1942 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001943 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001944 { },
Yonghong Song09584b42018-02-02 22:37:15 -08001945 { },
1946 .fill_helper = NULL,
1947 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001948 },
1949 {
1950 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07001951 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001952 /* seccomp insn, rejected in socket filter */
1953 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1954 BPF_STMT(BPF_RET | BPF_K, 0)
1955 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001956 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001957 { },
Yonghong Song09584b42018-02-02 22:37:15 -08001958 { },
1959 .fill_helper = NULL,
1960 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001961 },
1962 {
1963 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07001964 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001965 BPF_STMT(BPF_STX, 16),
1966 BPF_STMT(BPF_RET | BPF_K, 0)
1967 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001968 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001969 { },
Yonghong Song09584b42018-02-02 22:37:15 -08001970 { },
1971 .fill_helper = NULL,
1972 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001973 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001974 {
1975 "JUMPS + HOLES",
1976 .u.insns = {
1977 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1978 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1979 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1980 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1981 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1982 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1983 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1984 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1985 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1986 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1987 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1988 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1989 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1990 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1991 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1992 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1993 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1994 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1995 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1996 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1997 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1998 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1999 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2000 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2001 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2002 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2003 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2004 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2005 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2006 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2007 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2008 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2009 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2010 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2011 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2012 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2013 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2014 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2015 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2016 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2017 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2018 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2019 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2020 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2021 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2022 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2023 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2024 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2025 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2026 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2027 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2028 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2029 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2030 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2031 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2032 BPF_STMT(BPF_RET | BPF_A, 0),
2033 BPF_STMT(BPF_RET | BPF_A, 0),
2034 },
2035 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02002036 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2037 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2038 0x08, 0x00,
2039 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2040 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2041 0xc0, 0xa8, 0x33, 0x01,
2042 0xc0, 0xa8, 0x33, 0x02,
2043 0xbb, 0xb6,
2044 0xa9, 0xfa,
2045 0x00, 0x14, 0x00, 0x00,
2046 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2047 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2048 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2049 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2050 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2051 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2052 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2053 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002054 { { 88, 0x001b } }
2055 },
2056 {
2057 "check: RET X",
2058 .u.insns = {
2059 BPF_STMT(BPF_RET | BPF_X, 0),
2060 },
2061 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2062 { },
2063 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002064 .fill_helper = NULL,
2065 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002066 },
2067 {
2068 "check: LDX + RET X",
2069 .u.insns = {
2070 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2071 BPF_STMT(BPF_RET | BPF_X, 0),
2072 },
2073 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2074 { },
2075 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002076 .fill_helper = NULL,
2077 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002078 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02002079 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002080 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02002081 .u.insns = {
2082 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2083 BPF_STMT(BPF_STX, 0),
2084 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2085 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2086 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2087 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2088 BPF_STMT(BPF_STX, 1),
2089 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2090 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2091 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2092 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2093 BPF_STMT(BPF_STX, 2),
2094 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2095 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2096 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2097 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2098 BPF_STMT(BPF_STX, 3),
2099 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2100 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2101 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2102 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2103 BPF_STMT(BPF_STX, 4),
2104 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2105 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2106 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2107 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2108 BPF_STMT(BPF_STX, 5),
2109 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2110 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2111 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2112 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2113 BPF_STMT(BPF_STX, 6),
2114 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2115 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2116 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2117 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2118 BPF_STMT(BPF_STX, 7),
2119 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2120 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2121 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2122 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2123 BPF_STMT(BPF_STX, 8),
2124 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2125 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2126 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2127 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2128 BPF_STMT(BPF_STX, 9),
2129 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2130 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2131 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2132 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2133 BPF_STMT(BPF_STX, 10),
2134 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2135 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2136 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2137 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2138 BPF_STMT(BPF_STX, 11),
2139 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2140 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2141 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2142 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2143 BPF_STMT(BPF_STX, 12),
2144 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2145 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2146 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2147 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2148 BPF_STMT(BPF_STX, 13),
2149 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2150 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2151 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2152 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2153 BPF_STMT(BPF_STX, 14),
2154 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2155 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2156 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2157 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2158 BPF_STMT(BPF_STX, 15),
2159 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2160 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2161 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2162 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2163 BPF_STMT(BPF_RET | BPF_A, 0),
2164 },
2165 CLASSIC | FLAG_NO_DATA,
2166 { },
2167 { { 0, 116 } },
2168 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002169 { /* Mainly checking JIT here. */
2170 "M[]: full STX + full LDX",
2171 .u.insns = {
2172 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2173 BPF_STMT(BPF_STX, 0),
2174 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2175 BPF_STMT(BPF_STX, 1),
2176 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2177 BPF_STMT(BPF_STX, 2),
2178 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2179 BPF_STMT(BPF_STX, 3),
2180 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2181 BPF_STMT(BPF_STX, 4),
2182 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2183 BPF_STMT(BPF_STX, 5),
2184 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2185 BPF_STMT(BPF_STX, 6),
2186 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2187 BPF_STMT(BPF_STX, 7),
2188 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2189 BPF_STMT(BPF_STX, 8),
2190 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2191 BPF_STMT(BPF_STX, 9),
2192 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2193 BPF_STMT(BPF_STX, 10),
2194 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2195 BPF_STMT(BPF_STX, 11),
2196 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2197 BPF_STMT(BPF_STX, 12),
2198 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2199 BPF_STMT(BPF_STX, 13),
2200 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2201 BPF_STMT(BPF_STX, 14),
2202 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2203 BPF_STMT(BPF_STX, 15),
2204 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2205 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2206 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2207 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2208 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2209 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2210 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2211 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2212 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2213 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2214 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2215 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2216 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2217 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2218 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2219 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2220 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2221 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2222 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2223 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2224 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2225 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2226 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2227 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2228 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2229 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2230 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2231 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2232 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2233 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2234 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2235 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2236 BPF_STMT(BPF_RET | BPF_A, 0),
2237 },
2238 CLASSIC | FLAG_NO_DATA,
2239 { },
2240 { { 0, 0x2a5a5e5 } },
2241 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002242 {
2243 "check: SKF_AD_MAX",
2244 .u.insns = {
2245 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2246 SKF_AD_OFF + SKF_AD_MAX),
2247 BPF_STMT(BPF_RET | BPF_A, 0),
2248 },
2249 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2250 { },
2251 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002252 .fill_helper = NULL,
2253 .expected_errcode = -EINVAL,
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002254 },
2255 { /* Passes checker but fails during runtime. */
2256 "LD [SKF_AD_OFF-1]",
2257 .u.insns = {
2258 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2259 SKF_AD_OFF - 1),
2260 BPF_STMT(BPF_RET | BPF_K, 1),
2261 },
2262 CLASSIC,
2263 { },
2264 { { 1, 0 } },
2265 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002266 {
2267 "load 64-bit immediate",
2268 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07002269 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002270 BPF_MOV64_REG(R2, R1),
2271 BPF_MOV64_REG(R3, R2),
2272 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2273 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2274 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2275 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2276 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2277 BPF_EXIT_INSN(),
2278 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2279 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04002280 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2281 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002282 BPF_EXIT_INSN(),
2283 },
2284 INTERNAL,
2285 { },
2286 { { 0, 1 } }
2287 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002288 /* BPF_ALU | BPF_MOV | BPF_X */
2289 {
2290 "ALU_MOV_X: dst = 2",
2291 .u.insns_int = {
2292 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2293 BPF_ALU32_REG(BPF_MOV, R0, R1),
2294 BPF_EXIT_INSN(),
2295 },
2296 INTERNAL,
2297 { },
2298 { { 0, 2 } },
2299 },
2300 {
2301 "ALU_MOV_X: dst = 4294967295",
2302 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002303 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002304 BPF_ALU32_REG(BPF_MOV, R0, R1),
2305 BPF_EXIT_INSN(),
2306 },
2307 INTERNAL,
2308 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002309 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002310 },
2311 {
2312 "ALU64_MOV_X: dst = 2",
2313 .u.insns_int = {
2314 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2315 BPF_ALU64_REG(BPF_MOV, R0, R1),
2316 BPF_EXIT_INSN(),
2317 },
2318 INTERNAL,
2319 { },
2320 { { 0, 2 } },
2321 },
2322 {
2323 "ALU64_MOV_X: dst = 4294967295",
2324 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002325 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002326 BPF_ALU64_REG(BPF_MOV, R0, R1),
2327 BPF_EXIT_INSN(),
2328 },
2329 INTERNAL,
2330 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002331 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002332 },
2333 /* BPF_ALU | BPF_MOV | BPF_K */
2334 {
2335 "ALU_MOV_K: dst = 2",
2336 .u.insns_int = {
2337 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2338 BPF_EXIT_INSN(),
2339 },
2340 INTERNAL,
2341 { },
2342 { { 0, 2 } },
2343 },
2344 {
2345 "ALU_MOV_K: dst = 4294967295",
2346 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002347 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002348 BPF_EXIT_INSN(),
2349 },
2350 INTERNAL,
2351 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002352 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002353 },
2354 {
2355 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2356 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002357 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2358 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002359 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2360 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2361 BPF_MOV32_IMM(R0, 2),
2362 BPF_EXIT_INSN(),
2363 BPF_MOV32_IMM(R0, 1),
2364 BPF_EXIT_INSN(),
2365 },
2366 INTERNAL,
2367 { },
2368 { { 0, 0x1 } },
2369 },
2370 {
2371 "ALU64_MOV_K: dst = 2",
2372 .u.insns_int = {
2373 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2374 BPF_EXIT_INSN(),
2375 },
2376 INTERNAL,
2377 { },
2378 { { 0, 2 } },
2379 },
2380 {
2381 "ALU64_MOV_K: dst = 2147483647",
2382 .u.insns_int = {
2383 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2384 BPF_EXIT_INSN(),
2385 },
2386 INTERNAL,
2387 { },
2388 { { 0, 2147483647 } },
2389 },
2390 {
2391 "ALU64_OR_K: dst = 0x0",
2392 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002393 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002394 BPF_LD_IMM64(R3, 0x0),
2395 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2396 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2397 BPF_MOV32_IMM(R0, 2),
2398 BPF_EXIT_INSN(),
2399 BPF_MOV32_IMM(R0, 1),
2400 BPF_EXIT_INSN(),
2401 },
2402 INTERNAL,
2403 { },
2404 { { 0, 0x1 } },
2405 },
2406 {
2407 "ALU64_MOV_K: dst = -1",
2408 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002409 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2410 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002411 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2412 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2413 BPF_MOV32_IMM(R0, 2),
2414 BPF_EXIT_INSN(),
2415 BPF_MOV32_IMM(R0, 1),
2416 BPF_EXIT_INSN(),
2417 },
2418 INTERNAL,
2419 { },
2420 { { 0, 0x1 } },
2421 },
2422 /* BPF_ALU | BPF_ADD | BPF_X */
2423 {
2424 "ALU_ADD_X: 1 + 2 = 3",
2425 .u.insns_int = {
2426 BPF_LD_IMM64(R0, 1),
2427 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2428 BPF_ALU32_REG(BPF_ADD, R0, R1),
2429 BPF_EXIT_INSN(),
2430 },
2431 INTERNAL,
2432 { },
2433 { { 0, 3 } },
2434 },
2435 {
2436 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2437 .u.insns_int = {
2438 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002439 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002440 BPF_ALU32_REG(BPF_ADD, R0, R1),
2441 BPF_EXIT_INSN(),
2442 },
2443 INTERNAL,
2444 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002445 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002446 },
2447 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302448 "ALU_ADD_X: 2 + 4294967294 = 0",
2449 .u.insns_int = {
2450 BPF_LD_IMM64(R0, 2),
2451 BPF_LD_IMM64(R1, 4294967294U),
2452 BPF_ALU32_REG(BPF_ADD, R0, R1),
2453 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2454 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2455 BPF_EXIT_INSN(),
2456 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2457 BPF_EXIT_INSN(),
2458 },
2459 INTERNAL,
2460 { },
2461 { { 0, 1 } },
2462 },
2463 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002464 "ALU64_ADD_X: 1 + 2 = 3",
2465 .u.insns_int = {
2466 BPF_LD_IMM64(R0, 1),
2467 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2468 BPF_ALU64_REG(BPF_ADD, R0, R1),
2469 BPF_EXIT_INSN(),
2470 },
2471 INTERNAL,
2472 { },
2473 { { 0, 3 } },
2474 },
2475 {
2476 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2477 .u.insns_int = {
2478 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002479 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002480 BPF_ALU64_REG(BPF_ADD, R0, R1),
2481 BPF_EXIT_INSN(),
2482 },
2483 INTERNAL,
2484 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002485 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002486 },
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302487 {
2488 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2489 .u.insns_int = {
2490 BPF_LD_IMM64(R0, 2),
2491 BPF_LD_IMM64(R1, 4294967294U),
2492 BPF_LD_IMM64(R2, 4294967296ULL),
2493 BPF_ALU64_REG(BPF_ADD, R0, R1),
2494 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2495 BPF_MOV32_IMM(R0, 0),
2496 BPF_EXIT_INSN(),
2497 BPF_MOV32_IMM(R0, 1),
2498 BPF_EXIT_INSN(),
2499 },
2500 INTERNAL,
2501 { },
2502 { { 0, 1 } },
2503 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002504 /* BPF_ALU | BPF_ADD | BPF_K */
2505 {
2506 "ALU_ADD_K: 1 + 2 = 3",
2507 .u.insns_int = {
2508 BPF_LD_IMM64(R0, 1),
2509 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2510 BPF_EXIT_INSN(),
2511 },
2512 INTERNAL,
2513 { },
2514 { { 0, 3 } },
2515 },
2516 {
2517 "ALU_ADD_K: 3 + 0 = 3",
2518 .u.insns_int = {
2519 BPF_LD_IMM64(R0, 3),
2520 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2521 BPF_EXIT_INSN(),
2522 },
2523 INTERNAL,
2524 { },
2525 { { 0, 3 } },
2526 },
2527 {
2528 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2529 .u.insns_int = {
2530 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002531 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002532 BPF_EXIT_INSN(),
2533 },
2534 INTERNAL,
2535 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002536 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002537 },
2538 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302539 "ALU_ADD_K: 4294967294 + 2 = 0",
2540 .u.insns_int = {
2541 BPF_LD_IMM64(R0, 4294967294U),
2542 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2543 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2544 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2545 BPF_EXIT_INSN(),
2546 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2547 BPF_EXIT_INSN(),
2548 },
2549 INTERNAL,
2550 { },
2551 { { 0, 1 } },
2552 },
2553 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002554 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2555 .u.insns_int = {
2556 BPF_LD_IMM64(R2, 0x0),
2557 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2558 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2559 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2560 BPF_MOV32_IMM(R0, 2),
2561 BPF_EXIT_INSN(),
2562 BPF_MOV32_IMM(R0, 1),
2563 BPF_EXIT_INSN(),
2564 },
2565 INTERNAL,
2566 { },
2567 { { 0, 0x1 } },
2568 },
2569 {
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302570 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2571 .u.insns_int = {
2572 BPF_LD_IMM64(R2, 0x0),
2573 BPF_LD_IMM64(R3, 0xffff),
2574 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2575 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2576 BPF_MOV32_IMM(R0, 2),
2577 BPF_EXIT_INSN(),
2578 BPF_MOV32_IMM(R0, 1),
2579 BPF_EXIT_INSN(),
2580 },
2581 INTERNAL,
2582 { },
2583 { { 0, 0x1 } },
2584 },
2585 {
2586 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2587 .u.insns_int = {
2588 BPF_LD_IMM64(R2, 0x0),
2589 BPF_LD_IMM64(R3, 0x7fffffff),
2590 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2591 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2592 BPF_MOV32_IMM(R0, 2),
2593 BPF_EXIT_INSN(),
2594 BPF_MOV32_IMM(R0, 1),
2595 BPF_EXIT_INSN(),
2596 },
2597 INTERNAL,
2598 { },
2599 { { 0, 0x1 } },
2600 },
2601 {
2602 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2603 .u.insns_int = {
2604 BPF_LD_IMM64(R2, 0x0),
2605 BPF_LD_IMM64(R3, 0x80000000),
2606 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2607 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2608 BPF_MOV32_IMM(R0, 2),
2609 BPF_EXIT_INSN(),
2610 BPF_MOV32_IMM(R0, 1),
2611 BPF_EXIT_INSN(),
2612 },
2613 INTERNAL,
2614 { },
2615 { { 0, 0x1 } },
2616 },
2617 {
2618 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2619 .u.insns_int = {
2620 BPF_LD_IMM64(R2, 0x0),
2621 BPF_LD_IMM64(R3, 0x80008000),
2622 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2623 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2624 BPF_MOV32_IMM(R0, 2),
2625 BPF_EXIT_INSN(),
2626 BPF_MOV32_IMM(R0, 1),
2627 BPF_EXIT_INSN(),
2628 },
2629 INTERNAL,
2630 { },
2631 { { 0, 0x1 } },
2632 },
2633 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002634 "ALU64_ADD_K: 1 + 2 = 3",
2635 .u.insns_int = {
2636 BPF_LD_IMM64(R0, 1),
2637 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2638 BPF_EXIT_INSN(),
2639 },
2640 INTERNAL,
2641 { },
2642 { { 0, 3 } },
2643 },
2644 {
2645 "ALU64_ADD_K: 3 + 0 = 3",
2646 .u.insns_int = {
2647 BPF_LD_IMM64(R0, 3),
2648 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2649 BPF_EXIT_INSN(),
2650 },
2651 INTERNAL,
2652 { },
2653 { { 0, 3 } },
2654 },
2655 {
2656 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2657 .u.insns_int = {
2658 BPF_LD_IMM64(R0, 1),
2659 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2660 BPF_EXIT_INSN(),
2661 },
2662 INTERNAL,
2663 { },
2664 { { 0, 2147483647 } },
2665 },
2666 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302667 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2668 .u.insns_int = {
2669 BPF_LD_IMM64(R0, 4294967294U),
2670 BPF_LD_IMM64(R1, 4294967296ULL),
2671 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2672 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2673 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2674 BPF_EXIT_INSN(),
2675 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2676 BPF_EXIT_INSN(),
2677 },
2678 INTERNAL,
2679 { },
2680 { { 0, 1 } },
2681 },
2682 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002683 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2684 .u.insns_int = {
2685 BPF_LD_IMM64(R0, 2147483646),
2686 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2687 BPF_EXIT_INSN(),
2688 },
2689 INTERNAL,
2690 { },
2691 { { 0, -1 } },
2692 },
2693 {
2694 "ALU64_ADD_K: 1 + 0 = 1",
2695 .u.insns_int = {
2696 BPF_LD_IMM64(R2, 0x1),
2697 BPF_LD_IMM64(R3, 0x1),
2698 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2699 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2700 BPF_MOV32_IMM(R0, 2),
2701 BPF_EXIT_INSN(),
2702 BPF_MOV32_IMM(R0, 1),
2703 BPF_EXIT_INSN(),
2704 },
2705 INTERNAL,
2706 { },
2707 { { 0, 0x1 } },
2708 },
2709 {
2710 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2711 .u.insns_int = {
2712 BPF_LD_IMM64(R2, 0x0),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002713 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002714 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2715 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2716 BPF_MOV32_IMM(R0, 2),
2717 BPF_EXIT_INSN(),
2718 BPF_MOV32_IMM(R0, 1),
2719 BPF_EXIT_INSN(),
2720 },
2721 INTERNAL,
2722 { },
2723 { { 0, 0x1 } },
2724 },
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302725 {
2726 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2727 .u.insns_int = {
2728 BPF_LD_IMM64(R2, 0x0),
2729 BPF_LD_IMM64(R3, 0xffff),
2730 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
2731 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2732 BPF_MOV32_IMM(R0, 2),
2733 BPF_EXIT_INSN(),
2734 BPF_MOV32_IMM(R0, 1),
2735 BPF_EXIT_INSN(),
2736 },
2737 INTERNAL,
2738 { },
2739 { { 0, 0x1 } },
2740 },
2741 {
2742 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2743 .u.insns_int = {
2744 BPF_LD_IMM64(R2, 0x0),
2745 BPF_LD_IMM64(R3, 0x7fffffff),
2746 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
2747 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2748 BPF_MOV32_IMM(R0, 2),
2749 BPF_EXIT_INSN(),
2750 BPF_MOV32_IMM(R0, 1),
2751 BPF_EXIT_INSN(),
2752 },
2753 INTERNAL,
2754 { },
2755 { { 0, 0x1 } },
2756 },
2757 {
2758 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2759 .u.insns_int = {
2760 BPF_LD_IMM64(R2, 0x0),
2761 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
2762 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
2763 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2764 BPF_MOV32_IMM(R0, 2),
2765 BPF_EXIT_INSN(),
2766 BPF_MOV32_IMM(R0, 1),
2767 BPF_EXIT_INSN(),
2768 },
2769 INTERNAL,
2770 { },
2771 { { 0, 0x1 } },
2772 },
2773 {
2774 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2775 .u.insns_int = {
2776 BPF_LD_IMM64(R2, 0x0),
2777 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
2778 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
2779 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2780 BPF_MOV32_IMM(R0, 2),
2781 BPF_EXIT_INSN(),
2782 BPF_MOV32_IMM(R0, 1),
2783 BPF_EXIT_INSN(),
2784 },
2785 INTERNAL,
2786 { },
2787 { { 0, 0x1 } },
2788 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002789 /* BPF_ALU | BPF_SUB | BPF_X */
2790 {
2791 "ALU_SUB_X: 3 - 1 = 2",
2792 .u.insns_int = {
2793 BPF_LD_IMM64(R0, 3),
2794 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2795 BPF_ALU32_REG(BPF_SUB, R0, R1),
2796 BPF_EXIT_INSN(),
2797 },
2798 INTERNAL,
2799 { },
2800 { { 0, 2 } },
2801 },
2802 {
2803 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2804 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002805 BPF_LD_IMM64(R0, 4294967295U),
2806 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002807 BPF_ALU32_REG(BPF_SUB, R0, R1),
2808 BPF_EXIT_INSN(),
2809 },
2810 INTERNAL,
2811 { },
2812 { { 0, 1 } },
2813 },
2814 {
2815 "ALU64_SUB_X: 3 - 1 = 2",
2816 .u.insns_int = {
2817 BPF_LD_IMM64(R0, 3),
2818 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2819 BPF_ALU64_REG(BPF_SUB, R0, R1),
2820 BPF_EXIT_INSN(),
2821 },
2822 INTERNAL,
2823 { },
2824 { { 0, 2 } },
2825 },
2826 {
2827 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2828 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002829 BPF_LD_IMM64(R0, 4294967295U),
2830 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002831 BPF_ALU64_REG(BPF_SUB, R0, R1),
2832 BPF_EXIT_INSN(),
2833 },
2834 INTERNAL,
2835 { },
2836 { { 0, 1 } },
2837 },
2838 /* BPF_ALU | BPF_SUB | BPF_K */
2839 {
2840 "ALU_SUB_K: 3 - 1 = 2",
2841 .u.insns_int = {
2842 BPF_LD_IMM64(R0, 3),
2843 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2844 BPF_EXIT_INSN(),
2845 },
2846 INTERNAL,
2847 { },
2848 { { 0, 2 } },
2849 },
2850 {
2851 "ALU_SUB_K: 3 - 0 = 3",
2852 .u.insns_int = {
2853 BPF_LD_IMM64(R0, 3),
2854 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2855 BPF_EXIT_INSN(),
2856 },
2857 INTERNAL,
2858 { },
2859 { { 0, 3 } },
2860 },
2861 {
2862 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2863 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002864 BPF_LD_IMM64(R0, 4294967295U),
2865 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002866 BPF_EXIT_INSN(),
2867 },
2868 INTERNAL,
2869 { },
2870 { { 0, 1 } },
2871 },
2872 {
2873 "ALU64_SUB_K: 3 - 1 = 2",
2874 .u.insns_int = {
2875 BPF_LD_IMM64(R0, 3),
2876 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2877 BPF_EXIT_INSN(),
2878 },
2879 INTERNAL,
2880 { },
2881 { { 0, 2 } },
2882 },
2883 {
2884 "ALU64_SUB_K: 3 - 0 = 3",
2885 .u.insns_int = {
2886 BPF_LD_IMM64(R0, 3),
2887 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2888 BPF_EXIT_INSN(),
2889 },
2890 INTERNAL,
2891 { },
2892 { { 0, 3 } },
2893 },
2894 {
2895 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2896 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002897 BPF_LD_IMM64(R0, 4294967294U),
2898 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002899 BPF_EXIT_INSN(),
2900 },
2901 INTERNAL,
2902 { },
2903 { { 0, -1 } },
2904 },
2905 {
2906 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2907 .u.insns_int = {
2908 BPF_LD_IMM64(R0, 2147483646),
2909 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2910 BPF_EXIT_INSN(),
2911 },
2912 INTERNAL,
2913 { },
2914 { { 0, -1 } },
2915 },
2916 /* BPF_ALU | BPF_MUL | BPF_X */
2917 {
2918 "ALU_MUL_X: 2 * 3 = 6",
2919 .u.insns_int = {
2920 BPF_LD_IMM64(R0, 2),
2921 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2922 BPF_ALU32_REG(BPF_MUL, R0, R1),
2923 BPF_EXIT_INSN(),
2924 },
2925 INTERNAL,
2926 { },
2927 { { 0, 6 } },
2928 },
2929 {
2930 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2931 .u.insns_int = {
2932 BPF_LD_IMM64(R0, 2),
2933 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2934 BPF_ALU32_REG(BPF_MUL, R0, R1),
2935 BPF_EXIT_INSN(),
2936 },
2937 INTERNAL,
2938 { },
2939 { { 0, 0xFFFFFFF0 } },
2940 },
2941 {
2942 "ALU_MUL_X: -1 * -1 = 1",
2943 .u.insns_int = {
2944 BPF_LD_IMM64(R0, -1),
2945 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2946 BPF_ALU32_REG(BPF_MUL, R0, R1),
2947 BPF_EXIT_INSN(),
2948 },
2949 INTERNAL,
2950 { },
2951 { { 0, 1 } },
2952 },
2953 {
2954 "ALU64_MUL_X: 2 * 3 = 6",
2955 .u.insns_int = {
2956 BPF_LD_IMM64(R0, 2),
2957 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2958 BPF_ALU64_REG(BPF_MUL, R0, R1),
2959 BPF_EXIT_INSN(),
2960 },
2961 INTERNAL,
2962 { },
2963 { { 0, 6 } },
2964 },
2965 {
2966 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2967 .u.insns_int = {
2968 BPF_LD_IMM64(R0, 1),
2969 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2970 BPF_ALU64_REG(BPF_MUL, R0, R1),
2971 BPF_EXIT_INSN(),
2972 },
2973 INTERNAL,
2974 { },
2975 { { 0, 2147483647 } },
2976 },
2977 /* BPF_ALU | BPF_MUL | BPF_K */
2978 {
2979 "ALU_MUL_K: 2 * 3 = 6",
2980 .u.insns_int = {
2981 BPF_LD_IMM64(R0, 2),
2982 BPF_ALU32_IMM(BPF_MUL, R0, 3),
2983 BPF_EXIT_INSN(),
2984 },
2985 INTERNAL,
2986 { },
2987 { { 0, 6 } },
2988 },
2989 {
2990 "ALU_MUL_K: 3 * 1 = 3",
2991 .u.insns_int = {
2992 BPF_LD_IMM64(R0, 3),
2993 BPF_ALU32_IMM(BPF_MUL, R0, 1),
2994 BPF_EXIT_INSN(),
2995 },
2996 INTERNAL,
2997 { },
2998 { { 0, 3 } },
2999 },
3000 {
3001 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
3002 .u.insns_int = {
3003 BPF_LD_IMM64(R0, 2),
3004 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
3005 BPF_EXIT_INSN(),
3006 },
3007 INTERNAL,
3008 { },
3009 { { 0, 0xFFFFFFF0 } },
3010 },
3011 {
3012 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3013 .u.insns_int = {
3014 BPF_LD_IMM64(R2, 0x1),
3015 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3016 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3017 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3018 BPF_MOV32_IMM(R0, 2),
3019 BPF_EXIT_INSN(),
3020 BPF_MOV32_IMM(R0, 1),
3021 BPF_EXIT_INSN(),
3022 },
3023 INTERNAL,
3024 { },
3025 { { 0, 0x1 } },
3026 },
3027 {
3028 "ALU64_MUL_K: 2 * 3 = 6",
3029 .u.insns_int = {
3030 BPF_LD_IMM64(R0, 2),
3031 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3032 BPF_EXIT_INSN(),
3033 },
3034 INTERNAL,
3035 { },
3036 { { 0, 6 } },
3037 },
3038 {
3039 "ALU64_MUL_K: 3 * 1 = 3",
3040 .u.insns_int = {
3041 BPF_LD_IMM64(R0, 3),
3042 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3043 BPF_EXIT_INSN(),
3044 },
3045 INTERNAL,
3046 { },
3047 { { 0, 3 } },
3048 },
3049 {
3050 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3051 .u.insns_int = {
3052 BPF_LD_IMM64(R0, 1),
3053 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3054 BPF_EXIT_INSN(),
3055 },
3056 INTERNAL,
3057 { },
3058 { { 0, 2147483647 } },
3059 },
3060 {
3061 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3062 .u.insns_int = {
3063 BPF_LD_IMM64(R0, 1),
3064 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3065 BPF_EXIT_INSN(),
3066 },
3067 INTERNAL,
3068 { },
3069 { { 0, -2147483647 } },
3070 },
3071 {
3072 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3073 .u.insns_int = {
3074 BPF_LD_IMM64(R2, 0x1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003075 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003076 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3077 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3078 BPF_MOV32_IMM(R0, 2),
3079 BPF_EXIT_INSN(),
3080 BPF_MOV32_IMM(R0, 1),
3081 BPF_EXIT_INSN(),
3082 },
3083 INTERNAL,
3084 { },
3085 { { 0, 0x1 } },
3086 },
3087 /* BPF_ALU | BPF_DIV | BPF_X */
3088 {
3089 "ALU_DIV_X: 6 / 2 = 3",
3090 .u.insns_int = {
3091 BPF_LD_IMM64(R0, 6),
3092 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3093 BPF_ALU32_REG(BPF_DIV, R0, R1),
3094 BPF_EXIT_INSN(),
3095 },
3096 INTERNAL,
3097 { },
3098 { { 0, 3 } },
3099 },
3100 {
3101 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3102 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003103 BPF_LD_IMM64(R0, 4294967295U),
3104 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003105 BPF_ALU32_REG(BPF_DIV, R0, R1),
3106 BPF_EXIT_INSN(),
3107 },
3108 INTERNAL,
3109 { },
3110 { { 0, 1 } },
3111 },
3112 {
3113 "ALU64_DIV_X: 6 / 2 = 3",
3114 .u.insns_int = {
3115 BPF_LD_IMM64(R0, 6),
3116 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3117 BPF_ALU64_REG(BPF_DIV, R0, R1),
3118 BPF_EXIT_INSN(),
3119 },
3120 INTERNAL,
3121 { },
3122 { { 0, 3 } },
3123 },
3124 {
3125 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3126 .u.insns_int = {
3127 BPF_LD_IMM64(R0, 2147483647),
3128 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3129 BPF_ALU64_REG(BPF_DIV, R0, R1),
3130 BPF_EXIT_INSN(),
3131 },
3132 INTERNAL,
3133 { },
3134 { { 0, 1 } },
3135 },
3136 {
3137 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3138 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003139 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3140 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3141 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003142 BPF_ALU64_REG(BPF_DIV, R2, R4),
3143 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3144 BPF_MOV32_IMM(R0, 2),
3145 BPF_EXIT_INSN(),
3146 BPF_MOV32_IMM(R0, 1),
3147 BPF_EXIT_INSN(),
3148 },
3149 INTERNAL,
3150 { },
3151 { { 0, 0x1 } },
3152 },
3153 /* BPF_ALU | BPF_DIV | BPF_K */
3154 {
3155 "ALU_DIV_K: 6 / 2 = 3",
3156 .u.insns_int = {
3157 BPF_LD_IMM64(R0, 6),
3158 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3159 BPF_EXIT_INSN(),
3160 },
3161 INTERNAL,
3162 { },
3163 { { 0, 3 } },
3164 },
3165 {
3166 "ALU_DIV_K: 3 / 1 = 3",
3167 .u.insns_int = {
3168 BPF_LD_IMM64(R0, 3),
3169 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3170 BPF_EXIT_INSN(),
3171 },
3172 INTERNAL,
3173 { },
3174 { { 0, 3 } },
3175 },
3176 {
3177 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3178 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003179 BPF_LD_IMM64(R0, 4294967295U),
3180 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003181 BPF_EXIT_INSN(),
3182 },
3183 INTERNAL,
3184 { },
3185 { { 0, 1 } },
3186 },
3187 {
3188 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3189 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003190 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003191 BPF_LD_IMM64(R3, 0x1UL),
3192 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3193 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3194 BPF_MOV32_IMM(R0, 2),
3195 BPF_EXIT_INSN(),
3196 BPF_MOV32_IMM(R0, 1),
3197 BPF_EXIT_INSN(),
3198 },
3199 INTERNAL,
3200 { },
3201 { { 0, 0x1 } },
3202 },
3203 {
3204 "ALU64_DIV_K: 6 / 2 = 3",
3205 .u.insns_int = {
3206 BPF_LD_IMM64(R0, 6),
3207 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3208 BPF_EXIT_INSN(),
3209 },
3210 INTERNAL,
3211 { },
3212 { { 0, 3 } },
3213 },
3214 {
3215 "ALU64_DIV_K: 3 / 1 = 3",
3216 .u.insns_int = {
3217 BPF_LD_IMM64(R0, 3),
3218 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3219 BPF_EXIT_INSN(),
3220 },
3221 INTERNAL,
3222 { },
3223 { { 0, 3 } },
3224 },
3225 {
3226 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3227 .u.insns_int = {
3228 BPF_LD_IMM64(R0, 2147483647),
3229 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3230 BPF_EXIT_INSN(),
3231 },
3232 INTERNAL,
3233 { },
3234 { { 0, 1 } },
3235 },
3236 {
3237 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3238 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003239 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3240 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003241 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3242 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3243 BPF_MOV32_IMM(R0, 2),
3244 BPF_EXIT_INSN(),
3245 BPF_MOV32_IMM(R0, 1),
3246 BPF_EXIT_INSN(),
3247 },
3248 INTERNAL,
3249 { },
3250 { { 0, 0x1 } },
3251 },
3252 /* BPF_ALU | BPF_MOD | BPF_X */
3253 {
3254 "ALU_MOD_X: 3 % 2 = 1",
3255 .u.insns_int = {
3256 BPF_LD_IMM64(R0, 3),
3257 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3258 BPF_ALU32_REG(BPF_MOD, R0, R1),
3259 BPF_EXIT_INSN(),
3260 },
3261 INTERNAL,
3262 { },
3263 { { 0, 1 } },
3264 },
3265 {
3266 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3267 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003268 BPF_LD_IMM64(R0, 4294967295U),
3269 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003270 BPF_ALU32_REG(BPF_MOD, R0, R1),
3271 BPF_EXIT_INSN(),
3272 },
3273 INTERNAL,
3274 { },
3275 { { 0, 2 } },
3276 },
3277 {
3278 "ALU64_MOD_X: 3 % 2 = 1",
3279 .u.insns_int = {
3280 BPF_LD_IMM64(R0, 3),
3281 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3282 BPF_ALU64_REG(BPF_MOD, R0, R1),
3283 BPF_EXIT_INSN(),
3284 },
3285 INTERNAL,
3286 { },
3287 { { 0, 1 } },
3288 },
3289 {
3290 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3291 .u.insns_int = {
3292 BPF_LD_IMM64(R0, 2147483647),
3293 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3294 BPF_ALU64_REG(BPF_MOD, R0, R1),
3295 BPF_EXIT_INSN(),
3296 },
3297 INTERNAL,
3298 { },
3299 { { 0, 2 } },
3300 },
3301 /* BPF_ALU | BPF_MOD | BPF_K */
3302 {
3303 "ALU_MOD_K: 3 % 2 = 1",
3304 .u.insns_int = {
3305 BPF_LD_IMM64(R0, 3),
3306 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3307 BPF_EXIT_INSN(),
3308 },
3309 INTERNAL,
3310 { },
3311 { { 0, 1 } },
3312 },
3313 {
3314 "ALU_MOD_K: 3 % 1 = 0",
3315 .u.insns_int = {
3316 BPF_LD_IMM64(R0, 3),
3317 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3318 BPF_EXIT_INSN(),
3319 },
3320 INTERNAL,
3321 { },
3322 { { 0, 0 } },
3323 },
3324 {
3325 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3326 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003327 BPF_LD_IMM64(R0, 4294967295U),
3328 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003329 BPF_EXIT_INSN(),
3330 },
3331 INTERNAL,
3332 { },
3333 { { 0, 2 } },
3334 },
3335 {
3336 "ALU64_MOD_K: 3 % 2 = 1",
3337 .u.insns_int = {
3338 BPF_LD_IMM64(R0, 3),
3339 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3340 BPF_EXIT_INSN(),
3341 },
3342 INTERNAL,
3343 { },
3344 { { 0, 1 } },
3345 },
3346 {
3347 "ALU64_MOD_K: 3 % 1 = 0",
3348 .u.insns_int = {
3349 BPF_LD_IMM64(R0, 3),
3350 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3351 BPF_EXIT_INSN(),
3352 },
3353 INTERNAL,
3354 { },
3355 { { 0, 0 } },
3356 },
3357 {
3358 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3359 .u.insns_int = {
3360 BPF_LD_IMM64(R0, 2147483647),
3361 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3362 BPF_EXIT_INSN(),
3363 },
3364 INTERNAL,
3365 { },
3366 { { 0, 2 } },
3367 },
3368 /* BPF_ALU | BPF_AND | BPF_X */
3369 {
3370 "ALU_AND_X: 3 & 2 = 2",
3371 .u.insns_int = {
3372 BPF_LD_IMM64(R0, 3),
3373 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3374 BPF_ALU32_REG(BPF_AND, R0, R1),
3375 BPF_EXIT_INSN(),
3376 },
3377 INTERNAL,
3378 { },
3379 { { 0, 2 } },
3380 },
3381 {
3382 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3383 .u.insns_int = {
3384 BPF_LD_IMM64(R0, 0xffffffff),
3385 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3386 BPF_ALU32_REG(BPF_AND, R0, R1),
3387 BPF_EXIT_INSN(),
3388 },
3389 INTERNAL,
3390 { },
3391 { { 0, 0xffffffff } },
3392 },
3393 {
3394 "ALU64_AND_X: 3 & 2 = 2",
3395 .u.insns_int = {
3396 BPF_LD_IMM64(R0, 3),
3397 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3398 BPF_ALU64_REG(BPF_AND, R0, R1),
3399 BPF_EXIT_INSN(),
3400 },
3401 INTERNAL,
3402 { },
3403 { { 0, 2 } },
3404 },
3405 {
3406 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3407 .u.insns_int = {
3408 BPF_LD_IMM64(R0, 0xffffffff),
3409 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3410 BPF_ALU64_REG(BPF_AND, R0, R1),
3411 BPF_EXIT_INSN(),
3412 },
3413 INTERNAL,
3414 { },
3415 { { 0, 0xffffffff } },
3416 },
3417 /* BPF_ALU | BPF_AND | BPF_K */
3418 {
3419 "ALU_AND_K: 3 & 2 = 2",
3420 .u.insns_int = {
3421 BPF_LD_IMM64(R0, 3),
3422 BPF_ALU32_IMM(BPF_AND, R0, 2),
3423 BPF_EXIT_INSN(),
3424 },
3425 INTERNAL,
3426 { },
3427 { { 0, 2 } },
3428 },
3429 {
3430 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3431 .u.insns_int = {
3432 BPF_LD_IMM64(R0, 0xffffffff),
3433 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3434 BPF_EXIT_INSN(),
3435 },
3436 INTERNAL,
3437 { },
3438 { { 0, 0xffffffff } },
3439 },
3440 {
3441 "ALU64_AND_K: 3 & 2 = 2",
3442 .u.insns_int = {
3443 BPF_LD_IMM64(R0, 3),
3444 BPF_ALU64_IMM(BPF_AND, R0, 2),
3445 BPF_EXIT_INSN(),
3446 },
3447 INTERNAL,
3448 { },
3449 { { 0, 2 } },
3450 },
3451 {
3452 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3453 .u.insns_int = {
3454 BPF_LD_IMM64(R0, 0xffffffff),
3455 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3456 BPF_EXIT_INSN(),
3457 },
3458 INTERNAL,
3459 { },
3460 { { 0, 0xffffffff } },
3461 },
3462 {
3463 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3464 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003465 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3466 BPF_LD_IMM64(R3, 0x0000000000000000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003467 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3468 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3469 BPF_MOV32_IMM(R0, 2),
3470 BPF_EXIT_INSN(),
3471 BPF_MOV32_IMM(R0, 1),
3472 BPF_EXIT_INSN(),
3473 },
3474 INTERNAL,
3475 { },
3476 { { 0, 0x1 } },
3477 },
3478 {
3479 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3480 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003481 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3482 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003483 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3484 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3485 BPF_MOV32_IMM(R0, 2),
3486 BPF_EXIT_INSN(),
3487 BPF_MOV32_IMM(R0, 1),
3488 BPF_EXIT_INSN(),
3489 },
3490 INTERNAL,
3491 { },
3492 { { 0, 0x1 } },
3493 },
3494 {
3495 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3496 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003497 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3498 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003499 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3500 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3501 BPF_MOV32_IMM(R0, 2),
3502 BPF_EXIT_INSN(),
3503 BPF_MOV32_IMM(R0, 1),
3504 BPF_EXIT_INSN(),
3505 },
3506 INTERNAL,
3507 { },
3508 { { 0, 0x1 } },
3509 },
3510 /* BPF_ALU | BPF_OR | BPF_X */
3511 {
3512 "ALU_OR_X: 1 | 2 = 3",
3513 .u.insns_int = {
3514 BPF_LD_IMM64(R0, 1),
3515 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3516 BPF_ALU32_REG(BPF_OR, R0, R1),
3517 BPF_EXIT_INSN(),
3518 },
3519 INTERNAL,
3520 { },
3521 { { 0, 3 } },
3522 },
3523 {
3524 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3525 .u.insns_int = {
3526 BPF_LD_IMM64(R0, 0),
3527 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3528 BPF_ALU32_REG(BPF_OR, R0, R1),
3529 BPF_EXIT_INSN(),
3530 },
3531 INTERNAL,
3532 { },
3533 { { 0, 0xffffffff } },
3534 },
3535 {
3536 "ALU64_OR_X: 1 | 2 = 3",
3537 .u.insns_int = {
3538 BPF_LD_IMM64(R0, 1),
3539 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3540 BPF_ALU64_REG(BPF_OR, R0, R1),
3541 BPF_EXIT_INSN(),
3542 },
3543 INTERNAL,
3544 { },
3545 { { 0, 3 } },
3546 },
3547 {
3548 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3549 .u.insns_int = {
3550 BPF_LD_IMM64(R0, 0),
3551 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3552 BPF_ALU64_REG(BPF_OR, R0, R1),
3553 BPF_EXIT_INSN(),
3554 },
3555 INTERNAL,
3556 { },
3557 { { 0, 0xffffffff } },
3558 },
3559 /* BPF_ALU | BPF_OR | BPF_K */
3560 {
3561 "ALU_OR_K: 1 | 2 = 3",
3562 .u.insns_int = {
3563 BPF_LD_IMM64(R0, 1),
3564 BPF_ALU32_IMM(BPF_OR, R0, 2),
3565 BPF_EXIT_INSN(),
3566 },
3567 INTERNAL,
3568 { },
3569 { { 0, 3 } },
3570 },
3571 {
3572 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3573 .u.insns_int = {
3574 BPF_LD_IMM64(R0, 0),
3575 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3576 BPF_EXIT_INSN(),
3577 },
3578 INTERNAL,
3579 { },
3580 { { 0, 0xffffffff } },
3581 },
3582 {
3583 "ALU64_OR_K: 1 | 2 = 3",
3584 .u.insns_int = {
3585 BPF_LD_IMM64(R0, 1),
3586 BPF_ALU64_IMM(BPF_OR, R0, 2),
3587 BPF_EXIT_INSN(),
3588 },
3589 INTERNAL,
3590 { },
3591 { { 0, 3 } },
3592 },
3593 {
3594 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3595 .u.insns_int = {
3596 BPF_LD_IMM64(R0, 0),
3597 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3598 BPF_EXIT_INSN(),
3599 },
3600 INTERNAL,
3601 { },
3602 { { 0, 0xffffffff } },
3603 },
3604 {
3605 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3606 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003607 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3608 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003609 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3610 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3611 BPF_MOV32_IMM(R0, 2),
3612 BPF_EXIT_INSN(),
3613 BPF_MOV32_IMM(R0, 1),
3614 BPF_EXIT_INSN(),
3615 },
3616 INTERNAL,
3617 { },
3618 { { 0, 0x1 } },
3619 },
3620 {
3621 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3622 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003623 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3624 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003625 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3626 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3627 BPF_MOV32_IMM(R0, 2),
3628 BPF_EXIT_INSN(),
3629 BPF_MOV32_IMM(R0, 1),
3630 BPF_EXIT_INSN(),
3631 },
3632 INTERNAL,
3633 { },
3634 { { 0, 0x1 } },
3635 },
3636 {
3637 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3638 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003639 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3640 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003641 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3642 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3643 BPF_MOV32_IMM(R0, 2),
3644 BPF_EXIT_INSN(),
3645 BPF_MOV32_IMM(R0, 1),
3646 BPF_EXIT_INSN(),
3647 },
3648 INTERNAL,
3649 { },
3650 { { 0, 0x1 } },
3651 },
3652 /* BPF_ALU | BPF_XOR | BPF_X */
3653 {
3654 "ALU_XOR_X: 5 ^ 6 = 3",
3655 .u.insns_int = {
3656 BPF_LD_IMM64(R0, 5),
3657 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3658 BPF_ALU32_REG(BPF_XOR, R0, R1),
3659 BPF_EXIT_INSN(),
3660 },
3661 INTERNAL,
3662 { },
3663 { { 0, 3 } },
3664 },
3665 {
3666 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3667 .u.insns_int = {
3668 BPF_LD_IMM64(R0, 1),
3669 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3670 BPF_ALU32_REG(BPF_XOR, R0, R1),
3671 BPF_EXIT_INSN(),
3672 },
3673 INTERNAL,
3674 { },
3675 { { 0, 0xfffffffe } },
3676 },
3677 {
3678 "ALU64_XOR_X: 5 ^ 6 = 3",
3679 .u.insns_int = {
3680 BPF_LD_IMM64(R0, 5),
3681 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3682 BPF_ALU64_REG(BPF_XOR, R0, R1),
3683 BPF_EXIT_INSN(),
3684 },
3685 INTERNAL,
3686 { },
3687 { { 0, 3 } },
3688 },
3689 {
3690 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3691 .u.insns_int = {
3692 BPF_LD_IMM64(R0, 1),
3693 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3694 BPF_ALU64_REG(BPF_XOR, R0, R1),
3695 BPF_EXIT_INSN(),
3696 },
3697 INTERNAL,
3698 { },
3699 { { 0, 0xfffffffe } },
3700 },
3701 /* BPF_ALU | BPF_XOR | BPF_K */
3702 {
3703 "ALU_XOR_K: 5 ^ 6 = 3",
3704 .u.insns_int = {
3705 BPF_LD_IMM64(R0, 5),
3706 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3707 BPF_EXIT_INSN(),
3708 },
3709 INTERNAL,
3710 { },
3711 { { 0, 3 } },
3712 },
3713 {
3714 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3715 .u.insns_int = {
3716 BPF_LD_IMM64(R0, 1),
3717 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3718 BPF_EXIT_INSN(),
3719 },
3720 INTERNAL,
3721 { },
3722 { { 0, 0xfffffffe } },
3723 },
3724 {
3725 "ALU64_XOR_K: 5 ^ 6 = 3",
3726 .u.insns_int = {
3727 BPF_LD_IMM64(R0, 5),
3728 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3729 BPF_EXIT_INSN(),
3730 },
3731 INTERNAL,
3732 { },
3733 { { 0, 3 } },
3734 },
3735 {
3736 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3737 .u.insns_int = {
3738 BPF_LD_IMM64(R0, 1),
3739 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3740 BPF_EXIT_INSN(),
3741 },
3742 INTERNAL,
3743 { },
3744 { { 0, 0xfffffffe } },
3745 },
3746 {
3747 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3748 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003749 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3750 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003751 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3752 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3753 BPF_MOV32_IMM(R0, 2),
3754 BPF_EXIT_INSN(),
3755 BPF_MOV32_IMM(R0, 1),
3756 BPF_EXIT_INSN(),
3757 },
3758 INTERNAL,
3759 { },
3760 { { 0, 0x1 } },
3761 },
3762 {
3763 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3764 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003765 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3766 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003767 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3768 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3769 BPF_MOV32_IMM(R0, 2),
3770 BPF_EXIT_INSN(),
3771 BPF_MOV32_IMM(R0, 1),
3772 BPF_EXIT_INSN(),
3773 },
3774 INTERNAL,
3775 { },
3776 { { 0, 0x1 } },
3777 },
3778 {
3779 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3780 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003781 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3782 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003783 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3784 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3785 BPF_MOV32_IMM(R0, 2),
3786 BPF_EXIT_INSN(),
3787 BPF_MOV32_IMM(R0, 1),
3788 BPF_EXIT_INSN(),
3789 },
3790 INTERNAL,
3791 { },
3792 { { 0, 0x1 } },
3793 },
3794 /* BPF_ALU | BPF_LSH | BPF_X */
3795 {
3796 "ALU_LSH_X: 1 << 1 = 2",
3797 .u.insns_int = {
3798 BPF_LD_IMM64(R0, 1),
3799 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3800 BPF_ALU32_REG(BPF_LSH, R0, R1),
3801 BPF_EXIT_INSN(),
3802 },
3803 INTERNAL,
3804 { },
3805 { { 0, 2 } },
3806 },
3807 {
3808 "ALU_LSH_X: 1 << 31 = 0x80000000",
3809 .u.insns_int = {
3810 BPF_LD_IMM64(R0, 1),
3811 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3812 BPF_ALU32_REG(BPF_LSH, R0, R1),
3813 BPF_EXIT_INSN(),
3814 },
3815 INTERNAL,
3816 { },
3817 { { 0, 0x80000000 } },
3818 },
3819 {
3820 "ALU64_LSH_X: 1 << 1 = 2",
3821 .u.insns_int = {
3822 BPF_LD_IMM64(R0, 1),
3823 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3824 BPF_ALU64_REG(BPF_LSH, R0, R1),
3825 BPF_EXIT_INSN(),
3826 },
3827 INTERNAL,
3828 { },
3829 { { 0, 2 } },
3830 },
3831 {
3832 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3833 .u.insns_int = {
3834 BPF_LD_IMM64(R0, 1),
3835 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3836 BPF_ALU64_REG(BPF_LSH, R0, R1),
3837 BPF_EXIT_INSN(),
3838 },
3839 INTERNAL,
3840 { },
3841 { { 0, 0x80000000 } },
3842 },
3843 /* BPF_ALU | BPF_LSH | BPF_K */
3844 {
3845 "ALU_LSH_K: 1 << 1 = 2",
3846 .u.insns_int = {
3847 BPF_LD_IMM64(R0, 1),
3848 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3849 BPF_EXIT_INSN(),
3850 },
3851 INTERNAL,
3852 { },
3853 { { 0, 2 } },
3854 },
3855 {
3856 "ALU_LSH_K: 1 << 31 = 0x80000000",
3857 .u.insns_int = {
3858 BPF_LD_IMM64(R0, 1),
3859 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3860 BPF_EXIT_INSN(),
3861 },
3862 INTERNAL,
3863 { },
3864 { { 0, 0x80000000 } },
3865 },
3866 {
3867 "ALU64_LSH_K: 1 << 1 = 2",
3868 .u.insns_int = {
3869 BPF_LD_IMM64(R0, 1),
3870 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3871 BPF_EXIT_INSN(),
3872 },
3873 INTERNAL,
3874 { },
3875 { { 0, 2 } },
3876 },
3877 {
3878 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3879 .u.insns_int = {
3880 BPF_LD_IMM64(R0, 1),
3881 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3882 BPF_EXIT_INSN(),
3883 },
3884 INTERNAL,
3885 { },
3886 { { 0, 0x80000000 } },
3887 },
3888 /* BPF_ALU | BPF_RSH | BPF_X */
3889 {
3890 "ALU_RSH_X: 2 >> 1 = 1",
3891 .u.insns_int = {
3892 BPF_LD_IMM64(R0, 2),
3893 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3894 BPF_ALU32_REG(BPF_RSH, R0, R1),
3895 BPF_EXIT_INSN(),
3896 },
3897 INTERNAL,
3898 { },
3899 { { 0, 1 } },
3900 },
3901 {
3902 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3903 .u.insns_int = {
3904 BPF_LD_IMM64(R0, 0x80000000),
3905 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3906 BPF_ALU32_REG(BPF_RSH, R0, R1),
3907 BPF_EXIT_INSN(),
3908 },
3909 INTERNAL,
3910 { },
3911 { { 0, 1 } },
3912 },
3913 {
3914 "ALU64_RSH_X: 2 >> 1 = 1",
3915 .u.insns_int = {
3916 BPF_LD_IMM64(R0, 2),
3917 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3918 BPF_ALU64_REG(BPF_RSH, R0, R1),
3919 BPF_EXIT_INSN(),
3920 },
3921 INTERNAL,
3922 { },
3923 { { 0, 1 } },
3924 },
3925 {
3926 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3927 .u.insns_int = {
3928 BPF_LD_IMM64(R0, 0x80000000),
3929 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3930 BPF_ALU64_REG(BPF_RSH, R0, R1),
3931 BPF_EXIT_INSN(),
3932 },
3933 INTERNAL,
3934 { },
3935 { { 0, 1 } },
3936 },
3937 /* BPF_ALU | BPF_RSH | BPF_K */
3938 {
3939 "ALU_RSH_K: 2 >> 1 = 1",
3940 .u.insns_int = {
3941 BPF_LD_IMM64(R0, 2),
3942 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3943 BPF_EXIT_INSN(),
3944 },
3945 INTERNAL,
3946 { },
3947 { { 0, 1 } },
3948 },
3949 {
3950 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3951 .u.insns_int = {
3952 BPF_LD_IMM64(R0, 0x80000000),
3953 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3954 BPF_EXIT_INSN(),
3955 },
3956 INTERNAL,
3957 { },
3958 { { 0, 1 } },
3959 },
3960 {
3961 "ALU64_RSH_K: 2 >> 1 = 1",
3962 .u.insns_int = {
3963 BPF_LD_IMM64(R0, 2),
3964 BPF_ALU64_IMM(BPF_RSH, R0, 1),
3965 BPF_EXIT_INSN(),
3966 },
3967 INTERNAL,
3968 { },
3969 { { 0, 1 } },
3970 },
3971 {
3972 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3973 .u.insns_int = {
3974 BPF_LD_IMM64(R0, 0x80000000),
3975 BPF_ALU64_IMM(BPF_RSH, R0, 31),
3976 BPF_EXIT_INSN(),
3977 },
3978 INTERNAL,
3979 { },
3980 { { 0, 1 } },
3981 },
3982 /* BPF_ALU | BPF_ARSH | BPF_X */
3983 {
3984 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3985 .u.insns_int = {
3986 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3987 BPF_ALU32_IMM(BPF_MOV, R1, 40),
3988 BPF_ALU64_REG(BPF_ARSH, R0, R1),
3989 BPF_EXIT_INSN(),
3990 },
3991 INTERNAL,
3992 { },
3993 { { 0, 0xffff00ff } },
3994 },
3995 /* BPF_ALU | BPF_ARSH | BPF_K */
3996 {
3997 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3998 .u.insns_int = {
3999 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
4000 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
4001 BPF_EXIT_INSN(),
4002 },
4003 INTERNAL,
4004 { },
4005 { { 0, 0xffff00ff } },
4006 },
4007 /* BPF_ALU | BPF_NEG */
4008 {
4009 "ALU_NEG: -(3) = -3",
4010 .u.insns_int = {
4011 BPF_ALU32_IMM(BPF_MOV, R0, 3),
4012 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4013 BPF_EXIT_INSN(),
4014 },
4015 INTERNAL,
4016 { },
4017 { { 0, -3 } },
4018 },
4019 {
4020 "ALU_NEG: -(-3) = 3",
4021 .u.insns_int = {
4022 BPF_ALU32_IMM(BPF_MOV, R0, -3),
4023 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4024 BPF_EXIT_INSN(),
4025 },
4026 INTERNAL,
4027 { },
4028 { { 0, 3 } },
4029 },
4030 {
4031 "ALU64_NEG: -(3) = -3",
4032 .u.insns_int = {
4033 BPF_LD_IMM64(R0, 3),
4034 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4035 BPF_EXIT_INSN(),
4036 },
4037 INTERNAL,
4038 { },
4039 { { 0, -3 } },
4040 },
4041 {
4042 "ALU64_NEG: -(-3) = 3",
4043 .u.insns_int = {
4044 BPF_LD_IMM64(R0, -3),
4045 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4046 BPF_EXIT_INSN(),
4047 },
4048 INTERNAL,
4049 { },
4050 { { 0, 3 } },
4051 },
4052 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4053 {
4054 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4055 .u.insns_int = {
4056 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4057 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
4058 BPF_EXIT_INSN(),
4059 },
4060 INTERNAL,
4061 { },
4062 { { 0, cpu_to_be16(0xcdef) } },
4063 },
4064 {
4065 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4066 .u.insns_int = {
4067 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4068 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07004069 BPF_ALU64_REG(BPF_MOV, R1, R0),
4070 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4071 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07004072 BPF_EXIT_INSN(),
4073 },
4074 INTERNAL,
4075 { },
4076 { { 0, cpu_to_be32(0x89abcdef) } },
4077 },
4078 {
4079 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4080 .u.insns_int = {
4081 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4082 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
4083 BPF_EXIT_INSN(),
4084 },
4085 INTERNAL,
4086 { },
4087 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
4088 },
4089 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4090 {
4091 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4092 .u.insns_int = {
4093 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4094 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
4095 BPF_EXIT_INSN(),
4096 },
4097 INTERNAL,
4098 { },
4099 { { 0, cpu_to_le16(0xcdef) } },
4100 },
4101 {
4102 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4103 .u.insns_int = {
4104 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4105 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07004106 BPF_ALU64_REG(BPF_MOV, R1, R0),
4107 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4108 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07004109 BPF_EXIT_INSN(),
4110 },
4111 INTERNAL,
4112 { },
4113 { { 0, cpu_to_le32(0x89abcdef) } },
4114 },
4115 {
4116 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4117 .u.insns_int = {
4118 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4119 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
4120 BPF_EXIT_INSN(),
4121 },
4122 INTERNAL,
4123 { },
4124 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
4125 },
4126 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4127 {
4128 "ST_MEM_B: Store/Load byte: max negative",
4129 .u.insns_int = {
4130 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4131 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
4132 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4133 BPF_EXIT_INSN(),
4134 },
4135 INTERNAL,
4136 { },
4137 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004138 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004139 },
4140 {
4141 "ST_MEM_B: Store/Load byte: max positive",
4142 .u.insns_int = {
4143 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4144 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
4145 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4146 BPF_EXIT_INSN(),
4147 },
4148 INTERNAL,
4149 { },
4150 { { 0, 0x7f } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004151 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004152 },
4153 {
4154 "STX_MEM_B: Store/Load byte: max negative",
4155 .u.insns_int = {
4156 BPF_LD_IMM64(R0, 0),
4157 BPF_LD_IMM64(R1, 0xffLL),
4158 BPF_STX_MEM(BPF_B, R10, R1, -40),
4159 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4160 BPF_EXIT_INSN(),
4161 },
4162 INTERNAL,
4163 { },
4164 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004165 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004166 },
4167 {
4168 "ST_MEM_H: Store/Load half word: max negative",
4169 .u.insns_int = {
4170 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4171 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
4172 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4173 BPF_EXIT_INSN(),
4174 },
4175 INTERNAL,
4176 { },
4177 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004178 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004179 },
4180 {
4181 "ST_MEM_H: Store/Load half word: max positive",
4182 .u.insns_int = {
4183 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4184 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
4185 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4186 BPF_EXIT_INSN(),
4187 },
4188 INTERNAL,
4189 { },
4190 { { 0, 0x7fff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004191 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004192 },
4193 {
4194 "STX_MEM_H: Store/Load half word: max negative",
4195 .u.insns_int = {
4196 BPF_LD_IMM64(R0, 0),
4197 BPF_LD_IMM64(R1, 0xffffLL),
4198 BPF_STX_MEM(BPF_H, R10, R1, -40),
4199 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4200 BPF_EXIT_INSN(),
4201 },
4202 INTERNAL,
4203 { },
4204 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004205 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004206 },
4207 {
4208 "ST_MEM_W: Store/Load word: max negative",
4209 .u.insns_int = {
4210 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4211 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
4212 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4213 BPF_EXIT_INSN(),
4214 },
4215 INTERNAL,
4216 { },
4217 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004218 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004219 },
4220 {
4221 "ST_MEM_W: Store/Load word: max positive",
4222 .u.insns_int = {
4223 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4224 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
4225 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4226 BPF_EXIT_INSN(),
4227 },
4228 INTERNAL,
4229 { },
4230 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004231 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004232 },
4233 {
4234 "STX_MEM_W: Store/Load word: max negative",
4235 .u.insns_int = {
4236 BPF_LD_IMM64(R0, 0),
4237 BPF_LD_IMM64(R1, 0xffffffffLL),
4238 BPF_STX_MEM(BPF_W, R10, R1, -40),
4239 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4240 BPF_EXIT_INSN(),
4241 },
4242 INTERNAL,
4243 { },
4244 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004245 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004246 },
4247 {
4248 "ST_MEM_DW: Store/Load double word: max negative",
4249 .u.insns_int = {
4250 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4251 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4252 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4253 BPF_EXIT_INSN(),
4254 },
4255 INTERNAL,
4256 { },
4257 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004258 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004259 },
4260 {
4261 "ST_MEM_DW: Store/Load double word: max negative 2",
4262 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004263 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
4264 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004265 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4266 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
4267 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4268 BPF_MOV32_IMM(R0, 2),
4269 BPF_EXIT_INSN(),
4270 BPF_MOV32_IMM(R0, 1),
4271 BPF_EXIT_INSN(),
4272 },
4273 INTERNAL,
4274 { },
4275 { { 0, 0x1 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004276 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004277 },
4278 {
4279 "ST_MEM_DW: Store/Load double word: max positive",
4280 .u.insns_int = {
4281 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4282 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
4283 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4284 BPF_EXIT_INSN(),
4285 },
4286 INTERNAL,
4287 { },
4288 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004289 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004290 },
4291 {
4292 "STX_MEM_DW: Store/Load double word: max negative",
4293 .u.insns_int = {
4294 BPF_LD_IMM64(R0, 0),
4295 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4296 BPF_STX_MEM(BPF_W, R10, R1, -40),
4297 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4298 BPF_EXIT_INSN(),
4299 },
4300 INTERNAL,
4301 { },
4302 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004303 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004304 },
4305 /* BPF_STX | BPF_XADD | BPF_W/DW */
4306 {
4307 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4308 .u.insns_int = {
4309 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4310 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4311 BPF_STX_XADD(BPF_W, R10, R0, -40),
4312 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4313 BPF_EXIT_INSN(),
4314 },
4315 INTERNAL,
4316 { },
4317 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004318 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004319 },
4320 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004321 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4322 .u.insns_int = {
4323 BPF_ALU64_REG(BPF_MOV, R1, R10),
4324 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4325 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4326 BPF_STX_XADD(BPF_W, R10, R0, -40),
4327 BPF_ALU64_REG(BPF_MOV, R0, R10),
4328 BPF_ALU64_REG(BPF_SUB, R0, R1),
4329 BPF_EXIT_INSN(),
4330 },
4331 INTERNAL,
4332 { },
4333 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004334 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004335 },
4336 {
4337 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4338 .u.insns_int = {
4339 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4340 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
4341 BPF_STX_XADD(BPF_W, R10, R0, -40),
4342 BPF_EXIT_INSN(),
4343 },
4344 INTERNAL,
4345 { },
4346 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004347 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004348 },
4349 {
4350 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4351 { },
4352 INTERNAL,
4353 { },
4354 { { 0, 4134 } },
4355 .fill_helper = bpf_fill_stxw,
4356 },
4357 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004358 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4359 .u.insns_int = {
4360 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4361 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4362 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4363 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4364 BPF_EXIT_INSN(),
4365 },
4366 INTERNAL,
4367 { },
4368 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004369 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004370 },
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004371 {
4372 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4373 .u.insns_int = {
4374 BPF_ALU64_REG(BPF_MOV, R1, R10),
4375 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4376 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4377 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4378 BPF_ALU64_REG(BPF_MOV, R0, R10),
4379 BPF_ALU64_REG(BPF_SUB, R0, R1),
4380 BPF_EXIT_INSN(),
4381 },
4382 INTERNAL,
4383 { },
4384 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004385 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004386 },
4387 {
4388 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4389 .u.insns_int = {
4390 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4391 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
4392 BPF_STX_XADD(BPF_DW, R10, R0, -40),
4393 BPF_EXIT_INSN(),
4394 },
4395 INTERNAL,
4396 { },
4397 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004398 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004399 },
4400 {
4401 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4402 { },
4403 INTERNAL,
4404 { },
4405 { { 0, 4134 } },
4406 .fill_helper = bpf_fill_stxdw,
4407 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004408 /* BPF_JMP | BPF_EXIT */
4409 {
4410 "JMP_EXIT",
4411 .u.insns_int = {
4412 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4413 BPF_EXIT_INSN(),
4414 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4415 },
4416 INTERNAL,
4417 { },
4418 { { 0, 0x4711 } },
4419 },
4420 /* BPF_JMP | BPF_JA */
4421 {
4422 "JMP_JA: Unconditional jump: if (true) return 1",
4423 .u.insns_int = {
4424 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4425 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4426 BPF_EXIT_INSN(),
4427 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4428 BPF_EXIT_INSN(),
4429 },
4430 INTERNAL,
4431 { },
4432 { { 0, 1 } },
4433 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004434 /* BPF_JMP | BPF_JSLT | BPF_K */
4435 {
4436 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4437 .u.insns_int = {
4438 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4439 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4440 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4441 BPF_EXIT_INSN(),
4442 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4443 BPF_EXIT_INSN(),
4444 },
4445 INTERNAL,
4446 { },
4447 { { 0, 1 } },
4448 },
4449 {
4450 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4451 .u.insns_int = {
4452 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4453 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4454 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4455 BPF_EXIT_INSN(),
4456 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4457 BPF_EXIT_INSN(),
4458 },
4459 INTERNAL,
4460 { },
4461 { { 0, 1 } },
4462 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004463 /* BPF_JMP | BPF_JSGT | BPF_K */
4464 {
4465 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4466 .u.insns_int = {
4467 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4468 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4469 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4470 BPF_EXIT_INSN(),
4471 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4472 BPF_EXIT_INSN(),
4473 },
4474 INTERNAL,
4475 { },
4476 { { 0, 1 } },
4477 },
4478 {
4479 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4480 .u.insns_int = {
4481 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4482 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4483 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4484 BPF_EXIT_INSN(),
4485 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4486 BPF_EXIT_INSN(),
4487 },
4488 INTERNAL,
4489 { },
4490 { { 0, 1 } },
4491 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004492 /* BPF_JMP | BPF_JSLE | BPF_K */
4493 {
4494 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4495 .u.insns_int = {
4496 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4497 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4498 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
4499 BPF_EXIT_INSN(),
4500 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4501 BPF_EXIT_INSN(),
4502 },
4503 INTERNAL,
4504 { },
4505 { { 0, 1 } },
4506 },
4507 {
4508 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
4509 .u.insns_int = {
4510 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4511 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4512 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
4513 BPF_EXIT_INSN(),
4514 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4515 BPF_EXIT_INSN(),
4516 },
4517 INTERNAL,
4518 { },
4519 { { 0, 1 } },
4520 },
4521 {
4522 "JMP_JSLE_K: Signed jump: value walk 1",
4523 .u.insns_int = {
4524 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4525 BPF_LD_IMM64(R1, 3),
4526 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
4527 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4528 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
4529 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4530 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
4531 BPF_ALU64_IMM(BPF_SUB, R1, 1),
4532 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
4533 BPF_EXIT_INSN(), /* bad exit */
4534 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4535 BPF_EXIT_INSN(),
4536 },
4537 INTERNAL,
4538 { },
4539 { { 0, 1 } },
4540 },
4541 {
4542 "JMP_JSLE_K: Signed jump: value walk 2",
4543 .u.insns_int = {
4544 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4545 BPF_LD_IMM64(R1, 3),
4546 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
4547 BPF_ALU64_IMM(BPF_SUB, R1, 2),
4548 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
4549 BPF_ALU64_IMM(BPF_SUB, R1, 2),
4550 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
4551 BPF_EXIT_INSN(), /* bad exit */
4552 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4553 BPF_EXIT_INSN(),
4554 },
4555 INTERNAL,
4556 { },
4557 { { 0, 1 } },
4558 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004559 /* BPF_JMP | BPF_JSGE | BPF_K */
4560 {
4561 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
4562 .u.insns_int = {
4563 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4564 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4565 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
4566 BPF_EXIT_INSN(),
4567 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4568 BPF_EXIT_INSN(),
4569 },
4570 INTERNAL,
4571 { },
4572 { { 0, 1 } },
4573 },
4574 {
4575 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
4576 .u.insns_int = {
4577 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4578 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4579 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
4580 BPF_EXIT_INSN(),
4581 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4582 BPF_EXIT_INSN(),
4583 },
4584 INTERNAL,
4585 { },
4586 { { 0, 1 } },
4587 },
David Daney791caeb2017-05-24 16:35:49 -07004588 {
4589 "JMP_JSGE_K: Signed jump: value walk 1",
4590 .u.insns_int = {
4591 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4592 BPF_LD_IMM64(R1, -3),
4593 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
4594 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4595 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4596 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4597 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4598 BPF_ALU64_IMM(BPF_ADD, R1, 1),
4599 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4600 BPF_EXIT_INSN(), /* bad exit */
4601 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4602 BPF_EXIT_INSN(),
4603 },
4604 INTERNAL,
4605 { },
4606 { { 0, 1 } },
4607 },
4608 {
4609 "JMP_JSGE_K: Signed jump: value walk 2",
4610 .u.insns_int = {
4611 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4612 BPF_LD_IMM64(R1, -3),
4613 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
4614 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4615 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
4616 BPF_ALU64_IMM(BPF_ADD, R1, 2),
4617 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
4618 BPF_EXIT_INSN(), /* bad exit */
4619 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
4620 BPF_EXIT_INSN(),
4621 },
4622 INTERNAL,
4623 { },
4624 { { 0, 1 } },
4625 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004626 /* BPF_JMP | BPF_JGT | BPF_K */
4627 {
4628 "JMP_JGT_K: if (3 > 2) return 1",
4629 .u.insns_int = {
4630 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4631 BPF_LD_IMM64(R1, 3),
4632 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
4633 BPF_EXIT_INSN(),
4634 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4635 BPF_EXIT_INSN(),
4636 },
4637 INTERNAL,
4638 { },
4639 { { 0, 1 } },
4640 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05304641 {
4642 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
4643 .u.insns_int = {
4644 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4645 BPF_LD_IMM64(R1, -1),
4646 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
4647 BPF_EXIT_INSN(),
4648 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4649 BPF_EXIT_INSN(),
4650 },
4651 INTERNAL,
4652 { },
4653 { { 0, 1 } },
4654 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004655 /* BPF_JMP | BPF_JLT | BPF_K */
4656 {
4657 "JMP_JLT_K: if (2 < 3) return 1",
4658 .u.insns_int = {
4659 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4660 BPF_LD_IMM64(R1, 2),
4661 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
4662 BPF_EXIT_INSN(),
4663 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4664 BPF_EXIT_INSN(),
4665 },
4666 INTERNAL,
4667 { },
4668 { { 0, 1 } },
4669 },
4670 {
4671 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
4672 .u.insns_int = {
4673 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4674 BPF_LD_IMM64(R1, 1),
4675 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
4676 BPF_EXIT_INSN(),
4677 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4678 BPF_EXIT_INSN(),
4679 },
4680 INTERNAL,
4681 { },
4682 { { 0, 1 } },
4683 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004684 /* BPF_JMP | BPF_JGE | BPF_K */
4685 {
4686 "JMP_JGE_K: if (3 >= 2) return 1",
4687 .u.insns_int = {
4688 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4689 BPF_LD_IMM64(R1, 3),
4690 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
4691 BPF_EXIT_INSN(),
4692 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4693 BPF_EXIT_INSN(),
4694 },
4695 INTERNAL,
4696 { },
4697 { { 0, 1 } },
4698 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004699 /* BPF_JMP | BPF_JLE | BPF_K */
4700 {
4701 "JMP_JLE_K: if (2 <= 3) return 1",
4702 .u.insns_int = {
4703 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4704 BPF_LD_IMM64(R1, 2),
4705 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
4706 BPF_EXIT_INSN(),
4707 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4708 BPF_EXIT_INSN(),
4709 },
4710 INTERNAL,
4711 { },
4712 { { 0, 1 } },
4713 },
Michael Holzheufe593842015-05-22 08:36:40 -07004714 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
4715 {
4716 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
4717 .u.insns_int = {
4718 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4719 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4720 BPF_EXIT_INSN(),
4721 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4722 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
4723 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
4724 BPF_EXIT_INSN(),
4725 },
4726 INTERNAL,
4727 { },
4728 { { 0, 1 } },
4729 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004730 {
4731 "JMP_JGE_K: if (3 >= 3) return 1",
4732 .u.insns_int = {
4733 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4734 BPF_LD_IMM64(R1, 3),
4735 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
4736 BPF_EXIT_INSN(),
4737 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4738 BPF_EXIT_INSN(),
4739 },
4740 INTERNAL,
4741 { },
4742 { { 0, 1 } },
4743 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004744 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
4745 {
4746 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
4747 .u.insns_int = {
4748 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
4749 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
4750 BPF_EXIT_INSN(),
4751 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
4752 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
4753 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
4754 BPF_EXIT_INSN(),
4755 },
4756 INTERNAL,
4757 { },
4758 { { 0, 1 } },
4759 },
4760 {
4761 "JMP_JLE_K: if (3 <= 3) return 1",
4762 .u.insns_int = {
4763 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4764 BPF_LD_IMM64(R1, 3),
4765 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
4766 BPF_EXIT_INSN(),
4767 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4768 BPF_EXIT_INSN(),
4769 },
4770 INTERNAL,
4771 { },
4772 { { 0, 1 } },
4773 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004774 /* BPF_JMP | BPF_JNE | BPF_K */
4775 {
4776 "JMP_JNE_K: if (3 != 2) return 1",
4777 .u.insns_int = {
4778 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4779 BPF_LD_IMM64(R1, 3),
4780 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
4781 BPF_EXIT_INSN(),
4782 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4783 BPF_EXIT_INSN(),
4784 },
4785 INTERNAL,
4786 { },
4787 { { 0, 1 } },
4788 },
4789 /* BPF_JMP | BPF_JEQ | BPF_K */
4790 {
4791 "JMP_JEQ_K: if (3 == 3) return 1",
4792 .u.insns_int = {
4793 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4794 BPF_LD_IMM64(R1, 3),
4795 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
4796 BPF_EXIT_INSN(),
4797 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4798 BPF_EXIT_INSN(),
4799 },
4800 INTERNAL,
4801 { },
4802 { { 0, 1 } },
4803 },
4804 /* BPF_JMP | BPF_JSET | BPF_K */
4805 {
4806 "JMP_JSET_K: if (0x3 & 0x2) return 1",
4807 .u.insns_int = {
4808 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4809 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05304810 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07004811 BPF_EXIT_INSN(),
4812 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4813 BPF_EXIT_INSN(),
4814 },
4815 INTERNAL,
4816 { },
4817 { { 0, 1 } },
4818 },
4819 {
4820 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
4821 .u.insns_int = {
4822 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4823 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05304824 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07004825 BPF_EXIT_INSN(),
4826 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4827 BPF_EXIT_INSN(),
4828 },
4829 INTERNAL,
4830 { },
4831 { { 0, 1 } },
4832 },
4833 /* BPF_JMP | BPF_JSGT | BPF_X */
4834 {
4835 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
4836 .u.insns_int = {
4837 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4838 BPF_LD_IMM64(R1, -1),
4839 BPF_LD_IMM64(R2, -2),
4840 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4841 BPF_EXIT_INSN(),
4842 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4843 BPF_EXIT_INSN(),
4844 },
4845 INTERNAL,
4846 { },
4847 { { 0, 1 } },
4848 },
4849 {
4850 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
4851 .u.insns_int = {
4852 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4853 BPF_LD_IMM64(R1, -1),
4854 BPF_LD_IMM64(R2, -1),
4855 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
4856 BPF_EXIT_INSN(),
4857 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4858 BPF_EXIT_INSN(),
4859 },
4860 INTERNAL,
4861 { },
4862 { { 0, 1 } },
4863 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004864 /* BPF_JMP | BPF_JSLT | BPF_X */
4865 {
4866 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
4867 .u.insns_int = {
4868 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4869 BPF_LD_IMM64(R1, -1),
4870 BPF_LD_IMM64(R2, -2),
4871 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
4872 BPF_EXIT_INSN(),
4873 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4874 BPF_EXIT_INSN(),
4875 },
4876 INTERNAL,
4877 { },
4878 { { 0, 1 } },
4879 },
4880 {
4881 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
4882 .u.insns_int = {
4883 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4884 BPF_LD_IMM64(R1, -1),
4885 BPF_LD_IMM64(R2, -1),
4886 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
4887 BPF_EXIT_INSN(),
4888 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4889 BPF_EXIT_INSN(),
4890 },
4891 INTERNAL,
4892 { },
4893 { { 0, 1 } },
4894 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004895 /* BPF_JMP | BPF_JSGE | BPF_X */
4896 {
4897 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
4898 .u.insns_int = {
4899 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4900 BPF_LD_IMM64(R1, -1),
4901 BPF_LD_IMM64(R2, -2),
4902 BPF_JMP_REG(BPF_JSGE, R1, R2, 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 {
4912 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
4913 .u.insns_int = {
4914 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4915 BPF_LD_IMM64(R1, -1),
4916 BPF_LD_IMM64(R2, -1),
4917 BPF_JMP_REG(BPF_JSGE, R1, R2, 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 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004926 /* BPF_JMP | BPF_JSLE | BPF_X */
4927 {
4928 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
4929 .u.insns_int = {
4930 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4931 BPF_LD_IMM64(R1, -1),
4932 BPF_LD_IMM64(R2, -2),
4933 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
4934 BPF_EXIT_INSN(),
4935 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4936 BPF_EXIT_INSN(),
4937 },
4938 INTERNAL,
4939 { },
4940 { { 0, 1 } },
4941 },
4942 {
4943 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
4944 .u.insns_int = {
4945 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4946 BPF_LD_IMM64(R1, -1),
4947 BPF_LD_IMM64(R2, -1),
4948 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
4949 BPF_EXIT_INSN(),
4950 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4951 BPF_EXIT_INSN(),
4952 },
4953 INTERNAL,
4954 { },
4955 { { 0, 1 } },
4956 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004957 /* BPF_JMP | BPF_JGT | BPF_X */
4958 {
4959 "JMP_JGT_X: if (3 > 2) return 1",
4960 .u.insns_int = {
4961 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4962 BPF_LD_IMM64(R1, 3),
4963 BPF_LD_IMM64(R2, 2),
4964 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4965 BPF_EXIT_INSN(),
4966 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4967 BPF_EXIT_INSN(),
4968 },
4969 INTERNAL,
4970 { },
4971 { { 0, 1 } },
4972 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05304973 {
4974 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
4975 .u.insns_int = {
4976 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4977 BPF_LD_IMM64(R1, -1),
4978 BPF_LD_IMM64(R2, 1),
4979 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
4980 BPF_EXIT_INSN(),
4981 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4982 BPF_EXIT_INSN(),
4983 },
4984 INTERNAL,
4985 { },
4986 { { 0, 1 } },
4987 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004988 /* BPF_JMP | BPF_JLT | BPF_X */
4989 {
4990 "JMP_JLT_X: if (2 < 3) return 1",
4991 .u.insns_int = {
4992 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4993 BPF_LD_IMM64(R1, 3),
4994 BPF_LD_IMM64(R2, 2),
4995 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
4996 BPF_EXIT_INSN(),
4997 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4998 BPF_EXIT_INSN(),
4999 },
5000 INTERNAL,
5001 { },
5002 { { 0, 1 } },
5003 },
5004 {
5005 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5006 .u.insns_int = {
5007 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5008 BPF_LD_IMM64(R1, -1),
5009 BPF_LD_IMM64(R2, 1),
5010 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
5011 BPF_EXIT_INSN(),
5012 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5013 BPF_EXIT_INSN(),
5014 },
5015 INTERNAL,
5016 { },
5017 { { 0, 1 } },
5018 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005019 /* BPF_JMP | BPF_JGE | BPF_X */
5020 {
5021 "JMP_JGE_X: if (3 >= 2) return 1",
5022 .u.insns_int = {
5023 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5024 BPF_LD_IMM64(R1, 3),
5025 BPF_LD_IMM64(R2, 2),
5026 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5027 BPF_EXIT_INSN(),
5028 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5029 BPF_EXIT_INSN(),
5030 },
5031 INTERNAL,
5032 { },
5033 { { 0, 1 } },
5034 },
5035 {
5036 "JMP_JGE_X: if (3 >= 3) return 1",
5037 .u.insns_int = {
5038 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5039 BPF_LD_IMM64(R1, 3),
5040 BPF_LD_IMM64(R2, 3),
5041 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5042 BPF_EXIT_INSN(),
5043 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5044 BPF_EXIT_INSN(),
5045 },
5046 INTERNAL,
5047 { },
5048 { { 0, 1 } },
5049 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005050 /* BPF_JMP | BPF_JLE | BPF_X */
5051 {
5052 "JMP_JLE_X: if (2 <= 3) return 1",
5053 .u.insns_int = {
5054 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5055 BPF_LD_IMM64(R1, 3),
5056 BPF_LD_IMM64(R2, 2),
5057 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
5058 BPF_EXIT_INSN(),
5059 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5060 BPF_EXIT_INSN(),
5061 },
5062 INTERNAL,
5063 { },
5064 { { 0, 1 } },
5065 },
5066 {
5067 "JMP_JLE_X: if (3 <= 3) return 1",
5068 .u.insns_int = {
5069 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5070 BPF_LD_IMM64(R1, 3),
5071 BPF_LD_IMM64(R2, 3),
5072 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
5073 BPF_EXIT_INSN(),
5074 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5075 BPF_EXIT_INSN(),
5076 },
5077 INTERNAL,
5078 { },
5079 { { 0, 1 } },
5080 },
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005081 {
5082 /* Mainly testing JIT + imm64 here. */
5083 "JMP_JGE_X: ldimm64 test 1",
5084 .u.insns_int = {
5085 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5086 BPF_LD_IMM64(R1, 3),
5087 BPF_LD_IMM64(R2, 2),
5088 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005089 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5090 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005091 BPF_EXIT_INSN(),
5092 },
5093 INTERNAL,
5094 { },
5095 { { 0, 0xeeeeeeeeU } },
5096 },
5097 {
5098 "JMP_JGE_X: ldimm64 test 2",
5099 .u.insns_int = {
5100 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5101 BPF_LD_IMM64(R1, 3),
5102 BPF_LD_IMM64(R2, 2),
5103 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005104 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005105 BPF_EXIT_INSN(),
5106 },
5107 INTERNAL,
5108 { },
5109 { { 0, 0xffffffffU } },
5110 },
5111 {
5112 "JMP_JGE_X: ldimm64 test 3",
5113 .u.insns_int = {
5114 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5115 BPF_LD_IMM64(R1, 3),
5116 BPF_LD_IMM64(R2, 2),
5117 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005118 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5119 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005120 BPF_EXIT_INSN(),
5121 },
5122 INTERNAL,
5123 { },
5124 { { 0, 1 } },
5125 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005126 {
5127 "JMP_JLE_X: ldimm64 test 1",
5128 .u.insns_int = {
5129 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5130 BPF_LD_IMM64(R1, 3),
5131 BPF_LD_IMM64(R2, 2),
5132 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
5133 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5134 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5135 BPF_EXIT_INSN(),
5136 },
5137 INTERNAL,
5138 { },
5139 { { 0, 0xeeeeeeeeU } },
5140 },
5141 {
5142 "JMP_JLE_X: ldimm64 test 2",
5143 .u.insns_int = {
5144 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5145 BPF_LD_IMM64(R1, 3),
5146 BPF_LD_IMM64(R2, 2),
5147 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
5148 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5149 BPF_EXIT_INSN(),
5150 },
5151 INTERNAL,
5152 { },
5153 { { 0, 0xffffffffU } },
5154 },
5155 {
5156 "JMP_JLE_X: ldimm64 test 3",
5157 .u.insns_int = {
5158 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5159 BPF_LD_IMM64(R1, 3),
5160 BPF_LD_IMM64(R2, 2),
5161 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
5162 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5163 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5164 BPF_EXIT_INSN(),
5165 },
5166 INTERNAL,
5167 { },
5168 { { 0, 1 } },
5169 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005170 /* BPF_JMP | BPF_JNE | BPF_X */
5171 {
5172 "JMP_JNE_X: if (3 != 2) return 1",
5173 .u.insns_int = {
5174 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5175 BPF_LD_IMM64(R1, 3),
5176 BPF_LD_IMM64(R2, 2),
5177 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
5178 BPF_EXIT_INSN(),
5179 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5180 BPF_EXIT_INSN(),
5181 },
5182 INTERNAL,
5183 { },
5184 { { 0, 1 } },
5185 },
5186 /* BPF_JMP | BPF_JEQ | BPF_X */
5187 {
5188 "JMP_JEQ_X: if (3 == 3) return 1",
5189 .u.insns_int = {
5190 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5191 BPF_LD_IMM64(R1, 3),
5192 BPF_LD_IMM64(R2, 3),
5193 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
5194 BPF_EXIT_INSN(),
5195 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5196 BPF_EXIT_INSN(),
5197 },
5198 INTERNAL,
5199 { },
5200 { { 0, 1 } },
5201 },
5202 /* BPF_JMP | BPF_JSET | BPF_X */
5203 {
5204 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5205 .u.insns_int = {
5206 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5207 BPF_LD_IMM64(R1, 3),
5208 BPF_LD_IMM64(R2, 2),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05305209 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07005210 BPF_EXIT_INSN(),
5211 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5212 BPF_EXIT_INSN(),
5213 },
5214 INTERNAL,
5215 { },
5216 { { 0, 1 } },
5217 },
5218 {
5219 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5220 .u.insns_int = {
5221 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5222 BPF_LD_IMM64(R1, 3),
5223 BPF_LD_IMM64(R2, 0xffffffff),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05305224 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07005225 BPF_EXIT_INSN(),
5226 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5227 BPF_EXIT_INSN(),
5228 },
5229 INTERNAL,
5230 { },
5231 { { 0, 1 } },
5232 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005233 {
5234 "JMP_JA: Jump, gap, jump, ...",
5235 { },
5236 CLASSIC | FLAG_NO_DATA,
5237 { },
5238 { { 0, 0xababcbac } },
5239 .fill_helper = bpf_fill_ja,
5240 },
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005241 { /* Mainly checking JIT here. */
5242 "BPF_MAXINSNS: Maximum possible literals",
5243 { },
5244 CLASSIC | FLAG_NO_DATA,
5245 { },
5246 { { 0, 0xffffffff } },
5247 .fill_helper = bpf_fill_maxinsns1,
5248 },
5249 { /* Mainly checking JIT here. */
5250 "BPF_MAXINSNS: Single literal",
5251 { },
5252 CLASSIC | FLAG_NO_DATA,
5253 { },
5254 { { 0, 0xfefefefe } },
5255 .fill_helper = bpf_fill_maxinsns2,
5256 },
5257 { /* Mainly checking JIT here. */
5258 "BPF_MAXINSNS: Run/add until end",
5259 { },
5260 CLASSIC | FLAG_NO_DATA,
5261 { },
5262 { { 0, 0x947bf368 } },
5263 .fill_helper = bpf_fill_maxinsns3,
5264 },
5265 {
5266 "BPF_MAXINSNS: Too many instructions",
5267 { },
5268 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5269 { },
5270 { },
5271 .fill_helper = bpf_fill_maxinsns4,
Yonghong Song09584b42018-02-02 22:37:15 -08005272 .expected_errcode = -EINVAL,
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005273 },
5274 { /* Mainly checking JIT here. */
5275 "BPF_MAXINSNS: Very long jump",
5276 { },
5277 CLASSIC | FLAG_NO_DATA,
5278 { },
5279 { { 0, 0xabababab } },
5280 .fill_helper = bpf_fill_maxinsns5,
5281 },
5282 { /* Mainly checking JIT here. */
5283 "BPF_MAXINSNS: Ctx heavy transformations",
5284 { },
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005285#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
5286 CLASSIC | FLAG_EXPECTED_FAIL,
5287#else
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005288 CLASSIC,
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005289#endif
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005290 { },
5291 {
5292 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
5293 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
5294 },
5295 .fill_helper = bpf_fill_maxinsns6,
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005296 .expected_errcode = -ENOTSUPP,
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005297 },
5298 { /* Mainly checking JIT here. */
5299 "BPF_MAXINSNS: Call heavy transformations",
5300 { },
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005301#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
5302 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5303#else
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005304 CLASSIC | FLAG_NO_DATA,
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005305#endif
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005306 { },
5307 { { 1, 0 }, { 10, 0 } },
5308 .fill_helper = bpf_fill_maxinsns7,
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005309 .expected_errcode = -ENOTSUPP,
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005310 },
5311 { /* Mainly checking JIT here. */
5312 "BPF_MAXINSNS: Jump heavy test",
5313 { },
5314 CLASSIC | FLAG_NO_DATA,
5315 { },
5316 { { 0, 0xffffffff } },
5317 .fill_helper = bpf_fill_maxinsns8,
5318 },
Daniel Borkmann3b529602015-05-23 01:10:07 +02005319 { /* Mainly checking JIT here. */
5320 "BPF_MAXINSNS: Very long jump backwards",
5321 { },
5322 INTERNAL | FLAG_NO_DATA,
5323 { },
5324 { { 0, 0xcbababab } },
5325 .fill_helper = bpf_fill_maxinsns9,
5326 },
5327 { /* Mainly checking JIT here. */
5328 "BPF_MAXINSNS: Edge hopping nuthouse",
5329 { },
5330 INTERNAL | FLAG_NO_DATA,
5331 { },
5332 { { 0, 0xabababac } },
5333 .fill_helper = bpf_fill_maxinsns10,
5334 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005335 {
5336 "BPF_MAXINSNS: Jump, gap, jump, ...",
5337 { },
Thadeu Lima de Souza Cascardo52fda362018-03-20 09:58:51 -03005338#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_X86)
Yonghong Song09584b42018-02-02 22:37:15 -08005339 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5340#else
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005341 CLASSIC | FLAG_NO_DATA,
Yonghong Song09584b42018-02-02 22:37:15 -08005342#endif
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005343 { },
5344 { { 0, 0xababcbac } },
5345 .fill_helper = bpf_fill_maxinsns11,
Yonghong Song09584b42018-02-02 22:37:15 -08005346 .expected_errcode = -ENOTSUPP,
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005347 },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005348 {
Daniel Borkmannbe088152018-06-02 23:06:32 +02005349 "BPF_MAXINSNS: jump over MSH",
5350 { },
5351 CLASSIC | FLAG_EXPECTED_FAIL,
5352 { 0xfa, 0xfb, 0xfc, 0xfd, },
5353 { { 4, 0xabababab } },
5354 .fill_helper = bpf_fill_maxinsns12,
5355 .expected_errcode = -EINVAL,
5356 },
5357 {
5358 "BPF_MAXINSNS: exec all MSH",
5359 { },
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005360#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
5361 CLASSIC | FLAG_EXPECTED_FAIL,
5362#else
Daniel Borkmannbe088152018-06-02 23:06:32 +02005363 CLASSIC,
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005364#endif
Daniel Borkmannbe088152018-06-02 23:06:32 +02005365 { 0xfa, 0xfb, 0xfc, 0xfd, },
5366 { { 4, 0xababab83 } },
5367 .fill_helper = bpf_fill_maxinsns13,
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005368 .expected_errcode = -ENOTSUPP,
Daniel Borkmannbe088152018-06-02 23:06:32 +02005369 },
5370 {
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005371 "BPF_MAXINSNS: ld_abs+get_processor_id",
5372 { },
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005373#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
5374 CLASSIC | FLAG_EXPECTED_FAIL,
5375#else
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005376 CLASSIC,
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005377#endif
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005378 { },
5379 { { 1, 0xbee } },
5380 .fill_helper = bpf_fill_ld_abs_get_processor_id,
Kleber Sacilotto de Souza3203c902018-06-27 17:19:21 +02005381 .expected_errcode = -ENOTSUPP,
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005382 },
Nicolas Schichan2cf1ad72015-08-04 15:19:09 +02005383 /*
5384 * LD_IND / LD_ABS on fragmented SKBs
5385 */
5386 {
5387 "LD_IND byte frag",
5388 .u.insns = {
5389 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5390 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
5391 BPF_STMT(BPF_RET | BPF_A, 0x0),
5392 },
5393 CLASSIC | FLAG_SKB_FRAG,
5394 { },
5395 { {0x40, 0x42} },
5396 .frag_data = {
5397 0x42, 0x00, 0x00, 0x00,
5398 0x43, 0x44, 0x00, 0x00,
5399 0x21, 0x07, 0x19, 0x83,
5400 },
5401 },
5402 {
5403 "LD_IND halfword frag",
5404 .u.insns = {
5405 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5406 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
5407 BPF_STMT(BPF_RET | BPF_A, 0x0),
5408 },
5409 CLASSIC | FLAG_SKB_FRAG,
5410 { },
5411 { {0x40, 0x4344} },
5412 .frag_data = {
5413 0x42, 0x00, 0x00, 0x00,
5414 0x43, 0x44, 0x00, 0x00,
5415 0x21, 0x07, 0x19, 0x83,
5416 },
5417 },
5418 {
5419 "LD_IND word frag",
5420 .u.insns = {
5421 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5422 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
5423 BPF_STMT(BPF_RET | BPF_A, 0x0),
5424 },
5425 CLASSIC | FLAG_SKB_FRAG,
5426 { },
5427 { {0x40, 0x21071983} },
5428 .frag_data = {
5429 0x42, 0x00, 0x00, 0x00,
5430 0x43, 0x44, 0x00, 0x00,
5431 0x21, 0x07, 0x19, 0x83,
5432 },
5433 },
5434 {
5435 "LD_IND halfword mixed head/frag",
5436 .u.insns = {
5437 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5438 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5439 BPF_STMT(BPF_RET | BPF_A, 0x0),
5440 },
5441 CLASSIC | FLAG_SKB_FRAG,
5442 { [0x3e] = 0x25, [0x3f] = 0x05, },
5443 { {0x40, 0x0519} },
5444 .frag_data = { 0x19, 0x82 },
5445 },
5446 {
5447 "LD_IND word mixed head/frag",
5448 .u.insns = {
5449 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5450 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5451 BPF_STMT(BPF_RET | BPF_A, 0x0),
5452 },
5453 CLASSIC | FLAG_SKB_FRAG,
5454 { [0x3e] = 0x25, [0x3f] = 0x05, },
5455 { {0x40, 0x25051982} },
5456 .frag_data = { 0x19, 0x82 },
5457 },
5458 {
5459 "LD_ABS byte frag",
5460 .u.insns = {
5461 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
5462 BPF_STMT(BPF_RET | BPF_A, 0x0),
5463 },
5464 CLASSIC | FLAG_SKB_FRAG,
5465 { },
5466 { {0x40, 0x42} },
5467 .frag_data = {
5468 0x42, 0x00, 0x00, 0x00,
5469 0x43, 0x44, 0x00, 0x00,
5470 0x21, 0x07, 0x19, 0x83,
5471 },
5472 },
5473 {
5474 "LD_ABS halfword frag",
5475 .u.insns = {
5476 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
5477 BPF_STMT(BPF_RET | BPF_A, 0x0),
5478 },
5479 CLASSIC | FLAG_SKB_FRAG,
5480 { },
5481 { {0x40, 0x4344} },
5482 .frag_data = {
5483 0x42, 0x00, 0x00, 0x00,
5484 0x43, 0x44, 0x00, 0x00,
5485 0x21, 0x07, 0x19, 0x83,
5486 },
5487 },
5488 {
5489 "LD_ABS word frag",
5490 .u.insns = {
5491 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
5492 BPF_STMT(BPF_RET | BPF_A, 0x0),
5493 },
5494 CLASSIC | FLAG_SKB_FRAG,
5495 { },
5496 { {0x40, 0x21071983} },
5497 .frag_data = {
5498 0x42, 0x00, 0x00, 0x00,
5499 0x43, 0x44, 0x00, 0x00,
5500 0x21, 0x07, 0x19, 0x83,
5501 },
5502 },
5503 {
5504 "LD_ABS halfword mixed head/frag",
5505 .u.insns = {
5506 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
5507 BPF_STMT(BPF_RET | BPF_A, 0x0),
5508 },
5509 CLASSIC | FLAG_SKB_FRAG,
5510 { [0x3e] = 0x25, [0x3f] = 0x05, },
5511 { {0x40, 0x0519} },
5512 .frag_data = { 0x19, 0x82 },
5513 },
5514 {
5515 "LD_ABS word mixed head/frag",
5516 .u.insns = {
5517 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
5518 BPF_STMT(BPF_RET | BPF_A, 0x0),
5519 },
5520 CLASSIC | FLAG_SKB_FRAG,
5521 { [0x3e] = 0x25, [0x3f] = 0x05, },
5522 { {0x40, 0x25051982} },
5523 .frag_data = { 0x19, 0x82 },
5524 },
Nicolas Schichan08fcb082015-08-04 15:19:11 +02005525 /*
5526 * LD_IND / LD_ABS on non fragmented SKBs
5527 */
5528 {
5529 /*
5530 * this tests that the JIT/interpreter correctly resets X
5531 * before using it in an LD_IND instruction.
5532 */
5533 "LD_IND byte default X",
5534 .u.insns = {
5535 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5536 BPF_STMT(BPF_RET | BPF_A, 0x0),
5537 },
5538 CLASSIC,
5539 { [0x1] = 0x42 },
5540 { {0x40, 0x42 } },
5541 },
5542 {
5543 "LD_IND byte positive offset",
5544 .u.insns = {
5545 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5546 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5547 BPF_STMT(BPF_RET | BPF_A, 0x0),
5548 },
5549 CLASSIC,
5550 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5551 { {0x40, 0x82 } },
5552 },
5553 {
5554 "LD_IND byte negative offset",
5555 .u.insns = {
5556 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5557 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
5558 BPF_STMT(BPF_RET | BPF_A, 0x0),
5559 },
5560 CLASSIC,
5561 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5562 { {0x40, 0x05 } },
5563 },
5564 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02005565 "LD_IND byte positive offset, all ff",
5566 .u.insns = {
5567 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5568 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5569 BPF_STMT(BPF_RET | BPF_A, 0x0),
5570 },
5571 CLASSIC,
5572 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5573 { {0x40, 0xff } },
5574 },
5575 {
5576 "LD_IND byte positive offset, out of bounds",
5577 .u.insns = {
5578 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5579 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
5580 BPF_STMT(BPF_RET | BPF_A, 0x0),
5581 },
5582 CLASSIC,
5583 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5584 { {0x3f, 0 }, },
5585 },
5586 {
5587 "LD_IND byte negative offset, out of bounds",
5588 .u.insns = {
5589 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5590 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f),
5591 BPF_STMT(BPF_RET | BPF_A, 0x0),
5592 },
5593 CLASSIC,
5594 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5595 { {0x3f, 0 } },
5596 },
5597 {
5598 "LD_IND byte negative offset, multiple calls",
5599 .u.insns = {
5600 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
5601 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1),
5602 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2),
5603 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3),
5604 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4),
5605 BPF_STMT(BPF_RET | BPF_A, 0x0),
5606 },
5607 CLASSIC,
5608 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5609 { {0x40, 0x82 }, },
5610 },
5611 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02005612 "LD_IND halfword positive offset",
5613 .u.insns = {
5614 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5615 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
5616 BPF_STMT(BPF_RET | BPF_A, 0x0),
5617 },
5618 CLASSIC,
5619 {
5620 [0x1c] = 0xaa, [0x1d] = 0x55,
5621 [0x1e] = 0xbb, [0x1f] = 0x66,
5622 [0x20] = 0xcc, [0x21] = 0x77,
5623 [0x22] = 0xdd, [0x23] = 0x88,
5624 },
5625 { {0x40, 0xdd88 } },
5626 },
5627 {
5628 "LD_IND halfword negative offset",
5629 .u.insns = {
5630 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5631 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
5632 BPF_STMT(BPF_RET | BPF_A, 0x0),
5633 },
5634 CLASSIC,
5635 {
5636 [0x1c] = 0xaa, [0x1d] = 0x55,
5637 [0x1e] = 0xbb, [0x1f] = 0x66,
5638 [0x20] = 0xcc, [0x21] = 0x77,
5639 [0x22] = 0xdd, [0x23] = 0x88,
5640 },
5641 { {0x40, 0xbb66 } },
5642 },
5643 {
5644 "LD_IND halfword unaligned",
5645 .u.insns = {
5646 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5647 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5648 BPF_STMT(BPF_RET | BPF_A, 0x0),
5649 },
5650 CLASSIC,
5651 {
5652 [0x1c] = 0xaa, [0x1d] = 0x55,
5653 [0x1e] = 0xbb, [0x1f] = 0x66,
5654 [0x20] = 0xcc, [0x21] = 0x77,
5655 [0x22] = 0xdd, [0x23] = 0x88,
5656 },
5657 { {0x40, 0x66cc } },
5658 },
5659 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02005660 "LD_IND halfword positive offset, all ff",
5661 .u.insns = {
5662 BPF_STMT(BPF_LDX | BPF_IMM, 0x3d),
5663 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
5664 BPF_STMT(BPF_RET | BPF_A, 0x0),
5665 },
5666 CLASSIC,
5667 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5668 { {0x40, 0xffff } },
5669 },
5670 {
5671 "LD_IND halfword positive offset, out of bounds",
5672 .u.insns = {
5673 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5674 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
5675 BPF_STMT(BPF_RET | BPF_A, 0x0),
5676 },
5677 CLASSIC,
5678 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5679 { {0x3f, 0 }, },
5680 },
5681 {
5682 "LD_IND halfword negative offset, out of bounds",
5683 .u.insns = {
5684 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5685 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f),
5686 BPF_STMT(BPF_RET | BPF_A, 0x0),
5687 },
5688 CLASSIC,
5689 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5690 { {0x3f, 0 } },
5691 },
5692 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02005693 "LD_IND word positive offset",
5694 .u.insns = {
5695 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5696 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
5697 BPF_STMT(BPF_RET | BPF_A, 0x0),
5698 },
5699 CLASSIC,
5700 {
5701 [0x1c] = 0xaa, [0x1d] = 0x55,
5702 [0x1e] = 0xbb, [0x1f] = 0x66,
5703 [0x20] = 0xcc, [0x21] = 0x77,
5704 [0x22] = 0xdd, [0x23] = 0x88,
5705 [0x24] = 0xee, [0x25] = 0x99,
5706 [0x26] = 0xff, [0x27] = 0xaa,
5707 },
5708 { {0x40, 0xee99ffaa } },
5709 },
5710 {
5711 "LD_IND word negative offset",
5712 .u.insns = {
5713 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5714 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
5715 BPF_STMT(BPF_RET | BPF_A, 0x0),
5716 },
5717 CLASSIC,
5718 {
5719 [0x1c] = 0xaa, [0x1d] = 0x55,
5720 [0x1e] = 0xbb, [0x1f] = 0x66,
5721 [0x20] = 0xcc, [0x21] = 0x77,
5722 [0x22] = 0xdd, [0x23] = 0x88,
5723 [0x24] = 0xee, [0x25] = 0x99,
5724 [0x26] = 0xff, [0x27] = 0xaa,
5725 },
5726 { {0x40, 0xaa55bb66 } },
5727 },
5728 {
5729 "LD_IND word unaligned (addr & 3 == 2)",
5730 .u.insns = {
5731 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5732 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5733 BPF_STMT(BPF_RET | BPF_A, 0x0),
5734 },
5735 CLASSIC,
5736 {
5737 [0x1c] = 0xaa, [0x1d] = 0x55,
5738 [0x1e] = 0xbb, [0x1f] = 0x66,
5739 [0x20] = 0xcc, [0x21] = 0x77,
5740 [0x22] = 0xdd, [0x23] = 0x88,
5741 [0x24] = 0xee, [0x25] = 0x99,
5742 [0x26] = 0xff, [0x27] = 0xaa,
5743 },
5744 { {0x40, 0xbb66cc77 } },
5745 },
5746 {
5747 "LD_IND word unaligned (addr & 3 == 1)",
5748 .u.insns = {
5749 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5750 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
5751 BPF_STMT(BPF_RET | BPF_A, 0x0),
5752 },
5753 CLASSIC,
5754 {
5755 [0x1c] = 0xaa, [0x1d] = 0x55,
5756 [0x1e] = 0xbb, [0x1f] = 0x66,
5757 [0x20] = 0xcc, [0x21] = 0x77,
5758 [0x22] = 0xdd, [0x23] = 0x88,
5759 [0x24] = 0xee, [0x25] = 0x99,
5760 [0x26] = 0xff, [0x27] = 0xaa,
5761 },
5762 { {0x40, 0x55bb66cc } },
5763 },
5764 {
5765 "LD_IND word unaligned (addr & 3 == 3)",
5766 .u.insns = {
5767 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
5768 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
5769 BPF_STMT(BPF_RET | BPF_A, 0x0),
5770 },
5771 CLASSIC,
5772 {
5773 [0x1c] = 0xaa, [0x1d] = 0x55,
5774 [0x1e] = 0xbb, [0x1f] = 0x66,
5775 [0x20] = 0xcc, [0x21] = 0x77,
5776 [0x22] = 0xdd, [0x23] = 0x88,
5777 [0x24] = 0xee, [0x25] = 0x99,
5778 [0x26] = 0xff, [0x27] = 0xaa,
5779 },
5780 { {0x40, 0x66cc77dd } },
5781 },
5782 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02005783 "LD_IND word positive offset, all ff",
5784 .u.insns = {
5785 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
5786 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
5787 BPF_STMT(BPF_RET | BPF_A, 0x0),
5788 },
5789 CLASSIC,
5790 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5791 { {0x40, 0xffffffff } },
5792 },
5793 {
5794 "LD_IND word positive offset, out of bounds",
5795 .u.insns = {
5796 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5797 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
5798 BPF_STMT(BPF_RET | BPF_A, 0x0),
5799 },
5800 CLASSIC,
5801 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5802 { {0x3f, 0 }, },
5803 },
5804 {
5805 "LD_IND word negative offset, out of bounds",
5806 .u.insns = {
5807 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
5808 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f),
5809 BPF_STMT(BPF_RET | BPF_A, 0x0),
5810 },
5811 CLASSIC,
5812 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5813 { {0x3f, 0 } },
5814 },
5815 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02005816 "LD_ABS byte",
5817 .u.insns = {
5818 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
5819 BPF_STMT(BPF_RET | BPF_A, 0x0),
5820 },
5821 CLASSIC,
5822 {
5823 [0x1c] = 0xaa, [0x1d] = 0x55,
5824 [0x1e] = 0xbb, [0x1f] = 0x66,
5825 [0x20] = 0xcc, [0x21] = 0x77,
5826 [0x22] = 0xdd, [0x23] = 0x88,
5827 [0x24] = 0xee, [0x25] = 0x99,
5828 [0x26] = 0xff, [0x27] = 0xaa,
5829 },
5830 { {0x40, 0xcc } },
5831 },
5832 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02005833 "LD_ABS byte positive offset, all ff",
5834 .u.insns = {
5835 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
5836 BPF_STMT(BPF_RET | BPF_A, 0x0),
5837 },
5838 CLASSIC,
5839 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5840 { {0x40, 0xff } },
5841 },
5842 {
5843 "LD_ABS byte positive offset, out of bounds",
5844 .u.insns = {
5845 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
5846 BPF_STMT(BPF_RET | BPF_A, 0x0),
5847 },
5848 CLASSIC,
5849 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5850 { {0x3f, 0 }, },
5851 },
5852 {
5853 "LD_ABS byte negative offset, out of bounds load",
5854 .u.insns = {
5855 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1),
5856 BPF_STMT(BPF_RET | BPF_A, 0x0),
5857 },
5858 CLASSIC | FLAG_EXPECTED_FAIL,
5859 .expected_errcode = -EINVAL,
5860 },
5861 {
5862 "LD_ABS byte negative offset, in bounds",
5863 .u.insns = {
5864 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
5865 BPF_STMT(BPF_RET | BPF_A, 0x0),
5866 },
5867 CLASSIC,
5868 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5869 { {0x40, 0x82 }, },
5870 },
5871 {
5872 "LD_ABS byte negative offset, out of bounds",
5873 .u.insns = {
5874 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
5875 BPF_STMT(BPF_RET | BPF_A, 0x0),
5876 },
5877 CLASSIC,
5878 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5879 { {0x3f, 0 }, },
5880 },
5881 {
5882 "LD_ABS byte negative offset, multiple calls",
5883 .u.insns = {
5884 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c),
5885 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d),
5886 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e),
5887 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
5888 BPF_STMT(BPF_RET | BPF_A, 0x0),
5889 },
5890 CLASSIC,
5891 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5892 { {0x40, 0x82 }, },
5893 },
5894 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02005895 "LD_ABS halfword",
5896 .u.insns = {
5897 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
5898 BPF_STMT(BPF_RET | BPF_A, 0x0),
5899 },
5900 CLASSIC,
5901 {
5902 [0x1c] = 0xaa, [0x1d] = 0x55,
5903 [0x1e] = 0xbb, [0x1f] = 0x66,
5904 [0x20] = 0xcc, [0x21] = 0x77,
5905 [0x22] = 0xdd, [0x23] = 0x88,
5906 [0x24] = 0xee, [0x25] = 0x99,
5907 [0x26] = 0xff, [0x27] = 0xaa,
5908 },
5909 { {0x40, 0xdd88 } },
5910 },
5911 {
5912 "LD_ABS halfword unaligned",
5913 .u.insns = {
5914 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
5915 BPF_STMT(BPF_RET | BPF_A, 0x0),
5916 },
5917 CLASSIC,
5918 {
5919 [0x1c] = 0xaa, [0x1d] = 0x55,
5920 [0x1e] = 0xbb, [0x1f] = 0x66,
5921 [0x20] = 0xcc, [0x21] = 0x77,
5922 [0x22] = 0xdd, [0x23] = 0x88,
5923 [0x24] = 0xee, [0x25] = 0x99,
5924 [0x26] = 0xff, [0x27] = 0xaa,
5925 },
5926 { {0x40, 0x99ff } },
5927 },
5928 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02005929 "LD_ABS halfword positive offset, all ff",
5930 .u.insns = {
5931 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e),
5932 BPF_STMT(BPF_RET | BPF_A, 0x0),
5933 },
5934 CLASSIC,
5935 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
5936 { {0x40, 0xffff } },
5937 },
5938 {
5939 "LD_ABS halfword positive offset, out of bounds",
5940 .u.insns = {
5941 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
5942 BPF_STMT(BPF_RET | BPF_A, 0x0),
5943 },
5944 CLASSIC,
5945 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5946 { {0x3f, 0 }, },
5947 },
5948 {
5949 "LD_ABS halfword negative offset, out of bounds load",
5950 .u.insns = {
5951 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1),
5952 BPF_STMT(BPF_RET | BPF_A, 0x0),
5953 },
5954 CLASSIC | FLAG_EXPECTED_FAIL,
5955 .expected_errcode = -EINVAL,
5956 },
5957 {
5958 "LD_ABS halfword negative offset, in bounds",
5959 .u.insns = {
5960 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
5961 BPF_STMT(BPF_RET | BPF_A, 0x0),
5962 },
5963 CLASSIC,
5964 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5965 { {0x40, 0x1982 }, },
5966 },
5967 {
5968 "LD_ABS halfword negative offset, out of bounds",
5969 .u.insns = {
5970 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
5971 BPF_STMT(BPF_RET | BPF_A, 0x0),
5972 },
5973 CLASSIC,
5974 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
5975 { {0x3f, 0 }, },
5976 },
5977 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02005978 "LD_ABS word",
5979 .u.insns = {
5980 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
5981 BPF_STMT(BPF_RET | BPF_A, 0x0),
5982 },
5983 CLASSIC,
5984 {
5985 [0x1c] = 0xaa, [0x1d] = 0x55,
5986 [0x1e] = 0xbb, [0x1f] = 0x66,
5987 [0x20] = 0xcc, [0x21] = 0x77,
5988 [0x22] = 0xdd, [0x23] = 0x88,
5989 [0x24] = 0xee, [0x25] = 0x99,
5990 [0x26] = 0xff, [0x27] = 0xaa,
5991 },
5992 { {0x40, 0xaa55bb66 } },
5993 },
5994 {
5995 "LD_ABS word unaligned (addr & 3 == 2)",
5996 .u.insns = {
5997 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
5998 BPF_STMT(BPF_RET | BPF_A, 0x0),
5999 },
6000 CLASSIC,
6001 {
6002 [0x1c] = 0xaa, [0x1d] = 0x55,
6003 [0x1e] = 0xbb, [0x1f] = 0x66,
6004 [0x20] = 0xcc, [0x21] = 0x77,
6005 [0x22] = 0xdd, [0x23] = 0x88,
6006 [0x24] = 0xee, [0x25] = 0x99,
6007 [0x26] = 0xff, [0x27] = 0xaa,
6008 },
6009 { {0x40, 0xdd88ee99 } },
6010 },
6011 {
6012 "LD_ABS word unaligned (addr & 3 == 1)",
6013 .u.insns = {
6014 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
6015 BPF_STMT(BPF_RET | BPF_A, 0x0),
6016 },
6017 CLASSIC,
6018 {
6019 [0x1c] = 0xaa, [0x1d] = 0x55,
6020 [0x1e] = 0xbb, [0x1f] = 0x66,
6021 [0x20] = 0xcc, [0x21] = 0x77,
6022 [0x22] = 0xdd, [0x23] = 0x88,
6023 [0x24] = 0xee, [0x25] = 0x99,
6024 [0x26] = 0xff, [0x27] = 0xaa,
6025 },
6026 { {0x40, 0x77dd88ee } },
6027 },
6028 {
6029 "LD_ABS word unaligned (addr & 3 == 3)",
6030 .u.insns = {
6031 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
6032 BPF_STMT(BPF_RET | BPF_A, 0x0),
6033 },
6034 CLASSIC,
6035 {
6036 [0x1c] = 0xaa, [0x1d] = 0x55,
6037 [0x1e] = 0xbb, [0x1f] = 0x66,
6038 [0x20] = 0xcc, [0x21] = 0x77,
6039 [0x22] = 0xdd, [0x23] = 0x88,
6040 [0x24] = 0xee, [0x25] = 0x99,
6041 [0x26] = 0xff, [0x27] = 0xaa,
6042 },
6043 { {0x40, 0x88ee99ff } },
6044 },
Daniel Borkmann93731ef2018-05-04 01:08:13 +02006045 {
6046 "LD_ABS word positive offset, all ff",
6047 .u.insns = {
6048 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c),
6049 BPF_STMT(BPF_RET | BPF_A, 0x0),
6050 },
6051 CLASSIC,
6052 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6053 { {0x40, 0xffffffff } },
6054 },
6055 {
6056 "LD_ABS word positive offset, out of bounds",
6057 .u.insns = {
6058 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f),
6059 BPF_STMT(BPF_RET | BPF_A, 0x0),
6060 },
6061 CLASSIC,
6062 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6063 { {0x3f, 0 }, },
6064 },
6065 {
6066 "LD_ABS word negative offset, out of bounds load",
6067 .u.insns = {
6068 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1),
6069 BPF_STMT(BPF_RET | BPF_A, 0x0),
6070 },
6071 CLASSIC | FLAG_EXPECTED_FAIL,
6072 .expected_errcode = -EINVAL,
6073 },
6074 {
6075 "LD_ABS word negative offset, in bounds",
6076 .u.insns = {
6077 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
6078 BPF_STMT(BPF_RET | BPF_A, 0x0),
6079 },
6080 CLASSIC,
6081 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6082 { {0x40, 0x25051982 }, },
6083 },
6084 {
6085 "LD_ABS word negative offset, out of bounds",
6086 .u.insns = {
6087 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
6088 BPF_STMT(BPF_RET | BPF_A, 0x0),
6089 },
6090 CLASSIC,
6091 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6092 { {0x3f, 0 }, },
6093 },
6094 {
6095 "LDX_MSH standalone, preserved A",
6096 .u.insns = {
6097 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6098 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6099 BPF_STMT(BPF_RET | BPF_A, 0x0),
6100 },
6101 CLASSIC,
6102 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6103 { {0x40, 0xffeebbaa }, },
6104 },
6105 {
6106 "LDX_MSH standalone, preserved A 2",
6107 .u.insns = {
6108 BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63),
6109 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6110 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d),
6111 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
6112 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f),
6113 BPF_STMT(BPF_RET | BPF_A, 0x0),
6114 },
6115 CLASSIC,
6116 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6117 { {0x40, 0x175e9d63 }, },
6118 },
6119 {
6120 "LDX_MSH standalone, test result 1",
6121 .u.insns = {
6122 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6123 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6124 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6125 BPF_STMT(BPF_RET | BPF_A, 0x0),
6126 },
6127 CLASSIC,
6128 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6129 { {0x40, 0x14 }, },
6130 },
6131 {
6132 "LDX_MSH standalone, test result 2",
6133 .u.insns = {
6134 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6135 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
6136 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6137 BPF_STMT(BPF_RET | BPF_A, 0x0),
6138 },
6139 CLASSIC,
6140 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6141 { {0x40, 0x24 }, },
6142 },
6143 {
6144 "LDX_MSH standalone, negative offset",
6145 .u.insns = {
6146 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6147 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1),
6148 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6149 BPF_STMT(BPF_RET | BPF_A, 0x0),
6150 },
6151 CLASSIC,
6152 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6153 { {0x40, 0 }, },
6154 },
6155 {
6156 "LDX_MSH standalone, negative offset 2",
6157 .u.insns = {
6158 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6159 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e),
6160 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6161 BPF_STMT(BPF_RET | BPF_A, 0x0),
6162 },
6163 CLASSIC,
6164 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6165 { {0x40, 0x24 }, },
6166 },
6167 {
6168 "LDX_MSH standalone, out of bounds",
6169 .u.insns = {
6170 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6171 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40),
6172 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6173 BPF_STMT(BPF_RET | BPF_A, 0x0),
6174 },
6175 CLASSIC,
6176 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6177 { {0x40, 0 }, },
6178 },
Nicolas Schichan86bf1722015-08-04 15:19:12 +02006179 /*
6180 * verify that the interpreter or JIT correctly sets A and X
6181 * to 0.
6182 */
6183 {
6184 "ADD default X",
6185 .u.insns = {
6186 /*
6187 * A = 0x42
6188 * A = A + X
6189 * ret A
6190 */
6191 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6192 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
6193 BPF_STMT(BPF_RET | BPF_A, 0x0),
6194 },
6195 CLASSIC | FLAG_NO_DATA,
6196 {},
6197 { {0x1, 0x42 } },
6198 },
6199 {
6200 "ADD default A",
6201 .u.insns = {
6202 /*
6203 * A = A + 0x42
6204 * ret A
6205 */
6206 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
6207 BPF_STMT(BPF_RET | BPF_A, 0x0),
6208 },
6209 CLASSIC | FLAG_NO_DATA,
6210 {},
6211 { {0x1, 0x42 } },
6212 },
6213 {
6214 "SUB default X",
6215 .u.insns = {
6216 /*
6217 * A = 0x66
6218 * A = A - X
6219 * ret A
6220 */
6221 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
6222 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
6223 BPF_STMT(BPF_RET | BPF_A, 0x0),
6224 },
6225 CLASSIC | FLAG_NO_DATA,
6226 {},
6227 { {0x1, 0x66 } },
6228 },
6229 {
6230 "SUB default A",
6231 .u.insns = {
6232 /*
6233 * A = A - -0x66
6234 * ret A
6235 */
6236 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
6237 BPF_STMT(BPF_RET | BPF_A, 0x0),
6238 },
6239 CLASSIC | FLAG_NO_DATA,
6240 {},
6241 { {0x1, 0x66 } },
6242 },
6243 {
6244 "MUL default X",
6245 .u.insns = {
6246 /*
6247 * A = 0x42
6248 * A = A * X
6249 * ret A
6250 */
6251 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6252 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
6253 BPF_STMT(BPF_RET | BPF_A, 0x0),
6254 },
6255 CLASSIC | FLAG_NO_DATA,
6256 {},
6257 { {0x1, 0x0 } },
6258 },
6259 {
6260 "MUL default A",
6261 .u.insns = {
6262 /*
6263 * A = A * 0x66
6264 * ret A
6265 */
6266 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
6267 BPF_STMT(BPF_RET | BPF_A, 0x0),
6268 },
6269 CLASSIC | FLAG_NO_DATA,
6270 {},
6271 { {0x1, 0x0 } },
6272 },
6273 {
6274 "DIV default X",
6275 .u.insns = {
6276 /*
6277 * A = 0x42
6278 * A = A / X ; this halt the filter execution if X is 0
6279 * ret 0x42
6280 */
6281 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6282 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
6283 BPF_STMT(BPF_RET | BPF_K, 0x42),
6284 },
6285 CLASSIC | FLAG_NO_DATA,
6286 {},
6287 { {0x1, 0x0 } },
6288 },
6289 {
6290 "DIV default A",
6291 .u.insns = {
6292 /*
6293 * A = A / 1
6294 * ret A
6295 */
6296 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
6297 BPF_STMT(BPF_RET | BPF_A, 0x0),
6298 },
6299 CLASSIC | FLAG_NO_DATA,
6300 {},
6301 { {0x1, 0x0 } },
6302 },
6303 {
Yang Shid4e4bc12015-11-04 11:36:37 -08006304 "MOD default X",
6305 .u.insns = {
6306 /*
6307 * A = 0x42
6308 * A = A mod X ; this halt the filter execution if X is 0
6309 * ret 0x42
6310 */
6311 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6312 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
6313 BPF_STMT(BPF_RET | BPF_K, 0x42),
6314 },
6315 CLASSIC | FLAG_NO_DATA,
6316 {},
6317 { {0x1, 0x0 } },
6318 },
6319 {
6320 "MOD default A",
6321 .u.insns = {
6322 /*
6323 * A = A mod 1
6324 * ret A
6325 */
6326 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
6327 BPF_STMT(BPF_RET | BPF_A, 0x0),
6328 },
6329 CLASSIC | FLAG_NO_DATA,
6330 {},
6331 { {0x1, 0x0 } },
6332 },
6333 {
Nicolas Schichan86bf1722015-08-04 15:19:12 +02006334 "JMP EQ default A",
6335 .u.insns = {
6336 /*
6337 * cmp A, 0x0, 0, 1
6338 * ret 0x42
6339 * ret 0x66
6340 */
6341 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
6342 BPF_STMT(BPF_RET | BPF_K, 0x42),
6343 BPF_STMT(BPF_RET | BPF_K, 0x66),
6344 },
6345 CLASSIC | FLAG_NO_DATA,
6346 {},
6347 { {0x1, 0x42 } },
6348 },
6349 {
6350 "JMP EQ default X",
6351 .u.insns = {
6352 /*
6353 * A = 0x0
6354 * cmp A, X, 0, 1
6355 * ret 0x42
6356 * ret 0x66
6357 */
6358 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
6359 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
6360 BPF_STMT(BPF_RET | BPF_K, 0x42),
6361 BPF_STMT(BPF_RET | BPF_K, 0x66),
6362 },
6363 CLASSIC | FLAG_NO_DATA,
6364 {},
6365 { {0x1, 0x42 } },
6366 },
Daniel Borkmannfcd1c912018-01-20 01:24:31 +01006367 /* Checking interpreter vs JIT wrt signed extended imms. */
6368 {
6369 "JNE signed compare, test 1",
6370 .u.insns_int = {
6371 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6372 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6373 BPF_MOV64_REG(R2, R1),
6374 BPF_ALU64_REG(BPF_AND, R2, R3),
6375 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6376 BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1),
6377 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6378 BPF_EXIT_INSN(),
6379 },
6380 INTERNAL,
6381 { },
6382 { { 0, 1 } },
6383 },
6384 {
6385 "JNE signed compare, test 2",
6386 .u.insns_int = {
6387 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6388 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6389 BPF_MOV64_REG(R2, R1),
6390 BPF_ALU64_REG(BPF_AND, R2, R3),
6391 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6392 BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1),
6393 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6394 BPF_EXIT_INSN(),
6395 },
6396 INTERNAL,
6397 { },
6398 { { 0, 1 } },
6399 },
6400 {
6401 "JNE signed compare, test 3",
6402 .u.insns_int = {
6403 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6404 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6405 BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000),
6406 BPF_MOV64_REG(R2, R1),
6407 BPF_ALU64_REG(BPF_AND, R2, R3),
6408 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6409 BPF_JMP_REG(BPF_JNE, R2, R4, 1),
6410 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6411 BPF_EXIT_INSN(),
6412 },
6413 INTERNAL,
6414 { },
6415 { { 0, 2 } },
6416 },
6417 {
6418 "JNE signed compare, test 4",
6419 .u.insns_int = {
6420 BPF_LD_IMM64(R1, -17104896),
6421 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6422 BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1),
6423 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6424 BPF_EXIT_INSN(),
6425 },
6426 INTERNAL,
6427 { },
6428 { { 0, 2 } },
6429 },
6430 {
6431 "JNE signed compare, test 5",
6432 .u.insns_int = {
6433 BPF_LD_IMM64(R1, 0xfefb0000),
6434 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6435 BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1),
6436 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6437 BPF_EXIT_INSN(),
6438 },
6439 INTERNAL,
6440 { },
6441 { { 0, 1 } },
6442 },
6443 {
6444 "JNE signed compare, test 6",
6445 .u.insns_int = {
6446 BPF_LD_IMM64(R1, 0x7efb0000),
6447 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6448 BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1),
6449 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6450 BPF_EXIT_INSN(),
6451 },
6452 INTERNAL,
6453 { },
6454 { { 0, 2 } },
6455 },
6456 {
6457 "JNE signed compare, test 7",
6458 .u.insns = {
6459 BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000),
6460 BPF_STMT(BPF_MISC | BPF_TAX, 0),
6461 BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12),
6462 BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0),
6463 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0),
6464 BPF_STMT(BPF_RET | BPF_K, 1),
6465 BPF_STMT(BPF_RET | BPF_K, 2),
6466 },
6467 CLASSIC | FLAG_NO_DATA,
6468 {},
6469 { { 0, 2 } },
6470 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006471};
6472
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006473static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006474
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006475static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006476{
6477 struct sk_buff *skb;
6478
6479 if (size >= MAX_DATA)
6480 return NULL;
6481
6482 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
6483 if (!skb)
6484 return NULL;
6485
yuan linyude77b962017-06-18 22:48:17 +08006486 __skb_put_data(skb, buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006487
6488 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006489 skb_reset_mac_header(skb);
6490 skb->protocol = htons(ETH_P_IP);
6491 skb->pkt_type = SKB_TYPE;
6492 skb->mark = SKB_MARK;
6493 skb->hash = SKB_HASH;
6494 skb->queue_mapping = SKB_QUEUE_MAP;
6495 skb->vlan_tci = SKB_VLAN_TCI;
Jakub Kicinski5c0ca3f2016-09-12 13:04:57 +01006496 skb->vlan_proto = htons(ETH_P_IP);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006497 skb->dev = &dev;
6498 skb->dev->ifindex = SKB_DEV_IFINDEX;
6499 skb->dev->type = SKB_DEV_TYPE;
6500 skb_set_network_header(skb, min(size, ETH_HLEN));
6501
6502 return skb;
6503}
6504
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006505static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006506{
Nicolas Schichanbac142a2015-08-04 15:19:08 +02006507 struct sk_buff *skb;
6508 struct page *page;
6509
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006510 if (test->aux & FLAG_NO_DATA)
6511 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006512
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006513 /* Test case expects an skb, so populate one. Various
6514 * subtests generate skbs of different sizes based on
6515 * the same data.
6516 */
Nicolas Schichanbac142a2015-08-04 15:19:08 +02006517 skb = populate_skb(test->data, test->test[sub].data_size);
6518 if (!skb)
6519 return NULL;
6520
6521 if (test->aux & FLAG_SKB_FRAG) {
6522 /*
6523 * when the test requires a fragmented skb, add a
6524 * single fragment to the skb, filled with
6525 * test->frag_data.
6526 */
6527 void *ptr;
6528
6529 page = alloc_page(GFP_KERNEL);
6530
6531 if (!page)
6532 goto err_kfree_skb;
6533
6534 ptr = kmap(page);
6535 if (!ptr)
6536 goto err_free_page;
6537 memcpy(ptr, test->frag_data, MAX_DATA);
6538 kunmap(page);
6539 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
6540 }
6541
6542 return skb;
6543
6544err_free_page:
6545 __free_page(page);
6546err_kfree_skb:
6547 kfree_skb(skb);
6548 return NULL;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006549}
6550
6551static void release_test_data(const struct bpf_test *test, void *data)
6552{
6553 if (test->aux & FLAG_NO_DATA)
6554 return;
6555
6556 kfree_skb(data);
6557}
6558
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006559static int filter_length(int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006560{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006561 struct sock_filter *fp;
6562 int len;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006563
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006564 if (tests[which].fill_helper)
6565 return tests[which].u.ptr.len;
6566
6567 fp = tests[which].u.insns;
Chema Gonzaleze9d94502014-05-30 10:15:12 -07006568 for (len = MAX_INSNS - 1; len > 0; --len)
6569 if (fp[len].code != 0 || fp[len].k != 0)
6570 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006571
Chema Gonzaleze9d94502014-05-30 10:15:12 -07006572 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006573}
6574
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006575static void *filter_pointer(int which)
6576{
6577 if (tests[which].fill_helper)
6578 return tests[which].u.ptr.insns;
6579 else
6580 return tests[which].u.insns;
6581}
6582
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006583static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006584{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006585 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006586 unsigned int flen = filter_length(which);
6587 void *fptr = filter_pointer(which);
6588 struct sock_fprog_kern fprog;
6589 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006590
6591 switch (test_type) {
6592 case CLASSIC:
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006593 fprog.filter = fptr;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006594 fprog.len = flen;
6595
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006596 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006597 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
Yonghong Song09584b42018-02-02 22:37:15 -08006598 if (*err == tests[which].expected_errcode) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006599 pr_cont("PASS\n");
6600 /* Verifier rejected filter as expected. */
6601 *err = 0;
6602 return NULL;
6603 } else {
6604 pr_cont("UNEXPECTED_PASS\n");
6605 /* Verifier didn't reject the test that's
6606 * bad enough, just return!
6607 */
6608 *err = -EINVAL;
6609 return NULL;
6610 }
6611 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006612 if (*err) {
Alexei Starovoitov290af862018-01-09 10:04:29 -08006613 pr_cont("FAIL to prog_create err=%d len=%d\n",
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006614 *err, fprog.len);
6615 return NULL;
6616 }
6617 break;
6618
6619 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02006620 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006621 if (fp == NULL) {
6622 pr_cont("UNEXPECTED_FAIL no memory left\n");
6623 *err = -ENOMEM;
6624 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006625 }
6626
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006627 fp->len = flen;
Daniel Borkmann4962fa12015-07-30 12:42:46 +02006628 /* Type doesn't really matter here as long as it's not unspec. */
6629 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006630 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov105c0362017-05-30 13:31:32 -07006631 fp->aux->stack_depth = tests[which].stack_depth;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006632
Daniel Borkmannd1c55ab2016-05-13 19:08:31 +02006633 /* We cannot error here as we don't need type compatibility
6634 * checks.
6635 */
6636 fp = bpf_prog_select_runtime(fp, err);
Alexei Starovoitov290af862018-01-09 10:04:29 -08006637 if (*err) {
6638 pr_cont("FAIL to select_runtime err=%d\n", *err);
6639 return NULL;
6640 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006641 break;
6642 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006643
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006644 *err = 0;
6645 return fp;
6646}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006647
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006648static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006649{
6650 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006651
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006652 switch (test_type) {
6653 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006654 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006655 break;
6656 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006657 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006658 break;
6659 }
6660}
6661
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006662static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006663 int runs, u64 *duration)
6664{
6665 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07006666 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006667
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07006668 start = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006669
6670 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006671 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006672
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07006673 finish = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006674
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07006675 *duration = finish - start;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006676 do_div(*duration, runs);
6677
6678 return ret;
6679}
6680
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006681static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006682{
6683 int err_cnt = 0, i, runs = MAX_TESTRUNS;
6684
6685 for (i = 0; i < MAX_SUBTESTS; i++) {
6686 void *data;
6687 u64 duration;
6688 u32 ret;
6689
6690 if (test->test[i].data_size == 0 &&
6691 test->test[i].result == 0)
6692 break;
6693
6694 data = generate_test_data(test, i);
Nicolas Schichane34684f2015-08-04 15:19:07 +02006695 if (!data && !(test->aux & FLAG_NO_DATA)) {
6696 pr_cont("data generation failed ");
6697 err_cnt++;
6698 break;
6699 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006700 ret = __run_one(fp, data, runs, &duration);
6701 release_test_data(test, data);
6702
6703 if (ret == test->test[i].result) {
6704 pr_cont("%lld ", duration);
6705 } else {
6706 pr_cont("ret %d != %d ", ret,
6707 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006708 err_cnt++;
6709 }
6710 }
6711
6712 return err_cnt;
6713}
6714
Nicolas Schichand2648d42015-08-04 15:19:10 +02006715static char test_name[64];
6716module_param_string(test_name, test_name, sizeof(test_name), 0);
6717
6718static int test_id = -1;
6719module_param(test_id, int, 0);
6720
6721static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
6722module_param_array(test_range, int, NULL, 0);
6723
6724static __init int find_test_index(const char *test_name)
6725{
6726 int i;
6727
6728 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6729 if (!strcmp(tests[i].descr, test_name))
6730 return i;
6731 }
6732 return -1;
6733}
6734
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006735static __init int prepare_bpf_tests(void)
6736{
6737 int i;
6738
Nicolas Schichand2648d42015-08-04 15:19:10 +02006739 if (test_id >= 0) {
6740 /*
6741 * if a test_id was specified, use test_range to
6742 * cover only that test.
6743 */
6744 if (test_id >= ARRAY_SIZE(tests)) {
6745 pr_err("test_bpf: invalid test_id specified.\n");
6746 return -EINVAL;
6747 }
6748
6749 test_range[0] = test_id;
6750 test_range[1] = test_id;
6751 } else if (*test_name) {
6752 /*
6753 * if a test_name was specified, find it and setup
6754 * test_range to cover only that test.
6755 */
6756 int idx = find_test_index(test_name);
6757
6758 if (idx < 0) {
6759 pr_err("test_bpf: no test named '%s' found.\n",
6760 test_name);
6761 return -EINVAL;
6762 }
6763 test_range[0] = idx;
6764 test_range[1] = idx;
6765 } else {
6766 /*
6767 * check that the supplied test_range is valid.
6768 */
6769 if (test_range[0] >= ARRAY_SIZE(tests) ||
6770 test_range[1] >= ARRAY_SIZE(tests) ||
6771 test_range[0] < 0 || test_range[1] < 0) {
6772 pr_err("test_bpf: test_range is out of bound.\n");
6773 return -EINVAL;
6774 }
6775
6776 if (test_range[1] < test_range[0]) {
6777 pr_err("test_bpf: test_range is ending before it starts.\n");
6778 return -EINVAL;
6779 }
6780 }
6781
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006782 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6783 if (tests[i].fill_helper &&
6784 tests[i].fill_helper(&tests[i]) < 0)
6785 return -ENOMEM;
6786 }
6787
6788 return 0;
6789}
6790
6791static __init void destroy_bpf_tests(void)
6792{
6793 int i;
6794
6795 for (i = 0; i < ARRAY_SIZE(tests); i++) {
6796 if (tests[i].fill_helper)
6797 kfree(tests[i].u.ptr.insns);
6798 }
6799}
6800
Nicolas Schichand2648d42015-08-04 15:19:10 +02006801static bool exclude_test(int test_id)
6802{
6803 return test_id < test_range[0] || test_id > test_range[1];
6804}
6805
Yonghong Song76db8082018-03-21 16:31:04 -07006806static __init struct sk_buff *build_test_skb(void)
6807{
6808 u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN;
6809 struct sk_buff *skb[2];
6810 struct page *page[2];
6811 int i, data_size = 8;
6812
6813 for (i = 0; i < 2; i++) {
6814 page[i] = alloc_page(GFP_KERNEL);
6815 if (!page[i]) {
6816 if (i == 0)
6817 goto err_page0;
6818 else
6819 goto err_page1;
6820 }
6821
6822 /* this will set skb[i]->head_frag */
6823 skb[i] = dev_alloc_skb(headroom + data_size);
6824 if (!skb[i]) {
6825 if (i == 0)
6826 goto err_skb0;
6827 else
6828 goto err_skb1;
6829 }
6830
6831 skb_reserve(skb[i], headroom);
6832 skb_put(skb[i], data_size);
6833 skb[i]->protocol = htons(ETH_P_IP);
6834 skb_reset_network_header(skb[i]);
6835 skb_set_mac_header(skb[i], -ETH_HLEN);
6836
6837 skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64);
6838 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
6839 }
6840
6841 /* setup shinfo */
6842 skb_shinfo(skb[0])->gso_size = 1448;
6843 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4;
6844 skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY;
6845 skb_shinfo(skb[0])->gso_segs = 0;
6846 skb_shinfo(skb[0])->frag_list = skb[1];
6847
6848 /* adjust skb[0]'s len */
6849 skb[0]->len += skb[1]->len;
6850 skb[0]->data_len += skb[1]->data_len;
6851 skb[0]->truesize += skb[1]->truesize;
6852
6853 return skb[0];
6854
6855err_skb1:
6856 __free_page(page[1]);
6857err_page1:
6858 kfree_skb(skb[0]);
6859err_skb0:
6860 __free_page(page[0]);
6861err_page0:
6862 return NULL;
6863}
6864
6865static __init int test_skb_segment(void)
6866{
6867 netdev_features_t features;
6868 struct sk_buff *skb, *segs;
6869 int ret = -1;
6870
6871 features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM |
6872 NETIF_F_IPV6_CSUM;
6873 features |= NETIF_F_RXCSUM;
6874 skb = build_test_skb();
6875 if (!skb) {
6876 pr_info("%s: failed to build_test_skb", __func__);
6877 goto done;
6878 }
6879
6880 segs = skb_segment(skb, features);
Dan Carpenter99fe29d2018-03-28 14:48:36 +03006881 if (!IS_ERR(segs)) {
Yonghong Song76db8082018-03-21 16:31:04 -07006882 kfree_skb_list(segs);
6883 ret = 0;
6884 pr_info("%s: success in skb_segment!", __func__);
6885 } else {
6886 pr_info("%s: failed in skb_segment!", __func__);
6887 }
6888 kfree_skb(skb);
6889done:
6890 return ret;
6891}
6892
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006893static __init int test_bpf(void)
6894{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006895 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02006896 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006897
6898 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07006899 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006900 int err;
6901
Eric Dumazetd40bc962018-02-26 10:52:46 -08006902 cond_resched();
Nicolas Schichand2648d42015-08-04 15:19:10 +02006903 if (exclude_test(i))
6904 continue;
6905
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006906 pr_info("#%d %s ", i, tests[i].descr);
6907
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006908 fp = generate_filter(i, &err);
6909 if (fp == NULL) {
6910 if (err == 0) {
6911 pass_cnt++;
6912 continue;
6913 }
Alexei Starovoitov290af862018-01-09 10:04:29 -08006914 err_cnt++;
6915 continue;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006916 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02006917
6918 pr_cont("jited:%u ", fp->jited);
6919
6920 run_cnt++;
6921 if (fp->jited)
6922 jit_cnt++;
6923
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006924 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006925 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006926
6927 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006928 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006929 err_cnt++;
6930 } else {
6931 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006932 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006933 }
6934 }
6935
Daniel Borkmann327941f2015-04-30 16:17:27 +02006936 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
6937 pass_cnt, err_cnt, jit_cnt, run_cnt);
6938
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006939 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006940}
6941
6942static int __init test_bpf_init(void)
6943{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006944 int ret;
6945
6946 ret = prepare_bpf_tests();
6947 if (ret < 0)
6948 return ret;
6949
6950 ret = test_bpf();
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02006951 destroy_bpf_tests();
Yonghong Song76db8082018-03-21 16:31:04 -07006952 if (ret)
6953 return ret;
6954
6955 return test_skb_segment();
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006956}
6957
6958static void __exit test_bpf_exit(void)
6959{
6960}
6961
6962module_init(test_bpf_init);
6963module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006964
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006965MODULE_LICENSE("GPL");