blob: 377e866764cbec6701558dc2ff33df926995b725 [file] [log] [blame]
Thomas Gleixner5b497af2019-05-29 07:18:09 -07001// SPDX-License-Identifier: GPL-2.0-only
Alexei Starovoitov64a89462014-05-08 14:10:52 -07002/*
3 * Testsuite for BPF interpreter and BPF JIT compiler
4 *
5 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/filter.h>
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -070013#include <linux/bpf.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070014#include <linux/skbuff.h>
15#include <linux/netdevice.h>
16#include <linux/if_vlan.h>
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020017#include <linux/random.h>
Nicolas Schichanbac142a2015-08-04 15:19:08 +020018#include <linux/highmem.h>
Eric Dumazetd40bc962018-02-26 10:52:46 -080019#include <linux/sched.h>
Alexei Starovoitov64a89462014-05-08 14:10:52 -070020
Daniel Borkmann10f18e02014-05-23 18:44:00 +020021/* General test specific settings */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070022#define MAX_SUBTESTS 3
Eric Dumazet9960d762018-02-28 08:39:20 -080023#define MAX_TESTRUNS 1000
Alexei Starovoitov64a89462014-05-08 14:10:52 -070024#define MAX_DATA 128
25#define MAX_INSNS 512
26#define MAX_K 0xffffFFFF
27
Daniel Borkmann10f18e02014-05-23 18:44:00 +020028/* Few constants used to init test 'skb' */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070029#define SKB_TYPE 3
30#define SKB_MARK 0x1234aaaa
31#define SKB_HASH 0x1234aaab
32#define SKB_QUEUE_MAP 123
33#define SKB_VLAN_TCI 0xffff
Michał Mirosław0c4b2d32018-11-10 19:58:36 +010034#define SKB_VLAN_PRESENT 1
Alexei Starovoitov64a89462014-05-08 14:10:52 -070035#define SKB_DEV_IFINDEX 577
36#define SKB_DEV_TYPE 588
37
Daniel Borkmann10f18e02014-05-23 18:44:00 +020038/* Redefine REGs to make tests less verbose */
39#define R0 BPF_REG_0
40#define R1 BPF_REG_1
41#define R2 BPF_REG_2
42#define R3 BPF_REG_3
43#define R4 BPF_REG_4
44#define R5 BPF_REG_5
45#define R6 BPF_REG_6
46#define R7 BPF_REG_7
47#define R8 BPF_REG_8
48#define R9 BPF_REG_9
49#define R10 BPF_REG_10
50
51/* Flags that can be passed to test cases */
52#define FLAG_NO_DATA BIT(0)
53#define FLAG_EXPECTED_FAIL BIT(1)
Nicolas Schichanbac142a2015-08-04 15:19:08 +020054#define FLAG_SKB_FRAG BIT(2)
Daniel Borkmann10f18e02014-05-23 18:44:00 +020055
56enum {
57 CLASSIC = BIT(6), /* Old BPF instructions only. */
58 INTERNAL = BIT(7), /* Extended instruction set. */
59};
60
61#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
Alexei Starovoitov64a89462014-05-08 14:10:52 -070062
63struct bpf_test {
64 const char *descr;
65 union {
66 struct sock_filter insns[MAX_INSNS];
Alexei Starovoitov2695fb52014-07-24 16:38:21 -070067 struct bpf_insn insns_int[MAX_INSNS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020068 struct {
69 void *insns;
70 unsigned int len;
71 } ptr;
Andrew Mortonece80492014-05-22 10:16:46 -070072 } u;
Daniel Borkmann10f18e02014-05-23 18:44:00 +020073 __u8 aux;
Alexei Starovoitov64a89462014-05-08 14:10:52 -070074 __u8 data[MAX_DATA];
75 struct {
76 int data_size;
77 __u32 result;
78 } test[MAX_SUBTESTS];
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020079 int (*fill_helper)(struct bpf_test *self);
Yonghong Song09584b42018-02-02 22:37:15 -080080 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
Nicolas Schichanbac142a2015-08-04 15:19:08 +020081 __u8 frag_data[MAX_DATA];
Alexei Starovoitov105c0362017-05-30 13:31:32 -070082 int stack_depth; /* for eBPF only, since tests don't call verifier */
Alexei Starovoitov64a89462014-05-08 14:10:52 -070083};
84
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +020085/* Large test cases need separate allocation and fill handler. */
86
87static int bpf_fill_maxinsns1(struct bpf_test *self)
88{
89 unsigned int len = BPF_MAXINSNS;
90 struct sock_filter *insn;
91 __u32 k = ~0;
92 int i;
93
94 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
95 if (!insn)
96 return -ENOMEM;
97
98 for (i = 0; i < len; i++, k--)
99 insn[i] = __BPF_STMT(BPF_RET | BPF_K, k);
100
101 self->u.ptr.insns = insn;
102 self->u.ptr.len = len;
103
104 return 0;
105}
106
107static int bpf_fill_maxinsns2(struct bpf_test *self)
108{
109 unsigned int len = BPF_MAXINSNS;
110 struct sock_filter *insn;
111 int i;
112
113 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
114 if (!insn)
115 return -ENOMEM;
116
117 for (i = 0; i < len; i++)
118 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
119
120 self->u.ptr.insns = insn;
121 self->u.ptr.len = len;
122
123 return 0;
124}
125
126static int bpf_fill_maxinsns3(struct bpf_test *self)
127{
128 unsigned int len = BPF_MAXINSNS;
129 struct sock_filter *insn;
130 struct rnd_state rnd;
131 int i;
132
133 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
134 if (!insn)
135 return -ENOMEM;
136
137 prandom_seed_state(&rnd, 3141592653589793238ULL);
138
139 for (i = 0; i < len - 1; i++) {
140 __u32 k = prandom_u32_state(&rnd);
141
142 insn[i] = __BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, k);
143 }
144
145 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
146
147 self->u.ptr.insns = insn;
148 self->u.ptr.len = len;
149
150 return 0;
151}
152
153static int bpf_fill_maxinsns4(struct bpf_test *self)
154{
155 unsigned int len = BPF_MAXINSNS + 1;
156 struct sock_filter *insn;
157 int i;
158
159 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
160 if (!insn)
161 return -ENOMEM;
162
163 for (i = 0; i < len; i++)
164 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
165
166 self->u.ptr.insns = insn;
167 self->u.ptr.len = len;
168
169 return 0;
170}
171
172static int bpf_fill_maxinsns5(struct bpf_test *self)
173{
174 unsigned int len = BPF_MAXINSNS;
175 struct sock_filter *insn;
176 int i;
177
178 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
179 if (!insn)
180 return -ENOMEM;
181
182 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
183
184 for (i = 1; i < len - 1; i++)
185 insn[i] = __BPF_STMT(BPF_RET | BPF_K, 0xfefefefe);
186
187 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
188
189 self->u.ptr.insns = insn;
190 self->u.ptr.len = len;
191
192 return 0;
193}
194
195static int bpf_fill_maxinsns6(struct bpf_test *self)
196{
197 unsigned int len = BPF_MAXINSNS;
198 struct sock_filter *insn;
199 int i;
200
201 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
202 if (!insn)
203 return -ENOMEM;
204
205 for (i = 0; i < len - 1; i++)
206 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
207 SKF_AD_VLAN_TAG_PRESENT);
208
209 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
210
211 self->u.ptr.insns = insn;
212 self->u.ptr.len = len;
213
214 return 0;
215}
216
217static int bpf_fill_maxinsns7(struct bpf_test *self)
218{
219 unsigned int len = BPF_MAXINSNS;
220 struct sock_filter *insn;
221 int i;
222
223 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
224 if (!insn)
225 return -ENOMEM;
226
227 for (i = 0; i < len - 4; i++)
228 insn[i] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
229 SKF_AD_CPU);
230
231 insn[len - 4] = __BPF_STMT(BPF_MISC | BPF_TAX, 0);
232 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SKF_AD_OFF +
233 SKF_AD_CPU);
234 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0);
235 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
236
237 self->u.ptr.insns = insn;
238 self->u.ptr.len = len;
239
240 return 0;
241}
242
243static int bpf_fill_maxinsns8(struct bpf_test *self)
244{
245 unsigned int len = BPF_MAXINSNS;
246 struct sock_filter *insn;
247 int i, jmp_off = len - 3;
248
249 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
250 if (!insn)
251 return -ENOMEM;
252
253 insn[0] = __BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff);
254
255 for (i = 1; i < len - 1; i++)
256 insn[i] = __BPF_JUMP(BPF_JMP | BPF_JGT, 0xffffffff, jmp_off--, 0);
257
258 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
259
260 self->u.ptr.insns = insn;
261 self->u.ptr.len = len;
262
263 return 0;
264}
265
Daniel Borkmann3b529602015-05-23 01:10:07 +0200266static int bpf_fill_maxinsns9(struct bpf_test *self)
267{
268 unsigned int len = BPF_MAXINSNS;
269 struct bpf_insn *insn;
270 int i;
271
272 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
273 if (!insn)
274 return -ENOMEM;
275
276 insn[0] = BPF_JMP_IMM(BPF_JA, 0, 0, len - 2);
277 insn[1] = BPF_ALU32_IMM(BPF_MOV, R0, 0xcbababab);
278 insn[2] = BPF_EXIT_INSN();
279
280 for (i = 3; i < len - 2; i++)
281 insn[i] = BPF_ALU32_IMM(BPF_MOV, R0, 0xfefefefe);
282
283 insn[len - 2] = BPF_EXIT_INSN();
284 insn[len - 1] = BPF_JMP_IMM(BPF_JA, 0, 0, -(len - 1));
285
286 self->u.ptr.insns = insn;
287 self->u.ptr.len = len;
288
289 return 0;
290}
291
292static int bpf_fill_maxinsns10(struct bpf_test *self)
293{
294 unsigned int len = BPF_MAXINSNS, hlen = len - 2;
295 struct bpf_insn *insn;
296 int i;
297
298 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
299 if (!insn)
300 return -ENOMEM;
301
302 for (i = 0; i < hlen / 2; i++)
303 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 2 - 2 * i);
304 for (i = hlen - 1; i > hlen / 2; i--)
305 insn[i] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen - 1 - 2 * i);
306
307 insn[hlen / 2] = BPF_JMP_IMM(BPF_JA, 0, 0, hlen / 2 - 1);
308 insn[hlen] = BPF_ALU32_IMM(BPF_MOV, R0, 0xabababac);
309 insn[hlen + 1] = BPF_EXIT_INSN();
310
311 self->u.ptr.insns = insn;
312 self->u.ptr.len = len;
313
314 return 0;
315}
316
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200317static int __bpf_fill_ja(struct bpf_test *self, unsigned int len,
318 unsigned int plen)
319{
320 struct sock_filter *insn;
321 unsigned int rlen;
322 int i, j;
323
324 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
325 if (!insn)
326 return -ENOMEM;
327
328 rlen = (len % plen) - 1;
329
330 for (i = 0; i + plen < len; i += plen)
331 for (j = 0; j < plen; j++)
332 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA,
333 plen - 1 - j, 0, 0);
334 for (j = 0; j < rlen; j++)
335 insn[i + j] = __BPF_JUMP(BPF_JMP | BPF_JA, rlen - 1 - j,
336 0, 0);
337
338 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xababcbac);
339
340 self->u.ptr.insns = insn;
341 self->u.ptr.len = len;
342
343 return 0;
344}
345
346static int bpf_fill_maxinsns11(struct bpf_test *self)
347{
Gary Lin16a660e2021-01-19 18:25:00 +0800348 /* Hits 70 passes on x86_64 and triggers NOPs padding. */
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200349 return __bpf_fill_ja(self, BPF_MAXINSNS, 68);
350}
351
Daniel Borkmannbe088152018-06-02 23:06:32 +0200352static int bpf_fill_maxinsns12(struct bpf_test *self)
353{
354 unsigned int len = BPF_MAXINSNS;
355 struct sock_filter *insn;
356 int i = 0;
357
358 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
359 if (!insn)
360 return -ENOMEM;
361
362 insn[0] = __BPF_JUMP(BPF_JMP | BPF_JA, len - 2, 0, 0);
363
364 for (i = 1; i < len - 1; i++)
365 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
366
367 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xabababab);
368
369 self->u.ptr.insns = insn;
370 self->u.ptr.len = len;
371
372 return 0;
373}
374
375static int bpf_fill_maxinsns13(struct bpf_test *self)
376{
377 unsigned int len = BPF_MAXINSNS;
378 struct sock_filter *insn;
379 int i = 0;
380
381 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
382 if (!insn)
383 return -ENOMEM;
384
385 for (i = 0; i < len - 3; i++)
386 insn[i] = __BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0);
387
388 insn[len - 3] = __BPF_STMT(BPF_LD | BPF_IMM, 0xabababab);
389 insn[len - 2] = __BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0);
390 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_A, 0);
391
392 self->u.ptr.insns = insn;
393 self->u.ptr.len = len;
394
395 return 0;
396}
397
Daniel Borkmannbde28bc2015-05-26 22:35:43 +0200398static int bpf_fill_ja(struct bpf_test *self)
399{
400 /* Hits exactly 11 passes on x86_64 JIT. */
401 return __bpf_fill_ja(self, 12, 9);
402}
403
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -0700404static int bpf_fill_ld_abs_get_processor_id(struct bpf_test *self)
405{
406 unsigned int len = BPF_MAXINSNS;
407 struct sock_filter *insn;
408 int i;
409
410 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
411 if (!insn)
412 return -ENOMEM;
413
414 for (i = 0; i < len - 1; i += 2) {
415 insn[i] = __BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 0);
416 insn[i + 1] = __BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
417 SKF_AD_OFF + SKF_AD_CPU);
418 }
419
420 insn[len - 1] = __BPF_STMT(BPF_RET | BPF_K, 0xbee);
421
422 self->u.ptr.insns = insn;
423 self->u.ptr.len = len;
424
425 return 0;
426}
427
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200428static int __bpf_fill_stxdw(struct bpf_test *self, int size)
429{
430 unsigned int len = BPF_MAXINSNS;
431 struct bpf_insn *insn;
432 int i;
433
434 insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL);
435 if (!insn)
436 return -ENOMEM;
437
438 insn[0] = BPF_ALU32_IMM(BPF_MOV, R0, 1);
439 insn[1] = BPF_ST_MEM(size, R10, -40, 42);
440
441 for (i = 2; i < len - 2; i++)
442 insn[i] = BPF_STX_XADD(size, R10, R0, -40);
443
444 insn[len - 2] = BPF_LDX_MEM(size, R0, R10, -40);
445 insn[len - 1] = BPF_EXIT_INSN();
446
447 self->u.ptr.insns = insn;
448 self->u.ptr.len = len;
Alexei Starovoitov105c0362017-05-30 13:31:32 -0700449 self->stack_depth = 40;
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200450
451 return 0;
452}
453
454static int bpf_fill_stxw(struct bpf_test *self)
455{
456 return __bpf_fill_stxdw(self, BPF_W);
457}
458
459static int bpf_fill_stxdw(struct bpf_test *self)
460{
461 return __bpf_fill_stxdw(self, BPF_DW);
462}
463
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700464static struct bpf_test tests[] = {
465 {
466 "TAX",
Andrew Mortonece80492014-05-22 10:16:46 -0700467 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700468 BPF_STMT(BPF_LD | BPF_IMM, 1),
469 BPF_STMT(BPF_MISC | BPF_TAX, 0),
470 BPF_STMT(BPF_LD | BPF_IMM, 2),
471 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
472 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
473 BPF_STMT(BPF_MISC | BPF_TAX, 0),
474 BPF_STMT(BPF_LD | BPF_LEN, 0),
475 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
476 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
477 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
478 BPF_STMT(BPF_RET | BPF_A, 0)
479 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200480 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700481 { 10, 20, 30, 40, 50 },
482 { { 2, 10 }, { 3, 20 }, { 4, 30 } },
483 },
484 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700485 "TXA",
Andrew Mortonece80492014-05-22 10:16:46 -0700486 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700487 BPF_STMT(BPF_LDX | BPF_LEN, 0),
488 BPF_STMT(BPF_MISC | BPF_TXA, 0),
489 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
490 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
491 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200492 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700493 { 10, 20, 30, 40, 50 },
494 { { 1, 2 }, { 3, 6 }, { 4, 8 } },
495 },
496 {
497 "ADD_SUB_MUL_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700498 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700499 BPF_STMT(BPF_LD | BPF_IMM, 1),
500 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
501 BPF_STMT(BPF_LDX | BPF_IMM, 3),
502 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
503 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
504 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
505 BPF_STMT(BPF_RET | BPF_A, 0)
506 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200507 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700508 { },
509 { { 0, 0xfffffffd } }
510 },
511 {
Denis Kirjanov6867b172014-12-01 13:12:25 +0300512 "DIV_MOD_KX",
Andrew Mortonece80492014-05-22 10:16:46 -0700513 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700514 BPF_STMT(BPF_LD | BPF_IMM, 8),
515 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
516 BPF_STMT(BPF_MISC | BPF_TAX, 0),
517 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
518 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
519 BPF_STMT(BPF_MISC | BPF_TAX, 0),
520 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
521 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
Denis Kirjanov6867b172014-12-01 13:12:25 +0300522 BPF_STMT(BPF_MISC | BPF_TAX, 0),
523 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
524 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
525 BPF_STMT(BPF_MISC | BPF_TAX, 0),
526 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
527 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700528 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
529 BPF_STMT(BPF_RET | BPF_A, 0)
530 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200531 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700532 { },
Denis Kirjanov6867b172014-12-01 13:12:25 +0300533 { { 0, 0x20000000 } }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700534 },
535 {
536 "AND_OR_LSH_K",
Andrew Mortonece80492014-05-22 10:16:46 -0700537 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700538 BPF_STMT(BPF_LD | BPF_IMM, 0xff),
539 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
540 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
541 BPF_STMT(BPF_MISC | BPF_TAX, 0),
542 BPF_STMT(BPF_LD | BPF_IMM, 0xf),
543 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
544 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
545 BPF_STMT(BPF_RET | BPF_A, 0)
546 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200547 CLASSIC | FLAG_NO_DATA,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700548 { },
549 { { 0, 0x800000ff }, { 1, 0x800000ff } },
550 },
551 {
Chema Gonzaleze9d94502014-05-30 10:15:12 -0700552 "LD_IMM_0",
553 .u.insns = {
554 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
555 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
556 BPF_STMT(BPF_RET | BPF_K, 0),
557 BPF_STMT(BPF_RET | BPF_K, 1),
558 },
559 CLASSIC,
560 { },
561 { { 1, 1 } },
562 },
563 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700564 "LD_IND",
Andrew Mortonece80492014-05-22 10:16:46 -0700565 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700566 BPF_STMT(BPF_LDX | BPF_LEN, 0),
567 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
568 BPF_STMT(BPF_RET | BPF_K, 1)
569 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200570 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700571 { },
572 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
573 },
574 {
575 "LD_ABS",
Andrew Mortonece80492014-05-22 10:16:46 -0700576 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700577 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
578 BPF_STMT(BPF_RET | BPF_K, 1)
579 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200580 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700581 { },
582 { { 1, 0 }, { 10, 0 }, { 60, 0 } },
583 },
584 {
585 "LD_ABS_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700586 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700587 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
588 BPF_STMT(BPF_MISC | BPF_TAX, 0),
589 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
590 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
591 BPF_STMT(BPF_RET | BPF_A, 0)
592 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200593 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700594 { 1, 2, 3 },
595 { { 1, 0 }, { 2, 3 } },
596 },
597 {
598 "LD_IND_LL",
Andrew Mortonece80492014-05-22 10:16:46 -0700599 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700600 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
601 BPF_STMT(BPF_LDX | BPF_LEN, 0),
602 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
603 BPF_STMT(BPF_MISC | BPF_TAX, 0),
604 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
605 BPF_STMT(BPF_RET | BPF_A, 0)
606 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200607 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700608 { 1, 2, 3, 0xff },
609 { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
610 },
611 {
612 "LD_ABS_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700613 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700614 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
615 BPF_STMT(BPF_MISC | BPF_TAX, 0),
616 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
617 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
618 BPF_STMT(BPF_RET | BPF_A, 0)
619 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200620 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700621 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
622 { { 15, 0 }, { 16, 3 } },
623 },
624 {
625 "LD_IND_NET",
Andrew Mortonece80492014-05-22 10:16:46 -0700626 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700627 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
628 BPF_STMT(BPF_LDX | BPF_LEN, 0),
629 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
630 BPF_STMT(BPF_MISC | BPF_TAX, 0),
631 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
632 BPF_STMT(BPF_RET | BPF_A, 0)
633 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200634 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700635 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
636 { { 14, 0 }, { 15, 1 }, { 17, 3 } },
637 },
638 {
639 "LD_PKTTYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700640 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700641 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
642 SKF_AD_OFF + SKF_AD_PKTTYPE),
643 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
644 BPF_STMT(BPF_RET | BPF_K, 1),
645 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
646 SKF_AD_OFF + SKF_AD_PKTTYPE),
647 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
648 BPF_STMT(BPF_RET | BPF_K, 1),
649 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
650 SKF_AD_OFF + SKF_AD_PKTTYPE),
651 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
652 BPF_STMT(BPF_RET | BPF_K, 1),
653 BPF_STMT(BPF_RET | BPF_A, 0)
654 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200655 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700656 { },
657 { { 1, 3 }, { 10, 3 } },
658 },
659 {
660 "LD_MARK",
Andrew Mortonece80492014-05-22 10:16:46 -0700661 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700662 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
663 SKF_AD_OFF + SKF_AD_MARK),
664 BPF_STMT(BPF_RET | BPF_A, 0)
665 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200666 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700667 { },
668 { { 1, SKB_MARK}, { 10, SKB_MARK} },
669 },
670 {
671 "LD_RXHASH",
Andrew Mortonece80492014-05-22 10:16:46 -0700672 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700673 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
674 SKF_AD_OFF + SKF_AD_RXHASH),
675 BPF_STMT(BPF_RET | BPF_A, 0)
676 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200677 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700678 { },
679 { { 1, SKB_HASH}, { 10, SKB_HASH} },
680 },
681 {
682 "LD_QUEUE",
Andrew Mortonece80492014-05-22 10:16:46 -0700683 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700684 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
685 SKF_AD_OFF + SKF_AD_QUEUE),
686 BPF_STMT(BPF_RET | BPF_A, 0)
687 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200688 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700689 { },
690 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
691 },
692 {
693 "LD_PROTOCOL",
Andrew Mortonece80492014-05-22 10:16:46 -0700694 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700695 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
696 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
697 BPF_STMT(BPF_RET | BPF_K, 0),
698 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
699 SKF_AD_OFF + SKF_AD_PROTOCOL),
700 BPF_STMT(BPF_MISC | BPF_TAX, 0),
701 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
702 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
703 BPF_STMT(BPF_RET | BPF_K, 0),
704 BPF_STMT(BPF_MISC | BPF_TXA, 0),
705 BPF_STMT(BPF_RET | BPF_A, 0)
706 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200707 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700708 { 10, 20, 30 },
709 { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
710 },
711 {
712 "LD_VLAN_TAG",
Andrew Mortonece80492014-05-22 10:16:46 -0700713 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700714 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
715 SKF_AD_OFF + SKF_AD_VLAN_TAG),
716 BPF_STMT(BPF_RET | BPF_A, 0)
717 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200718 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700719 { },
720 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +0100721 { 1, SKB_VLAN_TCI },
722 { 10, SKB_VLAN_TCI }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700723 },
724 },
725 {
726 "LD_VLAN_TAG_PRESENT",
Andrew Mortonece80492014-05-22 10:16:46 -0700727 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700728 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
729 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
730 BPF_STMT(BPF_RET | BPF_A, 0)
731 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200732 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700733 { },
734 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +0100735 { 1, SKB_VLAN_PRESENT },
736 { 10, SKB_VLAN_PRESENT }
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700737 },
738 },
739 {
740 "LD_IFINDEX",
Andrew Mortonece80492014-05-22 10:16:46 -0700741 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700742 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
743 SKF_AD_OFF + SKF_AD_IFINDEX),
744 BPF_STMT(BPF_RET | BPF_A, 0)
745 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200746 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700747 { },
748 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
749 },
750 {
751 "LD_HATYPE",
Andrew Mortonece80492014-05-22 10:16:46 -0700752 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700753 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
754 SKF_AD_OFF + SKF_AD_HATYPE),
755 BPF_STMT(BPF_RET | BPF_A, 0)
756 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200757 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700758 { },
759 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
760 },
761 {
762 "LD_CPU",
Andrew Mortonece80492014-05-22 10:16:46 -0700763 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700764 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
765 SKF_AD_OFF + SKF_AD_CPU),
766 BPF_STMT(BPF_MISC | BPF_TAX, 0),
767 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
768 SKF_AD_OFF + SKF_AD_CPU),
769 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
770 BPF_STMT(BPF_RET | BPF_A, 0)
771 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200772 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700773 { },
774 { { 1, 0 }, { 10, 0 } },
775 },
776 {
777 "LD_NLATTR",
Andrew Mortonece80492014-05-22 10:16:46 -0700778 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700779 BPF_STMT(BPF_LDX | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700780 BPF_STMT(BPF_MISC | BPF_TXA, 0),
781 BPF_STMT(BPF_LDX | BPF_IMM, 3),
782 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
783 SKF_AD_OFF + SKF_AD_NLATTR),
784 BPF_STMT(BPF_RET | BPF_A, 0)
785 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200786 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700787#ifdef __BIG_ENDIAN
788 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
789#else
790 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
791#endif
792 { { 4, 0 }, { 20, 6 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700793 },
794 {
795 "LD_NLATTR_NEST",
Andrew Mortonece80492014-05-22 10:16:46 -0700796 .u.insns = {
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700797 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700798 BPF_STMT(BPF_LDX | BPF_IMM, 3),
799 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
800 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700801 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700802 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
803 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
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_LD | BPF_W | BPF_ABS,
806 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700807 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700808 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
809 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700810 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700811 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
812 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700813 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700814 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
815 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700816 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700817 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
818 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700819 BPF_STMT(BPF_LD | BPF_IMM, 2),
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700820 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
821 SKF_AD_OFF + SKF_AD_NLATTR_NEST),
822 BPF_STMT(BPF_RET | BPF_A, 0)
823 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200824 CLASSIC,
Alexei Starovoitovdf6d0f9832014-06-06 17:48:20 -0700825#ifdef __BIG_ENDIAN
826 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
827#else
828 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
829#endif
830 { { 4, 0 }, { 20, 10 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700831 },
832 {
833 "LD_PAYLOAD_OFF",
Andrew Mortonece80492014-05-22 10:16:46 -0700834 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700835 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
836 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
837 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
838 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
839 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
840 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
841 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
842 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
843 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
844 SKF_AD_OFF + SKF_AD_PAY_OFFSET),
845 BPF_STMT(BPF_RET | BPF_A, 0)
846 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200847 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700848 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
849 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
850 * id 9737, seq 1, length 64
851 */
852 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
853 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
854 0x08, 0x00,
855 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
856 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
857 { { 30, 0 }, { 100, 42 } },
858 },
859 {
860 "LD_ANC_XOR",
Andrew Mortonece80492014-05-22 10:16:46 -0700861 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700862 BPF_STMT(BPF_LD | BPF_IMM, 10),
863 BPF_STMT(BPF_LDX | BPF_IMM, 300),
864 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
865 SKF_AD_OFF + SKF_AD_ALU_XOR_X),
866 BPF_STMT(BPF_RET | BPF_A, 0)
867 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200868 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700869 { },
Nathan Chancellor09845432019-08-18 21:34:20 -0700870 { { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700871 },
872 {
873 "SPILL_FILL",
Andrew Mortonece80492014-05-22 10:16:46 -0700874 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700875 BPF_STMT(BPF_LDX | BPF_LEN, 0),
876 BPF_STMT(BPF_LD | BPF_IMM, 2),
877 BPF_STMT(BPF_ALU | BPF_RSH, 1),
878 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
879 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
880 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
881 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
882 BPF_STMT(BPF_STX, 15), /* M3 = len */
883 BPF_STMT(BPF_LDX | BPF_MEM, 1),
884 BPF_STMT(BPF_LD | BPF_MEM, 2),
885 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
886 BPF_STMT(BPF_LDX | BPF_MEM, 15),
887 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
888 BPF_STMT(BPF_RET | BPF_A, 0)
889 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200890 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700891 { },
892 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
893 },
894 {
895 "JEQ",
Andrew Mortonece80492014-05-22 10:16:46 -0700896 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700897 BPF_STMT(BPF_LDX | BPF_LEN, 0),
898 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
899 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
900 BPF_STMT(BPF_RET | BPF_K, 1),
901 BPF_STMT(BPF_RET | BPF_K, MAX_K)
902 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200903 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700904 { 3, 3, 3, 3, 3 },
905 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
906 },
907 {
908 "JGT",
Andrew Mortonece80492014-05-22 10:16:46 -0700909 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700910 BPF_STMT(BPF_LDX | BPF_LEN, 0),
911 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
912 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
913 BPF_STMT(BPF_RET | BPF_K, 1),
914 BPF_STMT(BPF_RET | BPF_K, MAX_K)
915 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200916 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700917 { 4, 4, 4, 3, 3 },
918 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
919 },
920 {
Daniel Borkmann92b31a92017-08-10 01:39:55 +0200921 "JGE (jt 0), test 1",
922 .u.insns = {
923 BPF_STMT(BPF_LDX | BPF_LEN, 0),
924 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
925 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
926 BPF_STMT(BPF_RET | BPF_K, 1),
927 BPF_STMT(BPF_RET | BPF_K, MAX_K)
928 },
929 CLASSIC,
930 { 4, 4, 4, 3, 3 },
931 { { 2, 0 }, { 3, 1 }, { 4, 1 } },
932 },
933 {
934 "JGE (jt 0), test 2",
935 .u.insns = {
936 BPF_STMT(BPF_LDX | BPF_LEN, 0),
937 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
938 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 1),
939 BPF_STMT(BPF_RET | BPF_K, 1),
940 BPF_STMT(BPF_RET | BPF_K, MAX_K)
941 },
942 CLASSIC,
943 { 4, 4, 5, 3, 3 },
944 { { 4, 1 }, { 5, 1 }, { 6, MAX_K } },
945 },
946 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700947 "JGE",
Andrew Mortonece80492014-05-22 10:16:46 -0700948 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700949 BPF_STMT(BPF_LDX | BPF_LEN, 0),
950 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
951 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
952 BPF_STMT(BPF_RET | BPF_K, 10),
953 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
954 BPF_STMT(BPF_RET | BPF_K, 20),
955 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
956 BPF_STMT(BPF_RET | BPF_K, 30),
957 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
958 BPF_STMT(BPF_RET | BPF_K, 40),
959 BPF_STMT(BPF_RET | BPF_K, MAX_K)
960 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200961 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700962 { 1, 2, 3, 4, 5 },
963 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
964 },
965 {
966 "JSET",
Andrew Mortonece80492014-05-22 10:16:46 -0700967 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700968 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
969 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
970 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
971 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
972 BPF_STMT(BPF_LDX | BPF_LEN, 0),
973 BPF_STMT(BPF_MISC | BPF_TXA, 0),
974 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
975 BPF_STMT(BPF_MISC | BPF_TAX, 0),
976 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
977 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
978 BPF_STMT(BPF_RET | BPF_K, 10),
979 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
980 BPF_STMT(BPF_RET | BPF_K, 20),
981 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
982 BPF_STMT(BPF_RET | BPF_K, 30),
983 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
984 BPF_STMT(BPF_RET | BPF_K, 30),
985 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
986 BPF_STMT(BPF_RET | BPF_K, 30),
987 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
988 BPF_STMT(BPF_RET | BPF_K, 30),
989 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
990 BPF_STMT(BPF_RET | BPF_K, 30),
991 BPF_STMT(BPF_RET | BPF_K, MAX_K)
992 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +0200993 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -0700994 { 0, 0xAA, 0x55, 1 },
995 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
996 },
997 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -0700998 "tcpdump port 22",
Andrew Mortonece80492014-05-22 10:16:46 -0700999 .u.insns = {
Daniel Borkmannce25b682014-05-26 20:17:35 +02001000 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1001 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
1002 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
1003 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1004 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1005 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
1006 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
1007 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
1008 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
1009 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
1010 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
1011 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1012 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
1013 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
1014 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
1015 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1016 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
1017 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1018 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1019 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1020 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1021 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
1022 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1023 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001024 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001025 CLASSIC,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001026 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
1027 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
1028 * seq 1305692979:1305693027, ack 3650467037, win 65535,
1029 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
1030 */
1031 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1032 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1033 0x08, 0x00,
1034 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1035 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1036 0x0a, 0x01, 0x01, 0x95, /* ip src */
1037 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1038 0xc2, 0x24,
1039 0x00, 0x16 /* dst port */ },
1040 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1041 },
1042 {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001043 "tcpdump complex",
Andrew Mortonece80492014-05-22 10:16:46 -07001044 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001045 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
1046 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
1047 * (len > 115 or len < 30000000000)' -d
1048 */
Daniel Borkmannce25b682014-05-26 20:17:35 +02001049 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
1050 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
1051 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
1052 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
1053 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
1054 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
1055 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
1056 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1057 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
1058 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
1059 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
1060 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
1061 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
1062 BPF_STMT(BPF_ST, 1),
1063 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
1064 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
1065 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
1066 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
1067 BPF_STMT(BPF_LD | BPF_MEM, 1),
1068 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
1069 BPF_STMT(BPF_ST, 5),
1070 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
1071 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
1072 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
1073 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
1074 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
1075 BPF_STMT(BPF_LD | BPF_MEM, 5),
1076 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
1077 BPF_STMT(BPF_LD | BPF_LEN, 0),
1078 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
1079 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
1080 BPF_STMT(BPF_RET | BPF_K, 0xffff),
1081 BPF_STMT(BPF_RET | BPF_K, 0),
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001082 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001083 CLASSIC,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001084 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
1085 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
1086 0x08, 0x00,
1087 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
1088 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
1089 0x0a, 0x01, 0x01, 0x95, /* ip src */
1090 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
1091 0xc2, 0x24,
1092 0x00, 0x16 /* dst port */ },
1093 { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
1094 },
1095 {
1096 "RET_A",
Andrew Mortonece80492014-05-22 10:16:46 -07001097 .u.insns = {
Zhen Lei53b0fe32021-07-07 18:07:28 -07001098 /* check that uninitialized X and A contain zeros */
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001099 BPF_STMT(BPF_MISC | BPF_TXA, 0),
1100 BPF_STMT(BPF_RET | BPF_A, 0)
1101 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001102 CLASSIC,
1103 { },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001104 { {1, 0}, {2, 0} },
1105 },
1106 {
1107 "INT: ADD trivial",
Andrew Mortonece80492014-05-22 10:16:46 -07001108 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001109 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1110 BPF_ALU64_IMM(BPF_ADD, R1, 2),
1111 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1112 BPF_ALU64_REG(BPF_SUB, R1, R2),
1113 BPF_ALU64_IMM(BPF_ADD, R1, -1),
1114 BPF_ALU64_IMM(BPF_MUL, R1, 3),
1115 BPF_ALU64_REG(BPF_MOV, R0, R1),
1116 BPF_EXIT_INSN(),
1117 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001118 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001119 { },
1120 { { 0, 0xfffffffd } }
1121 },
1122 {
1123 "INT: MUL_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001124 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001125 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1126 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1127 BPF_ALU64_IMM(BPF_MOV, R2, 3),
1128 BPF_ALU64_REG(BPF_MUL, R1, R2),
1129 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
1130 BPF_EXIT_INSN(),
1131 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1132 BPF_EXIT_INSN(),
1133 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001134 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001135 { },
1136 { { 0, 1 } }
1137 },
1138 {
1139 "INT: MUL_X2",
Andrew Mortonece80492014-05-22 10:16:46 -07001140 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001141 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1142 BPF_ALU32_IMM(BPF_MOV, R1, -1),
1143 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1144 BPF_ALU64_REG(BPF_MUL, R1, R2),
1145 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1146 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
1147 BPF_EXIT_INSN(),
1148 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1149 BPF_EXIT_INSN(),
1150 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001151 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001152 { },
1153 { { 0, 1 } }
1154 },
1155 {
1156 "INT: MUL32_X",
Andrew Mortonece80492014-05-22 10:16:46 -07001157 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001158 BPF_ALU32_IMM(BPF_MOV, R0, -1),
1159 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1160 BPF_ALU32_IMM(BPF_MOV, R2, 3),
1161 BPF_ALU32_REG(BPF_MUL, R1, R2),
1162 BPF_ALU64_IMM(BPF_RSH, R1, 8),
1163 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
1164 BPF_EXIT_INSN(),
1165 BPF_ALU32_IMM(BPF_MOV, R0, 1),
1166 BPF_EXIT_INSN(),
1167 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001168 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001169 { },
1170 { { 0, 1 } }
1171 },
1172 {
1173 /* Have to test all register combinations, since
1174 * JITing of different registers will produce
1175 * different asm code.
1176 */
1177 "INT: ADD 64-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001178 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001179 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1180 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1181 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1182 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1183 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1184 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1185 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1186 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1187 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1188 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1189 BPF_ALU64_IMM(BPF_ADD, R0, 20),
1190 BPF_ALU64_IMM(BPF_ADD, R1, 20),
1191 BPF_ALU64_IMM(BPF_ADD, R2, 20),
1192 BPF_ALU64_IMM(BPF_ADD, R3, 20),
1193 BPF_ALU64_IMM(BPF_ADD, R4, 20),
1194 BPF_ALU64_IMM(BPF_ADD, R5, 20),
1195 BPF_ALU64_IMM(BPF_ADD, R6, 20),
1196 BPF_ALU64_IMM(BPF_ADD, R7, 20),
1197 BPF_ALU64_IMM(BPF_ADD, R8, 20),
1198 BPF_ALU64_IMM(BPF_ADD, R9, 20),
1199 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1200 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1201 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1202 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1203 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1204 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1205 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1206 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1207 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1208 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1209 BPF_ALU64_REG(BPF_ADD, R0, R0),
1210 BPF_ALU64_REG(BPF_ADD, R0, R1),
1211 BPF_ALU64_REG(BPF_ADD, R0, R2),
1212 BPF_ALU64_REG(BPF_ADD, R0, R3),
1213 BPF_ALU64_REG(BPF_ADD, R0, R4),
1214 BPF_ALU64_REG(BPF_ADD, R0, R5),
1215 BPF_ALU64_REG(BPF_ADD, R0, R6),
1216 BPF_ALU64_REG(BPF_ADD, R0, R7),
1217 BPF_ALU64_REG(BPF_ADD, R0, R8),
1218 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1219 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1220 BPF_EXIT_INSN(),
1221 BPF_ALU64_REG(BPF_ADD, R1, R0),
1222 BPF_ALU64_REG(BPF_ADD, R1, R1),
1223 BPF_ALU64_REG(BPF_ADD, R1, R2),
1224 BPF_ALU64_REG(BPF_ADD, R1, R3),
1225 BPF_ALU64_REG(BPF_ADD, R1, R4),
1226 BPF_ALU64_REG(BPF_ADD, R1, R5),
1227 BPF_ALU64_REG(BPF_ADD, R1, R6),
1228 BPF_ALU64_REG(BPF_ADD, R1, R7),
1229 BPF_ALU64_REG(BPF_ADD, R1, R8),
1230 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1231 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1232 BPF_EXIT_INSN(),
1233 BPF_ALU64_REG(BPF_ADD, R2, R0),
1234 BPF_ALU64_REG(BPF_ADD, R2, R1),
1235 BPF_ALU64_REG(BPF_ADD, R2, R2),
1236 BPF_ALU64_REG(BPF_ADD, R2, R3),
1237 BPF_ALU64_REG(BPF_ADD, R2, R4),
1238 BPF_ALU64_REG(BPF_ADD, R2, R5),
1239 BPF_ALU64_REG(BPF_ADD, R2, R6),
1240 BPF_ALU64_REG(BPF_ADD, R2, R7),
1241 BPF_ALU64_REG(BPF_ADD, R2, R8),
1242 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1243 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1244 BPF_EXIT_INSN(),
1245 BPF_ALU64_REG(BPF_ADD, R3, R0),
1246 BPF_ALU64_REG(BPF_ADD, R3, R1),
1247 BPF_ALU64_REG(BPF_ADD, R3, R2),
1248 BPF_ALU64_REG(BPF_ADD, R3, R3),
1249 BPF_ALU64_REG(BPF_ADD, R3, R4),
1250 BPF_ALU64_REG(BPF_ADD, R3, R5),
1251 BPF_ALU64_REG(BPF_ADD, R3, R6),
1252 BPF_ALU64_REG(BPF_ADD, R3, R7),
1253 BPF_ALU64_REG(BPF_ADD, R3, R8),
1254 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1255 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1256 BPF_EXIT_INSN(),
1257 BPF_ALU64_REG(BPF_ADD, R4, R0),
1258 BPF_ALU64_REG(BPF_ADD, R4, R1),
1259 BPF_ALU64_REG(BPF_ADD, R4, R2),
1260 BPF_ALU64_REG(BPF_ADD, R4, R3),
1261 BPF_ALU64_REG(BPF_ADD, R4, R4),
1262 BPF_ALU64_REG(BPF_ADD, R4, R5),
1263 BPF_ALU64_REG(BPF_ADD, R4, R6),
1264 BPF_ALU64_REG(BPF_ADD, R4, R7),
1265 BPF_ALU64_REG(BPF_ADD, R4, R8),
1266 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1267 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1268 BPF_EXIT_INSN(),
1269 BPF_ALU64_REG(BPF_ADD, R5, R0),
1270 BPF_ALU64_REG(BPF_ADD, R5, R1),
1271 BPF_ALU64_REG(BPF_ADD, R5, R2),
1272 BPF_ALU64_REG(BPF_ADD, R5, R3),
1273 BPF_ALU64_REG(BPF_ADD, R5, R4),
1274 BPF_ALU64_REG(BPF_ADD, R5, R5),
1275 BPF_ALU64_REG(BPF_ADD, R5, R6),
1276 BPF_ALU64_REG(BPF_ADD, R5, R7),
1277 BPF_ALU64_REG(BPF_ADD, R5, R8),
1278 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1279 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1280 BPF_EXIT_INSN(),
1281 BPF_ALU64_REG(BPF_ADD, R6, R0),
1282 BPF_ALU64_REG(BPF_ADD, R6, R1),
1283 BPF_ALU64_REG(BPF_ADD, R6, R2),
1284 BPF_ALU64_REG(BPF_ADD, R6, R3),
1285 BPF_ALU64_REG(BPF_ADD, R6, R4),
1286 BPF_ALU64_REG(BPF_ADD, R6, R5),
1287 BPF_ALU64_REG(BPF_ADD, R6, R6),
1288 BPF_ALU64_REG(BPF_ADD, R6, R7),
1289 BPF_ALU64_REG(BPF_ADD, R6, R8),
1290 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1291 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1292 BPF_EXIT_INSN(),
1293 BPF_ALU64_REG(BPF_ADD, R7, R0),
1294 BPF_ALU64_REG(BPF_ADD, R7, R1),
1295 BPF_ALU64_REG(BPF_ADD, R7, R2),
1296 BPF_ALU64_REG(BPF_ADD, R7, R3),
1297 BPF_ALU64_REG(BPF_ADD, R7, R4),
1298 BPF_ALU64_REG(BPF_ADD, R7, R5),
1299 BPF_ALU64_REG(BPF_ADD, R7, R6),
1300 BPF_ALU64_REG(BPF_ADD, R7, R7),
1301 BPF_ALU64_REG(BPF_ADD, R7, R8),
1302 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1303 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1304 BPF_EXIT_INSN(),
1305 BPF_ALU64_REG(BPF_ADD, R8, R0),
1306 BPF_ALU64_REG(BPF_ADD, R8, R1),
1307 BPF_ALU64_REG(BPF_ADD, R8, R2),
1308 BPF_ALU64_REG(BPF_ADD, R8, R3),
1309 BPF_ALU64_REG(BPF_ADD, R8, R4),
1310 BPF_ALU64_REG(BPF_ADD, R8, R5),
1311 BPF_ALU64_REG(BPF_ADD, R8, R6),
1312 BPF_ALU64_REG(BPF_ADD, R8, R7),
1313 BPF_ALU64_REG(BPF_ADD, R8, R8),
1314 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1315 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1316 BPF_EXIT_INSN(),
1317 BPF_ALU64_REG(BPF_ADD, R9, R0),
1318 BPF_ALU64_REG(BPF_ADD, R9, R1),
1319 BPF_ALU64_REG(BPF_ADD, R9, R2),
1320 BPF_ALU64_REG(BPF_ADD, R9, R3),
1321 BPF_ALU64_REG(BPF_ADD, R9, R4),
1322 BPF_ALU64_REG(BPF_ADD, R9, R5),
1323 BPF_ALU64_REG(BPF_ADD, R9, R6),
1324 BPF_ALU64_REG(BPF_ADD, R9, R7),
1325 BPF_ALU64_REG(BPF_ADD, R9, R8),
1326 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1327 BPF_ALU64_REG(BPF_MOV, R0, R9),
1328 BPF_EXIT_INSN(),
1329 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001330 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001331 { },
1332 { { 0, 2957380 } }
1333 },
1334 {
1335 "INT: ADD 32-bit",
Andrew Mortonece80492014-05-22 10:16:46 -07001336 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001337 BPF_ALU32_IMM(BPF_MOV, R0, 20),
1338 BPF_ALU32_IMM(BPF_MOV, R1, 1),
1339 BPF_ALU32_IMM(BPF_MOV, R2, 2),
1340 BPF_ALU32_IMM(BPF_MOV, R3, 3),
1341 BPF_ALU32_IMM(BPF_MOV, R4, 4),
1342 BPF_ALU32_IMM(BPF_MOV, R5, 5),
1343 BPF_ALU32_IMM(BPF_MOV, R6, 6),
1344 BPF_ALU32_IMM(BPF_MOV, R7, 7),
1345 BPF_ALU32_IMM(BPF_MOV, R8, 8),
1346 BPF_ALU32_IMM(BPF_MOV, R9, 9),
1347 BPF_ALU64_IMM(BPF_ADD, R1, 10),
1348 BPF_ALU64_IMM(BPF_ADD, R2, 10),
1349 BPF_ALU64_IMM(BPF_ADD, R3, 10),
1350 BPF_ALU64_IMM(BPF_ADD, R4, 10),
1351 BPF_ALU64_IMM(BPF_ADD, R5, 10),
1352 BPF_ALU64_IMM(BPF_ADD, R6, 10),
1353 BPF_ALU64_IMM(BPF_ADD, R7, 10),
1354 BPF_ALU64_IMM(BPF_ADD, R8, 10),
1355 BPF_ALU64_IMM(BPF_ADD, R9, 10),
1356 BPF_ALU32_REG(BPF_ADD, R0, R1),
1357 BPF_ALU32_REG(BPF_ADD, R0, R2),
1358 BPF_ALU32_REG(BPF_ADD, R0, R3),
1359 BPF_ALU32_REG(BPF_ADD, R0, R4),
1360 BPF_ALU32_REG(BPF_ADD, R0, R5),
1361 BPF_ALU32_REG(BPF_ADD, R0, R6),
1362 BPF_ALU32_REG(BPF_ADD, R0, R7),
1363 BPF_ALU32_REG(BPF_ADD, R0, R8),
1364 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
1365 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
1366 BPF_EXIT_INSN(),
1367 BPF_ALU32_REG(BPF_ADD, R1, R0),
1368 BPF_ALU32_REG(BPF_ADD, R1, R1),
1369 BPF_ALU32_REG(BPF_ADD, R1, R2),
1370 BPF_ALU32_REG(BPF_ADD, R1, R3),
1371 BPF_ALU32_REG(BPF_ADD, R1, R4),
1372 BPF_ALU32_REG(BPF_ADD, R1, R5),
1373 BPF_ALU32_REG(BPF_ADD, R1, R6),
1374 BPF_ALU32_REG(BPF_ADD, R1, R7),
1375 BPF_ALU32_REG(BPF_ADD, R1, R8),
1376 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
1377 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
1378 BPF_EXIT_INSN(),
1379 BPF_ALU32_REG(BPF_ADD, R2, R0),
1380 BPF_ALU32_REG(BPF_ADD, R2, R1),
1381 BPF_ALU32_REG(BPF_ADD, R2, R2),
1382 BPF_ALU32_REG(BPF_ADD, R2, R3),
1383 BPF_ALU32_REG(BPF_ADD, R2, R4),
1384 BPF_ALU32_REG(BPF_ADD, R2, R5),
1385 BPF_ALU32_REG(BPF_ADD, R2, R6),
1386 BPF_ALU32_REG(BPF_ADD, R2, R7),
1387 BPF_ALU32_REG(BPF_ADD, R2, R8),
1388 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
1389 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
1390 BPF_EXIT_INSN(),
1391 BPF_ALU32_REG(BPF_ADD, R3, R0),
1392 BPF_ALU32_REG(BPF_ADD, R3, R1),
1393 BPF_ALU32_REG(BPF_ADD, R3, R2),
1394 BPF_ALU32_REG(BPF_ADD, R3, R3),
1395 BPF_ALU32_REG(BPF_ADD, R3, R4),
1396 BPF_ALU32_REG(BPF_ADD, R3, R5),
1397 BPF_ALU32_REG(BPF_ADD, R3, R6),
1398 BPF_ALU32_REG(BPF_ADD, R3, R7),
1399 BPF_ALU32_REG(BPF_ADD, R3, R8),
1400 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
1401 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
1402 BPF_EXIT_INSN(),
1403 BPF_ALU32_REG(BPF_ADD, R4, R0),
1404 BPF_ALU32_REG(BPF_ADD, R4, R1),
1405 BPF_ALU32_REG(BPF_ADD, R4, R2),
1406 BPF_ALU32_REG(BPF_ADD, R4, R3),
1407 BPF_ALU32_REG(BPF_ADD, R4, R4),
1408 BPF_ALU32_REG(BPF_ADD, R4, R5),
1409 BPF_ALU32_REG(BPF_ADD, R4, R6),
1410 BPF_ALU32_REG(BPF_ADD, R4, R7),
1411 BPF_ALU32_REG(BPF_ADD, R4, R8),
1412 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
1413 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
1414 BPF_EXIT_INSN(),
1415 BPF_ALU32_REG(BPF_ADD, R5, R0),
1416 BPF_ALU32_REG(BPF_ADD, R5, R1),
1417 BPF_ALU32_REG(BPF_ADD, R5, R2),
1418 BPF_ALU32_REG(BPF_ADD, R5, R3),
1419 BPF_ALU32_REG(BPF_ADD, R5, R4),
1420 BPF_ALU32_REG(BPF_ADD, R5, R5),
1421 BPF_ALU32_REG(BPF_ADD, R5, R6),
1422 BPF_ALU32_REG(BPF_ADD, R5, R7),
1423 BPF_ALU32_REG(BPF_ADD, R5, R8),
1424 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
1425 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
1426 BPF_EXIT_INSN(),
1427 BPF_ALU32_REG(BPF_ADD, R6, R0),
1428 BPF_ALU32_REG(BPF_ADD, R6, R1),
1429 BPF_ALU32_REG(BPF_ADD, R6, R2),
1430 BPF_ALU32_REG(BPF_ADD, R6, R3),
1431 BPF_ALU32_REG(BPF_ADD, R6, R4),
1432 BPF_ALU32_REG(BPF_ADD, R6, R5),
1433 BPF_ALU32_REG(BPF_ADD, R6, R6),
1434 BPF_ALU32_REG(BPF_ADD, R6, R7),
1435 BPF_ALU32_REG(BPF_ADD, R6, R8),
1436 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
1437 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
1438 BPF_EXIT_INSN(),
1439 BPF_ALU32_REG(BPF_ADD, R7, R0),
1440 BPF_ALU32_REG(BPF_ADD, R7, R1),
1441 BPF_ALU32_REG(BPF_ADD, R7, R2),
1442 BPF_ALU32_REG(BPF_ADD, R7, R3),
1443 BPF_ALU32_REG(BPF_ADD, R7, R4),
1444 BPF_ALU32_REG(BPF_ADD, R7, R5),
1445 BPF_ALU32_REG(BPF_ADD, R7, R6),
1446 BPF_ALU32_REG(BPF_ADD, R7, R7),
1447 BPF_ALU32_REG(BPF_ADD, R7, R8),
1448 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
1449 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
1450 BPF_EXIT_INSN(),
1451 BPF_ALU32_REG(BPF_ADD, R8, R0),
1452 BPF_ALU32_REG(BPF_ADD, R8, R1),
1453 BPF_ALU32_REG(BPF_ADD, R8, R2),
1454 BPF_ALU32_REG(BPF_ADD, R8, R3),
1455 BPF_ALU32_REG(BPF_ADD, R8, R4),
1456 BPF_ALU32_REG(BPF_ADD, R8, R5),
1457 BPF_ALU32_REG(BPF_ADD, R8, R6),
1458 BPF_ALU32_REG(BPF_ADD, R8, R7),
1459 BPF_ALU32_REG(BPF_ADD, R8, R8),
1460 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
1461 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
1462 BPF_EXIT_INSN(),
1463 BPF_ALU32_REG(BPF_ADD, R9, R0),
1464 BPF_ALU32_REG(BPF_ADD, R9, R1),
1465 BPF_ALU32_REG(BPF_ADD, R9, R2),
1466 BPF_ALU32_REG(BPF_ADD, R9, R3),
1467 BPF_ALU32_REG(BPF_ADD, R9, R4),
1468 BPF_ALU32_REG(BPF_ADD, R9, R5),
1469 BPF_ALU32_REG(BPF_ADD, R9, R6),
1470 BPF_ALU32_REG(BPF_ADD, R9, R7),
1471 BPF_ALU32_REG(BPF_ADD, R9, R8),
1472 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
1473 BPF_ALU32_REG(BPF_MOV, R0, R9),
1474 BPF_EXIT_INSN(),
1475 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001476 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001477 { },
1478 { { 0, 2957380 } }
1479 },
1480 { /* Mainly checking JIT here. */
1481 "INT: SUB",
Andrew Mortonece80492014-05-22 10:16:46 -07001482 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001483 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1484 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1485 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1486 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1487 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1488 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1489 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1490 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1491 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1492 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1493 BPF_ALU64_REG(BPF_SUB, R0, R0),
1494 BPF_ALU64_REG(BPF_SUB, R0, R1),
1495 BPF_ALU64_REG(BPF_SUB, R0, R2),
1496 BPF_ALU64_REG(BPF_SUB, R0, R3),
1497 BPF_ALU64_REG(BPF_SUB, R0, R4),
1498 BPF_ALU64_REG(BPF_SUB, R0, R5),
1499 BPF_ALU64_REG(BPF_SUB, R0, R6),
1500 BPF_ALU64_REG(BPF_SUB, R0, R7),
1501 BPF_ALU64_REG(BPF_SUB, R0, R8),
1502 BPF_ALU64_REG(BPF_SUB, R0, R9),
1503 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1504 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
1505 BPF_EXIT_INSN(),
1506 BPF_ALU64_REG(BPF_SUB, R1, R0),
1507 BPF_ALU64_REG(BPF_SUB, R1, R2),
1508 BPF_ALU64_REG(BPF_SUB, R1, R3),
1509 BPF_ALU64_REG(BPF_SUB, R1, R4),
1510 BPF_ALU64_REG(BPF_SUB, R1, R5),
1511 BPF_ALU64_REG(BPF_SUB, R1, R6),
1512 BPF_ALU64_REG(BPF_SUB, R1, R7),
1513 BPF_ALU64_REG(BPF_SUB, R1, R8),
1514 BPF_ALU64_REG(BPF_SUB, R1, R9),
1515 BPF_ALU64_IMM(BPF_SUB, R1, 10),
1516 BPF_ALU64_REG(BPF_SUB, R2, R0),
1517 BPF_ALU64_REG(BPF_SUB, R2, R1),
1518 BPF_ALU64_REG(BPF_SUB, R2, R3),
1519 BPF_ALU64_REG(BPF_SUB, R2, R4),
1520 BPF_ALU64_REG(BPF_SUB, R2, R5),
1521 BPF_ALU64_REG(BPF_SUB, R2, R6),
1522 BPF_ALU64_REG(BPF_SUB, R2, R7),
1523 BPF_ALU64_REG(BPF_SUB, R2, R8),
1524 BPF_ALU64_REG(BPF_SUB, R2, R9),
1525 BPF_ALU64_IMM(BPF_SUB, R2, 10),
1526 BPF_ALU64_REG(BPF_SUB, R3, R0),
1527 BPF_ALU64_REG(BPF_SUB, R3, R1),
1528 BPF_ALU64_REG(BPF_SUB, R3, R2),
1529 BPF_ALU64_REG(BPF_SUB, R3, R4),
1530 BPF_ALU64_REG(BPF_SUB, R3, R5),
1531 BPF_ALU64_REG(BPF_SUB, R3, R6),
1532 BPF_ALU64_REG(BPF_SUB, R3, R7),
1533 BPF_ALU64_REG(BPF_SUB, R3, R8),
1534 BPF_ALU64_REG(BPF_SUB, R3, R9),
1535 BPF_ALU64_IMM(BPF_SUB, R3, 10),
1536 BPF_ALU64_REG(BPF_SUB, R4, R0),
1537 BPF_ALU64_REG(BPF_SUB, R4, R1),
1538 BPF_ALU64_REG(BPF_SUB, R4, R2),
1539 BPF_ALU64_REG(BPF_SUB, R4, R3),
1540 BPF_ALU64_REG(BPF_SUB, R4, R5),
1541 BPF_ALU64_REG(BPF_SUB, R4, R6),
1542 BPF_ALU64_REG(BPF_SUB, R4, R7),
1543 BPF_ALU64_REG(BPF_SUB, R4, R8),
1544 BPF_ALU64_REG(BPF_SUB, R4, R9),
1545 BPF_ALU64_IMM(BPF_SUB, R4, 10),
1546 BPF_ALU64_REG(BPF_SUB, R5, R0),
1547 BPF_ALU64_REG(BPF_SUB, R5, R1),
1548 BPF_ALU64_REG(BPF_SUB, R5, R2),
1549 BPF_ALU64_REG(BPF_SUB, R5, R3),
1550 BPF_ALU64_REG(BPF_SUB, R5, R4),
1551 BPF_ALU64_REG(BPF_SUB, R5, R6),
1552 BPF_ALU64_REG(BPF_SUB, R5, R7),
1553 BPF_ALU64_REG(BPF_SUB, R5, R8),
1554 BPF_ALU64_REG(BPF_SUB, R5, R9),
1555 BPF_ALU64_IMM(BPF_SUB, R5, 10),
1556 BPF_ALU64_REG(BPF_SUB, R6, R0),
1557 BPF_ALU64_REG(BPF_SUB, R6, R1),
1558 BPF_ALU64_REG(BPF_SUB, R6, R2),
1559 BPF_ALU64_REG(BPF_SUB, R6, R3),
1560 BPF_ALU64_REG(BPF_SUB, R6, R4),
1561 BPF_ALU64_REG(BPF_SUB, R6, R5),
1562 BPF_ALU64_REG(BPF_SUB, R6, R7),
1563 BPF_ALU64_REG(BPF_SUB, R6, R8),
1564 BPF_ALU64_REG(BPF_SUB, R6, R9),
1565 BPF_ALU64_IMM(BPF_SUB, R6, 10),
1566 BPF_ALU64_REG(BPF_SUB, R7, R0),
1567 BPF_ALU64_REG(BPF_SUB, R7, R1),
1568 BPF_ALU64_REG(BPF_SUB, R7, R2),
1569 BPF_ALU64_REG(BPF_SUB, R7, R3),
1570 BPF_ALU64_REG(BPF_SUB, R7, R4),
1571 BPF_ALU64_REG(BPF_SUB, R7, R5),
1572 BPF_ALU64_REG(BPF_SUB, R7, R6),
1573 BPF_ALU64_REG(BPF_SUB, R7, R8),
1574 BPF_ALU64_REG(BPF_SUB, R7, R9),
1575 BPF_ALU64_IMM(BPF_SUB, R7, 10),
1576 BPF_ALU64_REG(BPF_SUB, R8, R0),
1577 BPF_ALU64_REG(BPF_SUB, R8, R1),
1578 BPF_ALU64_REG(BPF_SUB, R8, R2),
1579 BPF_ALU64_REG(BPF_SUB, R8, R3),
1580 BPF_ALU64_REG(BPF_SUB, R8, R4),
1581 BPF_ALU64_REG(BPF_SUB, R8, R5),
1582 BPF_ALU64_REG(BPF_SUB, R8, R6),
1583 BPF_ALU64_REG(BPF_SUB, R8, R7),
1584 BPF_ALU64_REG(BPF_SUB, R8, R9),
1585 BPF_ALU64_IMM(BPF_SUB, R8, 10),
1586 BPF_ALU64_REG(BPF_SUB, R9, R0),
1587 BPF_ALU64_REG(BPF_SUB, R9, R1),
1588 BPF_ALU64_REG(BPF_SUB, R9, R2),
1589 BPF_ALU64_REG(BPF_SUB, R9, R3),
1590 BPF_ALU64_REG(BPF_SUB, R9, R4),
1591 BPF_ALU64_REG(BPF_SUB, R9, R5),
1592 BPF_ALU64_REG(BPF_SUB, R9, R6),
1593 BPF_ALU64_REG(BPF_SUB, R9, R7),
1594 BPF_ALU64_REG(BPF_SUB, R9, R8),
1595 BPF_ALU64_IMM(BPF_SUB, R9, 10),
1596 BPF_ALU64_IMM(BPF_SUB, R0, 10),
1597 BPF_ALU64_IMM(BPF_NEG, R0, 0),
1598 BPF_ALU64_REG(BPF_SUB, R0, R1),
1599 BPF_ALU64_REG(BPF_SUB, R0, R2),
1600 BPF_ALU64_REG(BPF_SUB, R0, R3),
1601 BPF_ALU64_REG(BPF_SUB, R0, R4),
1602 BPF_ALU64_REG(BPF_SUB, R0, R5),
1603 BPF_ALU64_REG(BPF_SUB, R0, R6),
1604 BPF_ALU64_REG(BPF_SUB, R0, R7),
1605 BPF_ALU64_REG(BPF_SUB, R0, R8),
1606 BPF_ALU64_REG(BPF_SUB, R0, R9),
1607 BPF_EXIT_INSN(),
1608 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001609 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001610 { },
1611 { { 0, 11 } }
1612 },
1613 { /* Mainly checking JIT here. */
1614 "INT: XOR",
Andrew Mortonece80492014-05-22 10:16:46 -07001615 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001616 BPF_ALU64_REG(BPF_SUB, R0, R0),
1617 BPF_ALU64_REG(BPF_XOR, R1, R1),
1618 BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
1619 BPF_EXIT_INSN(),
1620 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1621 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1622 BPF_ALU64_REG(BPF_SUB, R1, R1),
1623 BPF_ALU64_REG(BPF_XOR, R2, R2),
1624 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
1625 BPF_EXIT_INSN(),
1626 BPF_ALU64_REG(BPF_SUB, R2, R2),
1627 BPF_ALU64_REG(BPF_XOR, R3, R3),
1628 BPF_ALU64_IMM(BPF_MOV, R0, 10),
1629 BPF_ALU64_IMM(BPF_MOV, R1, -1),
1630 BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
1631 BPF_EXIT_INSN(),
1632 BPF_ALU64_REG(BPF_SUB, R3, R3),
1633 BPF_ALU64_REG(BPF_XOR, R4, R4),
1634 BPF_ALU64_IMM(BPF_MOV, R2, 1),
1635 BPF_ALU64_IMM(BPF_MOV, R5, -1),
1636 BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
1637 BPF_EXIT_INSN(),
1638 BPF_ALU64_REG(BPF_SUB, R4, R4),
1639 BPF_ALU64_REG(BPF_XOR, R5, R5),
1640 BPF_ALU64_IMM(BPF_MOV, R3, 1),
1641 BPF_ALU64_IMM(BPF_MOV, R7, -1),
1642 BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
1643 BPF_EXIT_INSN(),
1644 BPF_ALU64_IMM(BPF_MOV, R5, 1),
1645 BPF_ALU64_REG(BPF_SUB, R5, R5),
1646 BPF_ALU64_REG(BPF_XOR, R6, R6),
1647 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1648 BPF_ALU64_IMM(BPF_MOV, R8, -1),
1649 BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
1650 BPF_EXIT_INSN(),
1651 BPF_ALU64_REG(BPF_SUB, R6, R6),
1652 BPF_ALU64_REG(BPF_XOR, R7, R7),
1653 BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
1654 BPF_EXIT_INSN(),
1655 BPF_ALU64_REG(BPF_SUB, R7, R7),
1656 BPF_ALU64_REG(BPF_XOR, R8, R8),
1657 BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
1658 BPF_EXIT_INSN(),
1659 BPF_ALU64_REG(BPF_SUB, R8, R8),
1660 BPF_ALU64_REG(BPF_XOR, R9, R9),
1661 BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
1662 BPF_EXIT_INSN(),
1663 BPF_ALU64_REG(BPF_SUB, R9, R9),
1664 BPF_ALU64_REG(BPF_XOR, R0, R0),
1665 BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
1666 BPF_EXIT_INSN(),
1667 BPF_ALU64_REG(BPF_SUB, R1, R1),
1668 BPF_ALU64_REG(BPF_XOR, R0, R0),
1669 BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
1670 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1671 BPF_EXIT_INSN(),
1672 BPF_ALU64_IMM(BPF_MOV, R0, 1),
1673 BPF_EXIT_INSN(),
1674 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001675 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001676 { },
1677 { { 0, 1 } }
1678 },
1679 { /* Mainly checking JIT here. */
1680 "INT: MUL",
Andrew Mortonece80492014-05-22 10:16:46 -07001681 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001682 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1683 BPF_ALU64_IMM(BPF_MOV, R1, 1),
1684 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1685 BPF_ALU64_IMM(BPF_MOV, R3, 3),
1686 BPF_ALU64_IMM(BPF_MOV, R4, 4),
1687 BPF_ALU64_IMM(BPF_MOV, R5, 5),
1688 BPF_ALU64_IMM(BPF_MOV, R6, 6),
1689 BPF_ALU64_IMM(BPF_MOV, R7, 7),
1690 BPF_ALU64_IMM(BPF_MOV, R8, 8),
1691 BPF_ALU64_IMM(BPF_MOV, R9, 9),
1692 BPF_ALU64_REG(BPF_MUL, R0, R0),
1693 BPF_ALU64_REG(BPF_MUL, R0, R1),
1694 BPF_ALU64_REG(BPF_MUL, R0, R2),
1695 BPF_ALU64_REG(BPF_MUL, R0, R3),
1696 BPF_ALU64_REG(BPF_MUL, R0, R4),
1697 BPF_ALU64_REG(BPF_MUL, R0, R5),
1698 BPF_ALU64_REG(BPF_MUL, R0, R6),
1699 BPF_ALU64_REG(BPF_MUL, R0, R7),
1700 BPF_ALU64_REG(BPF_MUL, R0, R8),
1701 BPF_ALU64_REG(BPF_MUL, R0, R9),
1702 BPF_ALU64_IMM(BPF_MUL, R0, 10),
1703 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
1704 BPF_EXIT_INSN(),
1705 BPF_ALU64_REG(BPF_MUL, R1, R0),
1706 BPF_ALU64_REG(BPF_MUL, R1, R2),
1707 BPF_ALU64_REG(BPF_MUL, R1, R3),
1708 BPF_ALU64_REG(BPF_MUL, R1, R4),
1709 BPF_ALU64_REG(BPF_MUL, R1, R5),
1710 BPF_ALU64_REG(BPF_MUL, R1, R6),
1711 BPF_ALU64_REG(BPF_MUL, R1, R7),
1712 BPF_ALU64_REG(BPF_MUL, R1, R8),
1713 BPF_ALU64_REG(BPF_MUL, R1, R9),
1714 BPF_ALU64_IMM(BPF_MUL, R1, 10),
1715 BPF_ALU64_REG(BPF_MOV, R2, R1),
1716 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1717 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
1718 BPF_EXIT_INSN(),
1719 BPF_ALU64_IMM(BPF_LSH, R1, 32),
1720 BPF_ALU64_IMM(BPF_ARSH, R1, 32),
1721 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
1722 BPF_EXIT_INSN(),
1723 BPF_ALU64_REG(BPF_MUL, R2, R0),
1724 BPF_ALU64_REG(BPF_MUL, R2, R1),
1725 BPF_ALU64_REG(BPF_MUL, R2, R3),
1726 BPF_ALU64_REG(BPF_MUL, R2, R4),
1727 BPF_ALU64_REG(BPF_MUL, R2, R5),
1728 BPF_ALU64_REG(BPF_MUL, R2, R6),
1729 BPF_ALU64_REG(BPF_MUL, R2, R7),
1730 BPF_ALU64_REG(BPF_MUL, R2, R8),
1731 BPF_ALU64_REG(BPF_MUL, R2, R9),
1732 BPF_ALU64_IMM(BPF_MUL, R2, 10),
1733 BPF_ALU64_IMM(BPF_RSH, R2, 32),
1734 BPF_ALU64_REG(BPF_MOV, R0, R2),
1735 BPF_EXIT_INSN(),
1736 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001737 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001738 { },
1739 { { 0, 0x35d97ef2 } }
1740 },
Daniel Borkmann9dd2af82015-12-17 23:51:57 +01001741 { /* Mainly checking JIT here. */
1742 "MOV REG64",
1743 .u.insns_int = {
1744 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1745 BPF_MOV64_REG(R1, R0),
1746 BPF_MOV64_REG(R2, R1),
1747 BPF_MOV64_REG(R3, R2),
1748 BPF_MOV64_REG(R4, R3),
1749 BPF_MOV64_REG(R5, R4),
1750 BPF_MOV64_REG(R6, R5),
1751 BPF_MOV64_REG(R7, R6),
1752 BPF_MOV64_REG(R8, R7),
1753 BPF_MOV64_REG(R9, R8),
1754 BPF_ALU64_IMM(BPF_MOV, R0, 0),
1755 BPF_ALU64_IMM(BPF_MOV, R1, 0),
1756 BPF_ALU64_IMM(BPF_MOV, R2, 0),
1757 BPF_ALU64_IMM(BPF_MOV, R3, 0),
1758 BPF_ALU64_IMM(BPF_MOV, R4, 0),
1759 BPF_ALU64_IMM(BPF_MOV, R5, 0),
1760 BPF_ALU64_IMM(BPF_MOV, R6, 0),
1761 BPF_ALU64_IMM(BPF_MOV, R7, 0),
1762 BPF_ALU64_IMM(BPF_MOV, R8, 0),
1763 BPF_ALU64_IMM(BPF_MOV, R9, 0),
1764 BPF_ALU64_REG(BPF_ADD, R0, R0),
1765 BPF_ALU64_REG(BPF_ADD, R0, R1),
1766 BPF_ALU64_REG(BPF_ADD, R0, R2),
1767 BPF_ALU64_REG(BPF_ADD, R0, R3),
1768 BPF_ALU64_REG(BPF_ADD, R0, R4),
1769 BPF_ALU64_REG(BPF_ADD, R0, R5),
1770 BPF_ALU64_REG(BPF_ADD, R0, R6),
1771 BPF_ALU64_REG(BPF_ADD, R0, R7),
1772 BPF_ALU64_REG(BPF_ADD, R0, R8),
1773 BPF_ALU64_REG(BPF_ADD, R0, R9),
1774 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1775 BPF_EXIT_INSN(),
1776 },
1777 INTERNAL,
1778 { },
1779 { { 0, 0xfefe } }
1780 },
1781 { /* Mainly checking JIT here. */
1782 "MOV REG32",
1783 .u.insns_int = {
1784 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1785 BPF_MOV64_REG(R1, R0),
1786 BPF_MOV64_REG(R2, R1),
1787 BPF_MOV64_REG(R3, R2),
1788 BPF_MOV64_REG(R4, R3),
1789 BPF_MOV64_REG(R5, R4),
1790 BPF_MOV64_REG(R6, R5),
1791 BPF_MOV64_REG(R7, R6),
1792 BPF_MOV64_REG(R8, R7),
1793 BPF_MOV64_REG(R9, R8),
1794 BPF_ALU32_IMM(BPF_MOV, R0, 0),
1795 BPF_ALU32_IMM(BPF_MOV, R1, 0),
1796 BPF_ALU32_IMM(BPF_MOV, R2, 0),
1797 BPF_ALU32_IMM(BPF_MOV, R3, 0),
1798 BPF_ALU32_IMM(BPF_MOV, R4, 0),
1799 BPF_ALU32_IMM(BPF_MOV, R5, 0),
1800 BPF_ALU32_IMM(BPF_MOV, R6, 0),
1801 BPF_ALU32_IMM(BPF_MOV, R7, 0),
1802 BPF_ALU32_IMM(BPF_MOV, R8, 0),
1803 BPF_ALU32_IMM(BPF_MOV, R9, 0),
1804 BPF_ALU64_REG(BPF_ADD, R0, R0),
1805 BPF_ALU64_REG(BPF_ADD, R0, R1),
1806 BPF_ALU64_REG(BPF_ADD, R0, R2),
1807 BPF_ALU64_REG(BPF_ADD, R0, R3),
1808 BPF_ALU64_REG(BPF_ADD, R0, R4),
1809 BPF_ALU64_REG(BPF_ADD, R0, R5),
1810 BPF_ALU64_REG(BPF_ADD, R0, R6),
1811 BPF_ALU64_REG(BPF_ADD, R0, R7),
1812 BPF_ALU64_REG(BPF_ADD, R0, R8),
1813 BPF_ALU64_REG(BPF_ADD, R0, R9),
1814 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1815 BPF_EXIT_INSN(),
1816 },
1817 INTERNAL,
1818 { },
1819 { { 0, 0xfefe } }
1820 },
1821 { /* Mainly checking JIT here. */
1822 "LD IMM64",
1823 .u.insns_int = {
1824 BPF_LD_IMM64(R0, 0xffffffffffffffffLL),
1825 BPF_MOV64_REG(R1, R0),
1826 BPF_MOV64_REG(R2, R1),
1827 BPF_MOV64_REG(R3, R2),
1828 BPF_MOV64_REG(R4, R3),
1829 BPF_MOV64_REG(R5, R4),
1830 BPF_MOV64_REG(R6, R5),
1831 BPF_MOV64_REG(R7, R6),
1832 BPF_MOV64_REG(R8, R7),
1833 BPF_MOV64_REG(R9, R8),
1834 BPF_LD_IMM64(R0, 0x0LL),
1835 BPF_LD_IMM64(R1, 0x0LL),
1836 BPF_LD_IMM64(R2, 0x0LL),
1837 BPF_LD_IMM64(R3, 0x0LL),
1838 BPF_LD_IMM64(R4, 0x0LL),
1839 BPF_LD_IMM64(R5, 0x0LL),
1840 BPF_LD_IMM64(R6, 0x0LL),
1841 BPF_LD_IMM64(R7, 0x0LL),
1842 BPF_LD_IMM64(R8, 0x0LL),
1843 BPF_LD_IMM64(R9, 0x0LL),
1844 BPF_ALU64_REG(BPF_ADD, R0, R0),
1845 BPF_ALU64_REG(BPF_ADD, R0, R1),
1846 BPF_ALU64_REG(BPF_ADD, R0, R2),
1847 BPF_ALU64_REG(BPF_ADD, R0, R3),
1848 BPF_ALU64_REG(BPF_ADD, R0, R4),
1849 BPF_ALU64_REG(BPF_ADD, R0, R5),
1850 BPF_ALU64_REG(BPF_ADD, R0, R6),
1851 BPF_ALU64_REG(BPF_ADD, R0, R7),
1852 BPF_ALU64_REG(BPF_ADD, R0, R8),
1853 BPF_ALU64_REG(BPF_ADD, R0, R9),
1854 BPF_ALU64_IMM(BPF_ADD, R0, 0xfefe),
1855 BPF_EXIT_INSN(),
1856 },
1857 INTERNAL,
1858 { },
1859 { { 0, 0xfefe } }
1860 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001861 {
1862 "INT: ALU MIX",
Andrew Mortonece80492014-05-22 10:16:46 -07001863 .u.insns_int = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001864 BPF_ALU64_IMM(BPF_MOV, R0, 11),
1865 BPF_ALU64_IMM(BPF_ADD, R0, -1),
1866 BPF_ALU64_IMM(BPF_MOV, R2, 2),
1867 BPF_ALU64_IMM(BPF_XOR, R2, 3),
1868 BPF_ALU64_REG(BPF_DIV, R0, R2),
1869 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
1870 BPF_EXIT_INSN(),
1871 BPF_ALU64_IMM(BPF_MOD, R0, 3),
1872 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
1873 BPF_EXIT_INSN(),
1874 BPF_ALU64_IMM(BPF_MOV, R0, -1),
1875 BPF_EXIT_INSN(),
1876 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001877 INTERNAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001878 { },
1879 { { 0, -1 } }
1880 },
1881 {
Alexei Starovoitov72b603e2014-08-25 12:27:02 -07001882 "INT: shifts by register",
1883 .u.insns_int = {
1884 BPF_MOV64_IMM(R0, -1234),
1885 BPF_MOV64_IMM(R1, 1),
1886 BPF_ALU32_REG(BPF_RSH, R0, R1),
1887 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1),
1888 BPF_EXIT_INSN(),
1889 BPF_MOV64_IMM(R2, 1),
1890 BPF_ALU64_REG(BPF_LSH, R0, R2),
1891 BPF_MOV32_IMM(R4, -1234),
1892 BPF_JMP_REG(BPF_JEQ, R0, R4, 1),
1893 BPF_EXIT_INSN(),
1894 BPF_ALU64_IMM(BPF_AND, R4, 63),
1895 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */
1896 BPF_MOV64_IMM(R3, 47),
1897 BPF_ALU64_REG(BPF_ARSH, R0, R3),
1898 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1),
1899 BPF_EXIT_INSN(),
1900 BPF_MOV64_IMM(R2, 1),
1901 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */
1902 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1),
1903 BPF_EXIT_INSN(),
1904 BPF_MOV64_IMM(R4, 4),
1905 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */
1906 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1),
1907 BPF_EXIT_INSN(),
1908 BPF_MOV64_IMM(R4, 5),
1909 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */
1910 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1),
1911 BPF_EXIT_INSN(),
1912 BPF_MOV64_IMM(R0, -1),
1913 BPF_EXIT_INSN(),
1914 },
1915 INTERNAL,
1916 { },
1917 { { 0, -1 } }
1918 },
1919 {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001920 "check: missing ret",
Andrew Mortonece80492014-05-22 10:16:46 -07001921 .u.insns = {
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001922 BPF_STMT(BPF_LD | BPF_IMM, 1),
1923 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001924 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001925 { },
Yonghong Song09584b42018-02-02 22:37:15 -08001926 { },
1927 .fill_helper = NULL,
1928 .expected_errcode = -EINVAL,
Alexei Starovoitov64a89462014-05-08 14:10:52 -07001929 },
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001930 {
1931 "check: div_k_0",
Andrew Mortonece80492014-05-22 10:16:46 -07001932 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001933 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
1934 BPF_STMT(BPF_RET | BPF_K, 0)
1935 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001936 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001937 { },
Yonghong Song09584b42018-02-02 22:37:15 -08001938 { },
1939 .fill_helper = NULL,
1940 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001941 },
1942 {
1943 "check: unknown insn",
Andrew Mortonece80492014-05-22 10:16:46 -07001944 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001945 /* seccomp insn, rejected in socket filter */
1946 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
1947 BPF_STMT(BPF_RET | BPF_K, 0)
1948 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001949 CLASSIC | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001950 { },
Yonghong Song09584b42018-02-02 22:37:15 -08001951 { },
1952 .fill_helper = NULL,
1953 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001954 },
1955 {
1956 "check: out of range spill/fill",
Andrew Mortonece80492014-05-22 10:16:46 -07001957 .u.insns = {
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001958 BPF_STMT(BPF_STX, 16),
1959 BPF_STMT(BPF_RET | BPF_K, 0)
1960 },
Daniel Borkmann10f18e02014-05-23 18:44:00 +02001961 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001962 { },
Yonghong Song09584b42018-02-02 22:37:15 -08001963 { },
1964 .fill_helper = NULL,
1965 .expected_errcode = -EINVAL,
Alexei Starovoitov9def6242014-05-08 14:10:53 -07001966 },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02001967 {
1968 "JUMPS + HOLES",
1969 .u.insns = {
1970 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1971 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
1972 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1973 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1974 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1975 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1976 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1977 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1978 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
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_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
1986 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1987 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
1988 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1989 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
1990 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
1991 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1992 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1993 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1994 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1995 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1996 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
1997 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
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_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
2005 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
2006 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2007 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
2008 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
2009 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2010 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2011 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2012 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2013 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2014 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2015 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
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_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
2023 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
2024 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
2025 BPF_STMT(BPF_RET | BPF_A, 0),
2026 BPF_STMT(BPF_RET | BPF_A, 0),
2027 },
2028 CLASSIC,
Daniel Borkmannce25b682014-05-26 20:17:35 +02002029 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
2030 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
2031 0x08, 0x00,
2032 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
2033 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
2034 0xc0, 0xa8, 0x33, 0x01,
2035 0xc0, 0xa8, 0x33, 0x02,
2036 0xbb, 0xb6,
2037 0xa9, 0xfa,
2038 0x00, 0x14, 0x00, 0x00,
2039 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2040 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2041 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2042 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2043 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2044 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2045 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
2046 0xcc, 0xcc, 0xcc, 0xcc },
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002047 { { 88, 0x001b } }
2048 },
2049 {
2050 "check: RET X",
2051 .u.insns = {
2052 BPF_STMT(BPF_RET | BPF_X, 0),
2053 },
2054 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2055 { },
2056 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002057 .fill_helper = NULL,
2058 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002059 },
2060 {
2061 "check: LDX + RET X",
2062 .u.insns = {
2063 BPF_STMT(BPF_LDX | BPF_IMM, 42),
2064 BPF_STMT(BPF_RET | BPF_X, 0),
2065 },
2066 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2067 { },
2068 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002069 .fill_helper = NULL,
2070 .expected_errcode = -EINVAL,
Daniel Borkmann2e8a83c2014-05-23 18:44:01 +02002071 },
Daniel Borkmann108cc222014-05-26 20:17:34 +02002072 { /* Mainly checking JIT here. */
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002073 "M[]: alt STX + LDX",
Daniel Borkmann108cc222014-05-26 20:17:34 +02002074 .u.insns = {
2075 BPF_STMT(BPF_LDX | BPF_IMM, 100),
2076 BPF_STMT(BPF_STX, 0),
2077 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2078 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2079 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2080 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2081 BPF_STMT(BPF_STX, 1),
2082 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2083 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2084 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2085 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2086 BPF_STMT(BPF_STX, 2),
2087 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2088 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2089 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2090 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2091 BPF_STMT(BPF_STX, 3),
2092 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2093 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2094 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2095 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2096 BPF_STMT(BPF_STX, 4),
2097 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2098 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2099 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2100 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2101 BPF_STMT(BPF_STX, 5),
2102 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2103 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2104 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2105 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2106 BPF_STMT(BPF_STX, 6),
2107 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2108 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2109 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2110 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2111 BPF_STMT(BPF_STX, 7),
2112 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2113 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2114 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2115 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2116 BPF_STMT(BPF_STX, 8),
2117 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2118 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2119 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2120 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2121 BPF_STMT(BPF_STX, 9),
2122 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2123 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2124 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2125 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2126 BPF_STMT(BPF_STX, 10),
2127 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2128 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2129 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2130 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2131 BPF_STMT(BPF_STX, 11),
2132 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2133 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2134 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2135 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2136 BPF_STMT(BPF_STX, 12),
2137 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2138 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2139 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2140 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2141 BPF_STMT(BPF_STX, 13),
2142 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2143 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2144 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2145 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2146 BPF_STMT(BPF_STX, 14),
2147 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2148 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2149 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2150 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2151 BPF_STMT(BPF_STX, 15),
2152 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2153 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2154 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
2155 BPF_STMT(BPF_MISC | BPF_TAX, 0),
2156 BPF_STMT(BPF_RET | BPF_A, 0),
2157 },
2158 CLASSIC | FLAG_NO_DATA,
2159 { },
2160 { { 0, 116 } },
2161 },
Daniel Borkmann9fe13ba2014-05-29 10:22:48 +02002162 { /* Mainly checking JIT here. */
2163 "M[]: full STX + full LDX",
2164 .u.insns = {
2165 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
2166 BPF_STMT(BPF_STX, 0),
2167 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
2168 BPF_STMT(BPF_STX, 1),
2169 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
2170 BPF_STMT(BPF_STX, 2),
2171 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
2172 BPF_STMT(BPF_STX, 3),
2173 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
2174 BPF_STMT(BPF_STX, 4),
2175 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
2176 BPF_STMT(BPF_STX, 5),
2177 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
2178 BPF_STMT(BPF_STX, 6),
2179 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
2180 BPF_STMT(BPF_STX, 7),
2181 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
2182 BPF_STMT(BPF_STX, 8),
2183 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
2184 BPF_STMT(BPF_STX, 9),
2185 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
2186 BPF_STMT(BPF_STX, 10),
2187 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
2188 BPF_STMT(BPF_STX, 11),
2189 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
2190 BPF_STMT(BPF_STX, 12),
2191 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
2192 BPF_STMT(BPF_STX, 13),
2193 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
2194 BPF_STMT(BPF_STX, 14),
2195 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
2196 BPF_STMT(BPF_STX, 15),
2197 BPF_STMT(BPF_LDX | BPF_MEM, 0),
2198 BPF_STMT(BPF_MISC | BPF_TXA, 0),
2199 BPF_STMT(BPF_LDX | BPF_MEM, 1),
2200 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2201 BPF_STMT(BPF_LDX | BPF_MEM, 2),
2202 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2203 BPF_STMT(BPF_LDX | BPF_MEM, 3),
2204 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2205 BPF_STMT(BPF_LDX | BPF_MEM, 4),
2206 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2207 BPF_STMT(BPF_LDX | BPF_MEM, 5),
2208 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2209 BPF_STMT(BPF_LDX | BPF_MEM, 6),
2210 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2211 BPF_STMT(BPF_LDX | BPF_MEM, 7),
2212 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2213 BPF_STMT(BPF_LDX | BPF_MEM, 8),
2214 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2215 BPF_STMT(BPF_LDX | BPF_MEM, 9),
2216 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2217 BPF_STMT(BPF_LDX | BPF_MEM, 10),
2218 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2219 BPF_STMT(BPF_LDX | BPF_MEM, 11),
2220 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2221 BPF_STMT(BPF_LDX | BPF_MEM, 12),
2222 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2223 BPF_STMT(BPF_LDX | BPF_MEM, 13),
2224 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2225 BPF_STMT(BPF_LDX | BPF_MEM, 14),
2226 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2227 BPF_STMT(BPF_LDX | BPF_MEM, 15),
2228 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
2229 BPF_STMT(BPF_RET | BPF_A, 0),
2230 },
2231 CLASSIC | FLAG_NO_DATA,
2232 { },
2233 { { 0, 0x2a5a5e5 } },
2234 },
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002235 {
2236 "check: SKF_AD_MAX",
2237 .u.insns = {
2238 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2239 SKF_AD_OFF + SKF_AD_MAX),
2240 BPF_STMT(BPF_RET | BPF_A, 0),
2241 },
2242 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2243 { },
2244 { },
Yonghong Song09584b42018-02-02 22:37:15 -08002245 .fill_helper = NULL,
2246 .expected_errcode = -EINVAL,
Daniel Borkmannd50bc152014-05-29 10:22:49 +02002247 },
2248 { /* Passes checker but fails during runtime. */
2249 "LD [SKF_AD_OFF-1]",
2250 .u.insns = {
2251 BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
2252 SKF_AD_OFF - 1),
2253 BPF_STMT(BPF_RET | BPF_K, 1),
2254 },
2255 CLASSIC,
2256 { },
2257 { { 1, 0 } },
2258 },
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002259 {
2260 "load 64-bit immediate",
2261 .u.insns_int = {
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07002262 BPF_LD_IMM64(R1, 0x567800001234LL),
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002263 BPF_MOV64_REG(R2, R1),
2264 BPF_MOV64_REG(R3, R2),
2265 BPF_ALU64_IMM(BPF_RSH, R2, 32),
2266 BPF_ALU64_IMM(BPF_LSH, R3, 32),
2267 BPF_ALU64_IMM(BPF_RSH, R3, 32),
2268 BPF_ALU64_IMM(BPF_MOV, R0, 0),
2269 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1),
2270 BPF_EXIT_INSN(),
2271 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1),
2272 BPF_EXIT_INSN(),
Xi Wang986ccfd2015-05-09 04:14:30 -04002273 BPF_LD_IMM64(R0, 0x1ffffffffLL),
2274 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */
Alexei Starovoitov02ab6952014-09-04 22:17:17 -07002275 BPF_EXIT_INSN(),
2276 },
2277 INTERNAL,
2278 { },
2279 { { 0, 1 } }
2280 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002281 /* BPF_ALU | BPF_MOV | BPF_X */
2282 {
2283 "ALU_MOV_X: dst = 2",
2284 .u.insns_int = {
2285 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2286 BPF_ALU32_REG(BPF_MOV, R0, R1),
2287 BPF_EXIT_INSN(),
2288 },
2289 INTERNAL,
2290 { },
2291 { { 0, 2 } },
2292 },
2293 {
2294 "ALU_MOV_X: dst = 4294967295",
2295 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002296 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002297 BPF_ALU32_REG(BPF_MOV, R0, R1),
2298 BPF_EXIT_INSN(),
2299 },
2300 INTERNAL,
2301 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002302 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002303 },
2304 {
2305 "ALU64_MOV_X: dst = 2",
2306 .u.insns_int = {
2307 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2308 BPF_ALU64_REG(BPF_MOV, R0, R1),
2309 BPF_EXIT_INSN(),
2310 },
2311 INTERNAL,
2312 { },
2313 { { 0, 2 } },
2314 },
2315 {
2316 "ALU64_MOV_X: dst = 4294967295",
2317 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002318 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002319 BPF_ALU64_REG(BPF_MOV, R0, R1),
2320 BPF_EXIT_INSN(),
2321 },
2322 INTERNAL,
2323 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002324 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002325 },
2326 /* BPF_ALU | BPF_MOV | BPF_K */
2327 {
2328 "ALU_MOV_K: dst = 2",
2329 .u.insns_int = {
2330 BPF_ALU32_IMM(BPF_MOV, R0, 2),
2331 BPF_EXIT_INSN(),
2332 },
2333 INTERNAL,
2334 { },
2335 { { 0, 2 } },
2336 },
2337 {
2338 "ALU_MOV_K: dst = 4294967295",
2339 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002340 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002341 BPF_EXIT_INSN(),
2342 },
2343 INTERNAL,
2344 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002345 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002346 },
2347 {
2348 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff",
2349 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002350 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2351 BPF_LD_IMM64(R3, 0x00000000ffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002352 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff),
2353 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2354 BPF_MOV32_IMM(R0, 2),
2355 BPF_EXIT_INSN(),
2356 BPF_MOV32_IMM(R0, 1),
2357 BPF_EXIT_INSN(),
2358 },
2359 INTERNAL,
2360 { },
2361 { { 0, 0x1 } },
2362 },
2363 {
2364 "ALU64_MOV_K: dst = 2",
2365 .u.insns_int = {
2366 BPF_ALU64_IMM(BPF_MOV, R0, 2),
2367 BPF_EXIT_INSN(),
2368 },
2369 INTERNAL,
2370 { },
2371 { { 0, 2 } },
2372 },
2373 {
2374 "ALU64_MOV_K: dst = 2147483647",
2375 .u.insns_int = {
2376 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647),
2377 BPF_EXIT_INSN(),
2378 },
2379 INTERNAL,
2380 { },
2381 { { 0, 2147483647 } },
2382 },
2383 {
2384 "ALU64_OR_K: dst = 0x0",
2385 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002386 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002387 BPF_LD_IMM64(R3, 0x0),
2388 BPF_ALU64_IMM(BPF_MOV, R2, 0x0),
2389 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2390 BPF_MOV32_IMM(R0, 2),
2391 BPF_EXIT_INSN(),
2392 BPF_MOV32_IMM(R0, 1),
2393 BPF_EXIT_INSN(),
2394 },
2395 INTERNAL,
2396 { },
2397 { { 0, 0x1 } },
2398 },
2399 {
2400 "ALU64_MOV_K: dst = -1",
2401 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002402 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
2403 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002404 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff),
2405 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2406 BPF_MOV32_IMM(R0, 2),
2407 BPF_EXIT_INSN(),
2408 BPF_MOV32_IMM(R0, 1),
2409 BPF_EXIT_INSN(),
2410 },
2411 INTERNAL,
2412 { },
2413 { { 0, 0x1 } },
2414 },
2415 /* BPF_ALU | BPF_ADD | BPF_X */
2416 {
2417 "ALU_ADD_X: 1 + 2 = 3",
2418 .u.insns_int = {
2419 BPF_LD_IMM64(R0, 1),
2420 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2421 BPF_ALU32_REG(BPF_ADD, R0, R1),
2422 BPF_EXIT_INSN(),
2423 },
2424 INTERNAL,
2425 { },
2426 { { 0, 3 } },
2427 },
2428 {
2429 "ALU_ADD_X: 1 + 4294967294 = 4294967295",
2430 .u.insns_int = {
2431 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002432 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002433 BPF_ALU32_REG(BPF_ADD, R0, R1),
2434 BPF_EXIT_INSN(),
2435 },
2436 INTERNAL,
2437 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002438 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002439 },
2440 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302441 "ALU_ADD_X: 2 + 4294967294 = 0",
2442 .u.insns_int = {
2443 BPF_LD_IMM64(R0, 2),
2444 BPF_LD_IMM64(R1, 4294967294U),
2445 BPF_ALU32_REG(BPF_ADD, R0, R1),
2446 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2447 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2448 BPF_EXIT_INSN(),
2449 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2450 BPF_EXIT_INSN(),
2451 },
2452 INTERNAL,
2453 { },
2454 { { 0, 1 } },
2455 },
2456 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002457 "ALU64_ADD_X: 1 + 2 = 3",
2458 .u.insns_int = {
2459 BPF_LD_IMM64(R0, 1),
2460 BPF_ALU32_IMM(BPF_MOV, R1, 2),
2461 BPF_ALU64_REG(BPF_ADD, R0, R1),
2462 BPF_EXIT_INSN(),
2463 },
2464 INTERNAL,
2465 { },
2466 { { 0, 3 } },
2467 },
2468 {
2469 "ALU64_ADD_X: 1 + 4294967294 = 4294967295",
2470 .u.insns_int = {
2471 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002472 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002473 BPF_ALU64_REG(BPF_ADD, R0, R1),
2474 BPF_EXIT_INSN(),
2475 },
2476 INTERNAL,
2477 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002478 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002479 },
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302480 {
2481 "ALU64_ADD_X: 2 + 4294967294 = 4294967296",
2482 .u.insns_int = {
2483 BPF_LD_IMM64(R0, 2),
2484 BPF_LD_IMM64(R1, 4294967294U),
2485 BPF_LD_IMM64(R2, 4294967296ULL),
2486 BPF_ALU64_REG(BPF_ADD, R0, R1),
2487 BPF_JMP_REG(BPF_JEQ, R0, R2, 2),
2488 BPF_MOV32_IMM(R0, 0),
2489 BPF_EXIT_INSN(),
2490 BPF_MOV32_IMM(R0, 1),
2491 BPF_EXIT_INSN(),
2492 },
2493 INTERNAL,
2494 { },
2495 { { 0, 1 } },
2496 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002497 /* BPF_ALU | BPF_ADD | BPF_K */
2498 {
2499 "ALU_ADD_K: 1 + 2 = 3",
2500 .u.insns_int = {
2501 BPF_LD_IMM64(R0, 1),
2502 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2503 BPF_EXIT_INSN(),
2504 },
2505 INTERNAL,
2506 { },
2507 { { 0, 3 } },
2508 },
2509 {
2510 "ALU_ADD_K: 3 + 0 = 3",
2511 .u.insns_int = {
2512 BPF_LD_IMM64(R0, 3),
2513 BPF_ALU32_IMM(BPF_ADD, R0, 0),
2514 BPF_EXIT_INSN(),
2515 },
2516 INTERNAL,
2517 { },
2518 { { 0, 3 } },
2519 },
2520 {
2521 "ALU_ADD_K: 1 + 4294967294 = 4294967295",
2522 .u.insns_int = {
2523 BPF_LD_IMM64(R0, 1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002524 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002525 BPF_EXIT_INSN(),
2526 },
2527 INTERNAL,
2528 { },
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002529 { { 0, 4294967295U } },
Michael Holzheucffc6422015-05-11 22:22:44 -07002530 },
2531 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302532 "ALU_ADD_K: 4294967294 + 2 = 0",
2533 .u.insns_int = {
2534 BPF_LD_IMM64(R0, 4294967294U),
2535 BPF_ALU32_IMM(BPF_ADD, R0, 2),
2536 BPF_JMP_IMM(BPF_JEQ, R0, 0, 2),
2537 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2538 BPF_EXIT_INSN(),
2539 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2540 BPF_EXIT_INSN(),
2541 },
2542 INTERNAL,
2543 { },
2544 { { 0, 1 } },
2545 },
2546 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002547 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff",
2548 .u.insns_int = {
2549 BPF_LD_IMM64(R2, 0x0),
2550 BPF_LD_IMM64(R3, 0x00000000ffffffff),
2551 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff),
2552 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2553 BPF_MOV32_IMM(R0, 2),
2554 BPF_EXIT_INSN(),
2555 BPF_MOV32_IMM(R0, 1),
2556 BPF_EXIT_INSN(),
2557 },
2558 INTERNAL,
2559 { },
2560 { { 0, 0x1 } },
2561 },
2562 {
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302563 "ALU_ADD_K: 0 + 0xffff = 0xffff",
2564 .u.insns_int = {
2565 BPF_LD_IMM64(R2, 0x0),
2566 BPF_LD_IMM64(R3, 0xffff),
2567 BPF_ALU32_IMM(BPF_ADD, R2, 0xffff),
2568 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2569 BPF_MOV32_IMM(R0, 2),
2570 BPF_EXIT_INSN(),
2571 BPF_MOV32_IMM(R0, 1),
2572 BPF_EXIT_INSN(),
2573 },
2574 INTERNAL,
2575 { },
2576 { { 0, 0x1 } },
2577 },
2578 {
2579 "ALU_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2580 .u.insns_int = {
2581 BPF_LD_IMM64(R2, 0x0),
2582 BPF_LD_IMM64(R3, 0x7fffffff),
2583 BPF_ALU32_IMM(BPF_ADD, R2, 0x7fffffff),
2584 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2585 BPF_MOV32_IMM(R0, 2),
2586 BPF_EXIT_INSN(),
2587 BPF_MOV32_IMM(R0, 1),
2588 BPF_EXIT_INSN(),
2589 },
2590 INTERNAL,
2591 { },
2592 { { 0, 0x1 } },
2593 },
2594 {
2595 "ALU_ADD_K: 0 + 0x80000000 = 0x80000000",
2596 .u.insns_int = {
2597 BPF_LD_IMM64(R2, 0x0),
2598 BPF_LD_IMM64(R3, 0x80000000),
2599 BPF_ALU32_IMM(BPF_ADD, R2, 0x80000000),
2600 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2601 BPF_MOV32_IMM(R0, 2),
2602 BPF_EXIT_INSN(),
2603 BPF_MOV32_IMM(R0, 1),
2604 BPF_EXIT_INSN(),
2605 },
2606 INTERNAL,
2607 { },
2608 { { 0, 0x1 } },
2609 },
2610 {
2611 "ALU_ADD_K: 0 + 0x80008000 = 0x80008000",
2612 .u.insns_int = {
2613 BPF_LD_IMM64(R2, 0x0),
2614 BPF_LD_IMM64(R3, 0x80008000),
2615 BPF_ALU32_IMM(BPF_ADD, R2, 0x80008000),
2616 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2617 BPF_MOV32_IMM(R0, 2),
2618 BPF_EXIT_INSN(),
2619 BPF_MOV32_IMM(R0, 1),
2620 BPF_EXIT_INSN(),
2621 },
2622 INTERNAL,
2623 { },
2624 { { 0, 0x1 } },
2625 },
2626 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002627 "ALU64_ADD_K: 1 + 2 = 3",
2628 .u.insns_int = {
2629 BPF_LD_IMM64(R0, 1),
2630 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2631 BPF_EXIT_INSN(),
2632 },
2633 INTERNAL,
2634 { },
2635 { { 0, 3 } },
2636 },
2637 {
2638 "ALU64_ADD_K: 3 + 0 = 3",
2639 .u.insns_int = {
2640 BPF_LD_IMM64(R0, 3),
2641 BPF_ALU64_IMM(BPF_ADD, R0, 0),
2642 BPF_EXIT_INSN(),
2643 },
2644 INTERNAL,
2645 { },
2646 { { 0, 3 } },
2647 },
2648 {
2649 "ALU64_ADD_K: 1 + 2147483646 = 2147483647",
2650 .u.insns_int = {
2651 BPF_LD_IMM64(R0, 1),
2652 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646),
2653 BPF_EXIT_INSN(),
2654 },
2655 INTERNAL,
2656 { },
2657 { { 0, 2147483647 } },
2658 },
2659 {
Naveen N. Raob64b50e2016-04-05 15:32:55 +05302660 "ALU64_ADD_K: 4294967294 + 2 = 4294967296",
2661 .u.insns_int = {
2662 BPF_LD_IMM64(R0, 4294967294U),
2663 BPF_LD_IMM64(R1, 4294967296ULL),
2664 BPF_ALU64_IMM(BPF_ADD, R0, 2),
2665 BPF_JMP_REG(BPF_JEQ, R0, R1, 2),
2666 BPF_ALU32_IMM(BPF_MOV, R0, 0),
2667 BPF_EXIT_INSN(),
2668 BPF_ALU32_IMM(BPF_MOV, R0, 1),
2669 BPF_EXIT_INSN(),
2670 },
2671 INTERNAL,
2672 { },
2673 { { 0, 1 } },
2674 },
2675 {
Michael Holzheucffc6422015-05-11 22:22:44 -07002676 "ALU64_ADD_K: 2147483646 + -2147483647 = -1",
2677 .u.insns_int = {
2678 BPF_LD_IMM64(R0, 2147483646),
2679 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647),
2680 BPF_EXIT_INSN(),
2681 },
2682 INTERNAL,
2683 { },
2684 { { 0, -1 } },
2685 },
2686 {
2687 "ALU64_ADD_K: 1 + 0 = 1",
2688 .u.insns_int = {
2689 BPF_LD_IMM64(R2, 0x1),
2690 BPF_LD_IMM64(R3, 0x1),
2691 BPF_ALU64_IMM(BPF_ADD, R2, 0x0),
2692 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2693 BPF_MOV32_IMM(R0, 2),
2694 BPF_EXIT_INSN(),
2695 BPF_MOV32_IMM(R0, 1),
2696 BPF_EXIT_INSN(),
2697 },
2698 INTERNAL,
2699 { },
2700 { { 0, 0x1 } },
2701 },
2702 {
2703 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff",
2704 .u.insns_int = {
2705 BPF_LD_IMM64(R2, 0x0),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002706 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07002707 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff),
2708 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2709 BPF_MOV32_IMM(R0, 2),
2710 BPF_EXIT_INSN(),
2711 BPF_MOV32_IMM(R0, 1),
2712 BPF_EXIT_INSN(),
2713 },
2714 INTERNAL,
2715 { },
2716 { { 0, 0x1 } },
2717 },
Naveen N. Rao9c94f6c2016-04-05 15:32:56 +05302718 {
2719 "ALU64_ADD_K: 0 + 0xffff = 0xffff",
2720 .u.insns_int = {
2721 BPF_LD_IMM64(R2, 0x0),
2722 BPF_LD_IMM64(R3, 0xffff),
2723 BPF_ALU64_IMM(BPF_ADD, R2, 0xffff),
2724 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2725 BPF_MOV32_IMM(R0, 2),
2726 BPF_EXIT_INSN(),
2727 BPF_MOV32_IMM(R0, 1),
2728 BPF_EXIT_INSN(),
2729 },
2730 INTERNAL,
2731 { },
2732 { { 0, 0x1 } },
2733 },
2734 {
2735 "ALU64_ADD_K: 0 + 0x7fffffff = 0x7fffffff",
2736 .u.insns_int = {
2737 BPF_LD_IMM64(R2, 0x0),
2738 BPF_LD_IMM64(R3, 0x7fffffff),
2739 BPF_ALU64_IMM(BPF_ADD, R2, 0x7fffffff),
2740 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2741 BPF_MOV32_IMM(R0, 2),
2742 BPF_EXIT_INSN(),
2743 BPF_MOV32_IMM(R0, 1),
2744 BPF_EXIT_INSN(),
2745 },
2746 INTERNAL,
2747 { },
2748 { { 0, 0x1 } },
2749 },
2750 {
2751 "ALU64_ADD_K: 0 + 0x80000000 = 0xffffffff80000000",
2752 .u.insns_int = {
2753 BPF_LD_IMM64(R2, 0x0),
2754 BPF_LD_IMM64(R3, 0xffffffff80000000LL),
2755 BPF_ALU64_IMM(BPF_ADD, R2, 0x80000000),
2756 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2757 BPF_MOV32_IMM(R0, 2),
2758 BPF_EXIT_INSN(),
2759 BPF_MOV32_IMM(R0, 1),
2760 BPF_EXIT_INSN(),
2761 },
2762 INTERNAL,
2763 { },
2764 { { 0, 0x1 } },
2765 },
2766 {
2767 "ALU_ADD_K: 0 + 0x80008000 = 0xffffffff80008000",
2768 .u.insns_int = {
2769 BPF_LD_IMM64(R2, 0x0),
2770 BPF_LD_IMM64(R3, 0xffffffff80008000LL),
2771 BPF_ALU64_IMM(BPF_ADD, R2, 0x80008000),
2772 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
2773 BPF_MOV32_IMM(R0, 2),
2774 BPF_EXIT_INSN(),
2775 BPF_MOV32_IMM(R0, 1),
2776 BPF_EXIT_INSN(),
2777 },
2778 INTERNAL,
2779 { },
2780 { { 0, 0x1 } },
2781 },
Michael Holzheucffc6422015-05-11 22:22:44 -07002782 /* BPF_ALU | BPF_SUB | BPF_X */
2783 {
2784 "ALU_SUB_X: 3 - 1 = 2",
2785 .u.insns_int = {
2786 BPF_LD_IMM64(R0, 3),
2787 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2788 BPF_ALU32_REG(BPF_SUB, R0, R1),
2789 BPF_EXIT_INSN(),
2790 },
2791 INTERNAL,
2792 { },
2793 { { 0, 2 } },
2794 },
2795 {
2796 "ALU_SUB_X: 4294967295 - 4294967294 = 1",
2797 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002798 BPF_LD_IMM64(R0, 4294967295U),
2799 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002800 BPF_ALU32_REG(BPF_SUB, R0, R1),
2801 BPF_EXIT_INSN(),
2802 },
2803 INTERNAL,
2804 { },
2805 { { 0, 1 } },
2806 },
2807 {
2808 "ALU64_SUB_X: 3 - 1 = 2",
2809 .u.insns_int = {
2810 BPF_LD_IMM64(R0, 3),
2811 BPF_ALU32_IMM(BPF_MOV, R1, 1),
2812 BPF_ALU64_REG(BPF_SUB, R0, R1),
2813 BPF_EXIT_INSN(),
2814 },
2815 INTERNAL,
2816 { },
2817 { { 0, 2 } },
2818 },
2819 {
2820 "ALU64_SUB_X: 4294967295 - 4294967294 = 1",
2821 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002822 BPF_LD_IMM64(R0, 4294967295U),
2823 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002824 BPF_ALU64_REG(BPF_SUB, R0, R1),
2825 BPF_EXIT_INSN(),
2826 },
2827 INTERNAL,
2828 { },
2829 { { 0, 1 } },
2830 },
2831 /* BPF_ALU | BPF_SUB | BPF_K */
2832 {
2833 "ALU_SUB_K: 3 - 1 = 2",
2834 .u.insns_int = {
2835 BPF_LD_IMM64(R0, 3),
2836 BPF_ALU32_IMM(BPF_SUB, R0, 1),
2837 BPF_EXIT_INSN(),
2838 },
2839 INTERNAL,
2840 { },
2841 { { 0, 2 } },
2842 },
2843 {
2844 "ALU_SUB_K: 3 - 0 = 3",
2845 .u.insns_int = {
2846 BPF_LD_IMM64(R0, 3),
2847 BPF_ALU32_IMM(BPF_SUB, R0, 0),
2848 BPF_EXIT_INSN(),
2849 },
2850 INTERNAL,
2851 { },
2852 { { 0, 3 } },
2853 },
2854 {
2855 "ALU_SUB_K: 4294967295 - 4294967294 = 1",
2856 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002857 BPF_LD_IMM64(R0, 4294967295U),
2858 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002859 BPF_EXIT_INSN(),
2860 },
2861 INTERNAL,
2862 { },
2863 { { 0, 1 } },
2864 },
2865 {
2866 "ALU64_SUB_K: 3 - 1 = 2",
2867 .u.insns_int = {
2868 BPF_LD_IMM64(R0, 3),
2869 BPF_ALU64_IMM(BPF_SUB, R0, 1),
2870 BPF_EXIT_INSN(),
2871 },
2872 INTERNAL,
2873 { },
2874 { { 0, 2 } },
2875 },
2876 {
2877 "ALU64_SUB_K: 3 - 0 = 3",
2878 .u.insns_int = {
2879 BPF_LD_IMM64(R0, 3),
2880 BPF_ALU64_IMM(BPF_SUB, R0, 0),
2881 BPF_EXIT_INSN(),
2882 },
2883 INTERNAL,
2884 { },
2885 { { 0, 3 } },
2886 },
2887 {
2888 "ALU64_SUB_K: 4294967294 - 4294967295 = -1",
2889 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07002890 BPF_LD_IMM64(R0, 4294967294U),
2891 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07002892 BPF_EXIT_INSN(),
2893 },
2894 INTERNAL,
2895 { },
2896 { { 0, -1 } },
2897 },
2898 {
2899 "ALU64_ADD_K: 2147483646 - 2147483647 = -1",
2900 .u.insns_int = {
2901 BPF_LD_IMM64(R0, 2147483646),
2902 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647),
2903 BPF_EXIT_INSN(),
2904 },
2905 INTERNAL,
2906 { },
2907 { { 0, -1 } },
2908 },
2909 /* BPF_ALU | BPF_MUL | BPF_X */
2910 {
2911 "ALU_MUL_X: 2 * 3 = 6",
2912 .u.insns_int = {
2913 BPF_LD_IMM64(R0, 2),
2914 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2915 BPF_ALU32_REG(BPF_MUL, R0, R1),
2916 BPF_EXIT_INSN(),
2917 },
2918 INTERNAL,
2919 { },
2920 { { 0, 6 } },
2921 },
2922 {
2923 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2924 .u.insns_int = {
2925 BPF_LD_IMM64(R0, 2),
2926 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8),
2927 BPF_ALU32_REG(BPF_MUL, R0, R1),
2928 BPF_EXIT_INSN(),
2929 },
2930 INTERNAL,
2931 { },
2932 { { 0, 0xFFFFFFF0 } },
2933 },
2934 {
2935 "ALU_MUL_X: -1 * -1 = 1",
2936 .u.insns_int = {
2937 BPF_LD_IMM64(R0, -1),
2938 BPF_ALU32_IMM(BPF_MOV, R1, -1),
2939 BPF_ALU32_REG(BPF_MUL, R0, R1),
2940 BPF_EXIT_INSN(),
2941 },
2942 INTERNAL,
2943 { },
2944 { { 0, 1 } },
2945 },
2946 {
2947 "ALU64_MUL_X: 2 * 3 = 6",
2948 .u.insns_int = {
2949 BPF_LD_IMM64(R0, 2),
2950 BPF_ALU32_IMM(BPF_MOV, R1, 3),
2951 BPF_ALU64_REG(BPF_MUL, R0, R1),
2952 BPF_EXIT_INSN(),
2953 },
2954 INTERNAL,
2955 { },
2956 { { 0, 6 } },
2957 },
2958 {
2959 "ALU64_MUL_X: 1 * 2147483647 = 2147483647",
2960 .u.insns_int = {
2961 BPF_LD_IMM64(R0, 1),
2962 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
2963 BPF_ALU64_REG(BPF_MUL, R0, R1),
2964 BPF_EXIT_INSN(),
2965 },
2966 INTERNAL,
2967 { },
2968 { { 0, 2147483647 } },
2969 },
2970 /* BPF_ALU | BPF_MUL | BPF_K */
2971 {
2972 "ALU_MUL_K: 2 * 3 = 6",
2973 .u.insns_int = {
2974 BPF_LD_IMM64(R0, 2),
2975 BPF_ALU32_IMM(BPF_MUL, R0, 3),
2976 BPF_EXIT_INSN(),
2977 },
2978 INTERNAL,
2979 { },
2980 { { 0, 6 } },
2981 },
2982 {
2983 "ALU_MUL_K: 3 * 1 = 3",
2984 .u.insns_int = {
2985 BPF_LD_IMM64(R0, 3),
2986 BPF_ALU32_IMM(BPF_MUL, R0, 1),
2987 BPF_EXIT_INSN(),
2988 },
2989 INTERNAL,
2990 { },
2991 { { 0, 3 } },
2992 },
2993 {
2994 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0",
2995 .u.insns_int = {
2996 BPF_LD_IMM64(R0, 2),
2997 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8),
2998 BPF_EXIT_INSN(),
2999 },
3000 INTERNAL,
3001 { },
3002 { { 0, 0xFFFFFFF0 } },
3003 },
3004 {
3005 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff",
3006 .u.insns_int = {
3007 BPF_LD_IMM64(R2, 0x1),
3008 BPF_LD_IMM64(R3, 0x00000000ffffffff),
3009 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff),
3010 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3011 BPF_MOV32_IMM(R0, 2),
3012 BPF_EXIT_INSN(),
3013 BPF_MOV32_IMM(R0, 1),
3014 BPF_EXIT_INSN(),
3015 },
3016 INTERNAL,
3017 { },
3018 { { 0, 0x1 } },
3019 },
3020 {
3021 "ALU64_MUL_K: 2 * 3 = 6",
3022 .u.insns_int = {
3023 BPF_LD_IMM64(R0, 2),
3024 BPF_ALU64_IMM(BPF_MUL, R0, 3),
3025 BPF_EXIT_INSN(),
3026 },
3027 INTERNAL,
3028 { },
3029 { { 0, 6 } },
3030 },
3031 {
3032 "ALU64_MUL_K: 3 * 1 = 3",
3033 .u.insns_int = {
3034 BPF_LD_IMM64(R0, 3),
3035 BPF_ALU64_IMM(BPF_MUL, R0, 1),
3036 BPF_EXIT_INSN(),
3037 },
3038 INTERNAL,
3039 { },
3040 { { 0, 3 } },
3041 },
3042 {
3043 "ALU64_MUL_K: 1 * 2147483647 = 2147483647",
3044 .u.insns_int = {
3045 BPF_LD_IMM64(R0, 1),
3046 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647),
3047 BPF_EXIT_INSN(),
3048 },
3049 INTERNAL,
3050 { },
3051 { { 0, 2147483647 } },
3052 },
3053 {
3054 "ALU64_MUL_K: 1 * -2147483647 = -2147483647",
3055 .u.insns_int = {
3056 BPF_LD_IMM64(R0, 1),
3057 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647),
3058 BPF_EXIT_INSN(),
3059 },
3060 INTERNAL,
3061 { },
3062 { { 0, -2147483647 } },
3063 },
3064 {
3065 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff",
3066 .u.insns_int = {
3067 BPF_LD_IMM64(R2, 0x1),
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003068 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003069 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff),
3070 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3071 BPF_MOV32_IMM(R0, 2),
3072 BPF_EXIT_INSN(),
3073 BPF_MOV32_IMM(R0, 1),
3074 BPF_EXIT_INSN(),
3075 },
3076 INTERNAL,
3077 { },
3078 { { 0, 0x1 } },
3079 },
3080 /* BPF_ALU | BPF_DIV | BPF_X */
3081 {
3082 "ALU_DIV_X: 6 / 2 = 3",
3083 .u.insns_int = {
3084 BPF_LD_IMM64(R0, 6),
3085 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3086 BPF_ALU32_REG(BPF_DIV, R0, R1),
3087 BPF_EXIT_INSN(),
3088 },
3089 INTERNAL,
3090 { },
3091 { { 0, 3 } },
3092 },
3093 {
3094 "ALU_DIV_X: 4294967295 / 4294967295 = 1",
3095 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003096 BPF_LD_IMM64(R0, 4294967295U),
3097 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003098 BPF_ALU32_REG(BPF_DIV, R0, R1),
3099 BPF_EXIT_INSN(),
3100 },
3101 INTERNAL,
3102 { },
3103 { { 0, 1 } },
3104 },
3105 {
3106 "ALU64_DIV_X: 6 / 2 = 3",
3107 .u.insns_int = {
3108 BPF_LD_IMM64(R0, 6),
3109 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3110 BPF_ALU64_REG(BPF_DIV, R0, R1),
3111 BPF_EXIT_INSN(),
3112 },
3113 INTERNAL,
3114 { },
3115 { { 0, 3 } },
3116 },
3117 {
3118 "ALU64_DIV_X: 2147483647 / 2147483647 = 1",
3119 .u.insns_int = {
3120 BPF_LD_IMM64(R0, 2147483647),
3121 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647),
3122 BPF_ALU64_REG(BPF_DIV, R0, R1),
3123 BPF_EXIT_INSN(),
3124 },
3125 INTERNAL,
3126 { },
3127 { { 0, 1 } },
3128 },
3129 {
3130 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3131 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003132 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3133 BPF_LD_IMM64(R4, 0xffffffffffffffffLL),
3134 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003135 BPF_ALU64_REG(BPF_DIV, R2, R4),
3136 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3137 BPF_MOV32_IMM(R0, 2),
3138 BPF_EXIT_INSN(),
3139 BPF_MOV32_IMM(R0, 1),
3140 BPF_EXIT_INSN(),
3141 },
3142 INTERNAL,
3143 { },
3144 { { 0, 0x1 } },
3145 },
3146 /* BPF_ALU | BPF_DIV | BPF_K */
3147 {
3148 "ALU_DIV_K: 6 / 2 = 3",
3149 .u.insns_int = {
3150 BPF_LD_IMM64(R0, 6),
3151 BPF_ALU32_IMM(BPF_DIV, R0, 2),
3152 BPF_EXIT_INSN(),
3153 },
3154 INTERNAL,
3155 { },
3156 { { 0, 3 } },
3157 },
3158 {
3159 "ALU_DIV_K: 3 / 1 = 3",
3160 .u.insns_int = {
3161 BPF_LD_IMM64(R0, 3),
3162 BPF_ALU32_IMM(BPF_DIV, R0, 1),
3163 BPF_EXIT_INSN(),
3164 },
3165 INTERNAL,
3166 { },
3167 { { 0, 3 } },
3168 },
3169 {
3170 "ALU_DIV_K: 4294967295 / 4294967295 = 1",
3171 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003172 BPF_LD_IMM64(R0, 4294967295U),
3173 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003174 BPF_EXIT_INSN(),
3175 },
3176 INTERNAL,
3177 { },
3178 { { 0, 1 } },
3179 },
3180 {
3181 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1",
3182 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003183 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003184 BPF_LD_IMM64(R3, 0x1UL),
3185 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff),
3186 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3187 BPF_MOV32_IMM(R0, 2),
3188 BPF_EXIT_INSN(),
3189 BPF_MOV32_IMM(R0, 1),
3190 BPF_EXIT_INSN(),
3191 },
3192 INTERNAL,
3193 { },
3194 { { 0, 0x1 } },
3195 },
3196 {
3197 "ALU64_DIV_K: 6 / 2 = 3",
3198 .u.insns_int = {
3199 BPF_LD_IMM64(R0, 6),
3200 BPF_ALU64_IMM(BPF_DIV, R0, 2),
3201 BPF_EXIT_INSN(),
3202 },
3203 INTERNAL,
3204 { },
3205 { { 0, 3 } },
3206 },
3207 {
3208 "ALU64_DIV_K: 3 / 1 = 3",
3209 .u.insns_int = {
3210 BPF_LD_IMM64(R0, 3),
3211 BPF_ALU64_IMM(BPF_DIV, R0, 1),
3212 BPF_EXIT_INSN(),
3213 },
3214 INTERNAL,
3215 { },
3216 { { 0, 3 } },
3217 },
3218 {
3219 "ALU64_DIV_K: 2147483647 / 2147483647 = 1",
3220 .u.insns_int = {
3221 BPF_LD_IMM64(R0, 2147483647),
3222 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647),
3223 BPF_EXIT_INSN(),
3224 },
3225 INTERNAL,
3226 { },
3227 { { 0, 1 } },
3228 },
3229 {
3230 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001",
3231 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003232 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3233 BPF_LD_IMM64(R3, 0x0000000000000001LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003234 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff),
3235 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3236 BPF_MOV32_IMM(R0, 2),
3237 BPF_EXIT_INSN(),
3238 BPF_MOV32_IMM(R0, 1),
3239 BPF_EXIT_INSN(),
3240 },
3241 INTERNAL,
3242 { },
3243 { { 0, 0x1 } },
3244 },
3245 /* BPF_ALU | BPF_MOD | BPF_X */
3246 {
3247 "ALU_MOD_X: 3 % 2 = 1",
3248 .u.insns_int = {
3249 BPF_LD_IMM64(R0, 3),
3250 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3251 BPF_ALU32_REG(BPF_MOD, R0, R1),
3252 BPF_EXIT_INSN(),
3253 },
3254 INTERNAL,
3255 { },
3256 { { 0, 1 } },
3257 },
3258 {
3259 "ALU_MOD_X: 4294967295 % 4294967293 = 2",
3260 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003261 BPF_LD_IMM64(R0, 4294967295U),
3262 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003263 BPF_ALU32_REG(BPF_MOD, R0, R1),
3264 BPF_EXIT_INSN(),
3265 },
3266 INTERNAL,
3267 { },
3268 { { 0, 2 } },
3269 },
3270 {
3271 "ALU64_MOD_X: 3 % 2 = 1",
3272 .u.insns_int = {
3273 BPF_LD_IMM64(R0, 3),
3274 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3275 BPF_ALU64_REG(BPF_MOD, R0, R1),
3276 BPF_EXIT_INSN(),
3277 },
3278 INTERNAL,
3279 { },
3280 { { 0, 1 } },
3281 },
3282 {
3283 "ALU64_MOD_X: 2147483647 % 2147483645 = 2",
3284 .u.insns_int = {
3285 BPF_LD_IMM64(R0, 2147483647),
3286 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645),
3287 BPF_ALU64_REG(BPF_MOD, R0, R1),
3288 BPF_EXIT_INSN(),
3289 },
3290 INTERNAL,
3291 { },
3292 { { 0, 2 } },
3293 },
3294 /* BPF_ALU | BPF_MOD | BPF_K */
3295 {
3296 "ALU_MOD_K: 3 % 2 = 1",
3297 .u.insns_int = {
3298 BPF_LD_IMM64(R0, 3),
3299 BPF_ALU32_IMM(BPF_MOD, R0, 2),
3300 BPF_EXIT_INSN(),
3301 },
3302 INTERNAL,
3303 { },
3304 { { 0, 1 } },
3305 },
3306 {
3307 "ALU_MOD_K: 3 % 1 = 0",
3308 .u.insns_int = {
3309 BPF_LD_IMM64(R0, 3),
3310 BPF_ALU32_IMM(BPF_MOD, R0, 1),
3311 BPF_EXIT_INSN(),
3312 },
3313 INTERNAL,
3314 { },
3315 { { 0, 0 } },
3316 },
3317 {
3318 "ALU_MOD_K: 4294967295 % 4294967293 = 2",
3319 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003320 BPF_LD_IMM64(R0, 4294967295U),
3321 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U),
Michael Holzheucffc6422015-05-11 22:22:44 -07003322 BPF_EXIT_INSN(),
3323 },
3324 INTERNAL,
3325 { },
3326 { { 0, 2 } },
3327 },
3328 {
3329 "ALU64_MOD_K: 3 % 2 = 1",
3330 .u.insns_int = {
3331 BPF_LD_IMM64(R0, 3),
3332 BPF_ALU64_IMM(BPF_MOD, R0, 2),
3333 BPF_EXIT_INSN(),
3334 },
3335 INTERNAL,
3336 { },
3337 { { 0, 1 } },
3338 },
3339 {
3340 "ALU64_MOD_K: 3 % 1 = 0",
3341 .u.insns_int = {
3342 BPF_LD_IMM64(R0, 3),
3343 BPF_ALU64_IMM(BPF_MOD, R0, 1),
3344 BPF_EXIT_INSN(),
3345 },
3346 INTERNAL,
3347 { },
3348 { { 0, 0 } },
3349 },
3350 {
3351 "ALU64_MOD_K: 2147483647 % 2147483645 = 2",
3352 .u.insns_int = {
3353 BPF_LD_IMM64(R0, 2147483647),
3354 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645),
3355 BPF_EXIT_INSN(),
3356 },
3357 INTERNAL,
3358 { },
3359 { { 0, 2 } },
3360 },
3361 /* BPF_ALU | BPF_AND | BPF_X */
3362 {
3363 "ALU_AND_X: 3 & 2 = 2",
3364 .u.insns_int = {
3365 BPF_LD_IMM64(R0, 3),
3366 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3367 BPF_ALU32_REG(BPF_AND, R0, R1),
3368 BPF_EXIT_INSN(),
3369 },
3370 INTERNAL,
3371 { },
3372 { { 0, 2 } },
3373 },
3374 {
3375 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3376 .u.insns_int = {
3377 BPF_LD_IMM64(R0, 0xffffffff),
3378 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3379 BPF_ALU32_REG(BPF_AND, R0, R1),
3380 BPF_EXIT_INSN(),
3381 },
3382 INTERNAL,
3383 { },
3384 { { 0, 0xffffffff } },
3385 },
3386 {
3387 "ALU64_AND_X: 3 & 2 = 2",
3388 .u.insns_int = {
3389 BPF_LD_IMM64(R0, 3),
3390 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3391 BPF_ALU64_REG(BPF_AND, R0, R1),
3392 BPF_EXIT_INSN(),
3393 },
3394 INTERNAL,
3395 { },
3396 { { 0, 2 } },
3397 },
3398 {
3399 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff",
3400 .u.insns_int = {
3401 BPF_LD_IMM64(R0, 0xffffffff),
3402 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3403 BPF_ALU64_REG(BPF_AND, R0, R1),
3404 BPF_EXIT_INSN(),
3405 },
3406 INTERNAL,
3407 { },
3408 { { 0, 0xffffffff } },
3409 },
3410 /* BPF_ALU | BPF_AND | BPF_K */
3411 {
3412 "ALU_AND_K: 3 & 2 = 2",
3413 .u.insns_int = {
3414 BPF_LD_IMM64(R0, 3),
3415 BPF_ALU32_IMM(BPF_AND, R0, 2),
3416 BPF_EXIT_INSN(),
3417 },
3418 INTERNAL,
3419 { },
3420 { { 0, 2 } },
3421 },
3422 {
3423 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3424 .u.insns_int = {
3425 BPF_LD_IMM64(R0, 0xffffffff),
3426 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff),
3427 BPF_EXIT_INSN(),
3428 },
3429 INTERNAL,
3430 { },
3431 { { 0, 0xffffffff } },
3432 },
3433 {
3434 "ALU64_AND_K: 3 & 2 = 2",
3435 .u.insns_int = {
3436 BPF_LD_IMM64(R0, 3),
3437 BPF_ALU64_IMM(BPF_AND, R0, 2),
3438 BPF_EXIT_INSN(),
3439 },
3440 INTERNAL,
3441 { },
3442 { { 0, 2 } },
3443 },
3444 {
3445 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff",
3446 .u.insns_int = {
3447 BPF_LD_IMM64(R0, 0xffffffff),
3448 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff),
3449 BPF_EXIT_INSN(),
3450 },
3451 INTERNAL,
3452 { },
3453 { { 0, 0xffffffff } },
3454 },
3455 {
3456 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000",
3457 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003458 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3459 BPF_LD_IMM64(R3, 0x0000000000000000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003460 BPF_ALU64_IMM(BPF_AND, R2, 0x0),
3461 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3462 BPF_MOV32_IMM(R0, 2),
3463 BPF_EXIT_INSN(),
3464 BPF_MOV32_IMM(R0, 1),
3465 BPF_EXIT_INSN(),
3466 },
3467 INTERNAL,
3468 { },
3469 { { 0, 0x1 } },
3470 },
3471 {
3472 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff",
3473 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003474 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3475 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003476 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3477 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3478 BPF_MOV32_IMM(R0, 2),
3479 BPF_EXIT_INSN(),
3480 BPF_MOV32_IMM(R0, 1),
3481 BPF_EXIT_INSN(),
3482 },
3483 INTERNAL,
3484 { },
3485 { { 0, 0x1 } },
3486 },
3487 {
3488 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff",
3489 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003490 BPF_LD_IMM64(R2, 0xffffffffffffffffLL),
3491 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003492 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff),
3493 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3494 BPF_MOV32_IMM(R0, 2),
3495 BPF_EXIT_INSN(),
3496 BPF_MOV32_IMM(R0, 1),
3497 BPF_EXIT_INSN(),
3498 },
3499 INTERNAL,
3500 { },
3501 { { 0, 0x1 } },
3502 },
3503 /* BPF_ALU | BPF_OR | BPF_X */
3504 {
3505 "ALU_OR_X: 1 | 2 = 3",
3506 .u.insns_int = {
3507 BPF_LD_IMM64(R0, 1),
3508 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3509 BPF_ALU32_REG(BPF_OR, R0, R1),
3510 BPF_EXIT_INSN(),
3511 },
3512 INTERNAL,
3513 { },
3514 { { 0, 3 } },
3515 },
3516 {
3517 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff",
3518 .u.insns_int = {
3519 BPF_LD_IMM64(R0, 0),
3520 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3521 BPF_ALU32_REG(BPF_OR, R0, R1),
3522 BPF_EXIT_INSN(),
3523 },
3524 INTERNAL,
3525 { },
3526 { { 0, 0xffffffff } },
3527 },
3528 {
3529 "ALU64_OR_X: 1 | 2 = 3",
3530 .u.insns_int = {
3531 BPF_LD_IMM64(R0, 1),
3532 BPF_ALU32_IMM(BPF_MOV, R1, 2),
3533 BPF_ALU64_REG(BPF_OR, R0, R1),
3534 BPF_EXIT_INSN(),
3535 },
3536 INTERNAL,
3537 { },
3538 { { 0, 3 } },
3539 },
3540 {
3541 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff",
3542 .u.insns_int = {
3543 BPF_LD_IMM64(R0, 0),
3544 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3545 BPF_ALU64_REG(BPF_OR, R0, R1),
3546 BPF_EXIT_INSN(),
3547 },
3548 INTERNAL,
3549 { },
3550 { { 0, 0xffffffff } },
3551 },
3552 /* BPF_ALU | BPF_OR | BPF_K */
3553 {
3554 "ALU_OR_K: 1 | 2 = 3",
3555 .u.insns_int = {
3556 BPF_LD_IMM64(R0, 1),
3557 BPF_ALU32_IMM(BPF_OR, R0, 2),
3558 BPF_EXIT_INSN(),
3559 },
3560 INTERNAL,
3561 { },
3562 { { 0, 3 } },
3563 },
3564 {
3565 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff",
3566 .u.insns_int = {
3567 BPF_LD_IMM64(R0, 0),
3568 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff),
3569 BPF_EXIT_INSN(),
3570 },
3571 INTERNAL,
3572 { },
3573 { { 0, 0xffffffff } },
3574 },
3575 {
3576 "ALU64_OR_K: 1 | 2 = 3",
3577 .u.insns_int = {
3578 BPF_LD_IMM64(R0, 1),
3579 BPF_ALU64_IMM(BPF_OR, R0, 2),
3580 BPF_EXIT_INSN(),
3581 },
3582 INTERNAL,
3583 { },
3584 { { 0, 3 } },
3585 },
3586 {
3587 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff",
3588 .u.insns_int = {
3589 BPF_LD_IMM64(R0, 0),
3590 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff),
3591 BPF_EXIT_INSN(),
3592 },
3593 INTERNAL,
3594 { },
3595 { { 0, 0xffffffff } },
3596 },
3597 {
3598 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000",
3599 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003600 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3601 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003602 BPF_ALU64_IMM(BPF_OR, R2, 0x0),
3603 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3604 BPF_MOV32_IMM(R0, 2),
3605 BPF_EXIT_INSN(),
3606 BPF_MOV32_IMM(R0, 1),
3607 BPF_EXIT_INSN(),
3608 },
3609 INTERNAL,
3610 { },
3611 { { 0, 0x1 } },
3612 },
3613 {
3614 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff",
3615 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003616 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3617 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003618 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3619 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3620 BPF_MOV32_IMM(R0, 2),
3621 BPF_EXIT_INSN(),
3622 BPF_MOV32_IMM(R0, 1),
3623 BPF_EXIT_INSN(),
3624 },
3625 INTERNAL,
3626 { },
3627 { { 0, 0x1 } },
3628 },
3629 {
3630 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff",
3631 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003632 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3633 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003634 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff),
3635 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3636 BPF_MOV32_IMM(R0, 2),
3637 BPF_EXIT_INSN(),
3638 BPF_MOV32_IMM(R0, 1),
3639 BPF_EXIT_INSN(),
3640 },
3641 INTERNAL,
3642 { },
3643 { { 0, 0x1 } },
3644 },
3645 /* BPF_ALU | BPF_XOR | BPF_X */
3646 {
3647 "ALU_XOR_X: 5 ^ 6 = 3",
3648 .u.insns_int = {
3649 BPF_LD_IMM64(R0, 5),
3650 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3651 BPF_ALU32_REG(BPF_XOR, R0, R1),
3652 BPF_EXIT_INSN(),
3653 },
3654 INTERNAL,
3655 { },
3656 { { 0, 3 } },
3657 },
3658 {
3659 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe",
3660 .u.insns_int = {
3661 BPF_LD_IMM64(R0, 1),
3662 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3663 BPF_ALU32_REG(BPF_XOR, R0, R1),
3664 BPF_EXIT_INSN(),
3665 },
3666 INTERNAL,
3667 { },
3668 { { 0, 0xfffffffe } },
3669 },
3670 {
3671 "ALU64_XOR_X: 5 ^ 6 = 3",
3672 .u.insns_int = {
3673 BPF_LD_IMM64(R0, 5),
3674 BPF_ALU32_IMM(BPF_MOV, R1, 6),
3675 BPF_ALU64_REG(BPF_XOR, R0, R1),
3676 BPF_EXIT_INSN(),
3677 },
3678 INTERNAL,
3679 { },
3680 { { 0, 3 } },
3681 },
3682 {
3683 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe",
3684 .u.insns_int = {
3685 BPF_LD_IMM64(R0, 1),
3686 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
3687 BPF_ALU64_REG(BPF_XOR, R0, R1),
3688 BPF_EXIT_INSN(),
3689 },
3690 INTERNAL,
3691 { },
3692 { { 0, 0xfffffffe } },
3693 },
3694 /* BPF_ALU | BPF_XOR | BPF_K */
3695 {
3696 "ALU_XOR_K: 5 ^ 6 = 3",
3697 .u.insns_int = {
3698 BPF_LD_IMM64(R0, 5),
3699 BPF_ALU32_IMM(BPF_XOR, R0, 6),
3700 BPF_EXIT_INSN(),
3701 },
3702 INTERNAL,
3703 { },
3704 { { 0, 3 } },
3705 },
3706 {
3707 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe",
3708 .u.insns_int = {
3709 BPF_LD_IMM64(R0, 1),
3710 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff),
3711 BPF_EXIT_INSN(),
3712 },
3713 INTERNAL,
3714 { },
3715 { { 0, 0xfffffffe } },
3716 },
3717 {
3718 "ALU64_XOR_K: 5 ^ 6 = 3",
3719 .u.insns_int = {
3720 BPF_LD_IMM64(R0, 5),
3721 BPF_ALU64_IMM(BPF_XOR, R0, 6),
3722 BPF_EXIT_INSN(),
3723 },
3724 INTERNAL,
3725 { },
3726 { { 0, 3 } },
3727 },
3728 {
3729 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe",
3730 .u.insns_int = {
3731 BPF_LD_IMM64(R0, 1),
3732 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff),
3733 BPF_EXIT_INSN(),
3734 },
3735 INTERNAL,
3736 { },
3737 { { 0, 0xfffffffe } },
3738 },
3739 {
3740 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000",
3741 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003742 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3743 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003744 BPF_ALU64_IMM(BPF_XOR, R2, 0x0),
3745 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3746 BPF_MOV32_IMM(R0, 2),
3747 BPF_EXIT_INSN(),
3748 BPF_MOV32_IMM(R0, 1),
3749 BPF_EXIT_INSN(),
3750 },
3751 INTERNAL,
3752 { },
3753 { { 0, 0x1 } },
3754 },
3755 {
3756 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff",
3757 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003758 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL),
3759 BPF_LD_IMM64(R3, 0xffff00000000ffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003760 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3761 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3762 BPF_MOV32_IMM(R0, 2),
3763 BPF_EXIT_INSN(),
3764 BPF_MOV32_IMM(R0, 1),
3765 BPF_EXIT_INSN(),
3766 },
3767 INTERNAL,
3768 { },
3769 { { 0, 0x1 } },
3770 },
3771 {
3772 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff",
3773 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07003774 BPF_LD_IMM64(R2, 0x0000000000000000LL),
3775 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07003776 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff),
3777 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
3778 BPF_MOV32_IMM(R0, 2),
3779 BPF_EXIT_INSN(),
3780 BPF_MOV32_IMM(R0, 1),
3781 BPF_EXIT_INSN(),
3782 },
3783 INTERNAL,
3784 { },
3785 { { 0, 0x1 } },
3786 },
3787 /* BPF_ALU | BPF_LSH | BPF_X */
3788 {
3789 "ALU_LSH_X: 1 << 1 = 2",
3790 .u.insns_int = {
3791 BPF_LD_IMM64(R0, 1),
3792 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3793 BPF_ALU32_REG(BPF_LSH, R0, R1),
3794 BPF_EXIT_INSN(),
3795 },
3796 INTERNAL,
3797 { },
3798 { { 0, 2 } },
3799 },
3800 {
3801 "ALU_LSH_X: 1 << 31 = 0x80000000",
3802 .u.insns_int = {
3803 BPF_LD_IMM64(R0, 1),
3804 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3805 BPF_ALU32_REG(BPF_LSH, R0, R1),
3806 BPF_EXIT_INSN(),
3807 },
3808 INTERNAL,
3809 { },
3810 { { 0, 0x80000000 } },
3811 },
3812 {
3813 "ALU64_LSH_X: 1 << 1 = 2",
3814 .u.insns_int = {
3815 BPF_LD_IMM64(R0, 1),
3816 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3817 BPF_ALU64_REG(BPF_LSH, R0, R1),
3818 BPF_EXIT_INSN(),
3819 },
3820 INTERNAL,
3821 { },
3822 { { 0, 2 } },
3823 },
3824 {
3825 "ALU64_LSH_X: 1 << 31 = 0x80000000",
3826 .u.insns_int = {
3827 BPF_LD_IMM64(R0, 1),
3828 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3829 BPF_ALU64_REG(BPF_LSH, R0, R1),
3830 BPF_EXIT_INSN(),
3831 },
3832 INTERNAL,
3833 { },
3834 { { 0, 0x80000000 } },
3835 },
3836 /* BPF_ALU | BPF_LSH | BPF_K */
3837 {
3838 "ALU_LSH_K: 1 << 1 = 2",
3839 .u.insns_int = {
3840 BPF_LD_IMM64(R0, 1),
3841 BPF_ALU32_IMM(BPF_LSH, R0, 1),
3842 BPF_EXIT_INSN(),
3843 },
3844 INTERNAL,
3845 { },
3846 { { 0, 2 } },
3847 },
3848 {
3849 "ALU_LSH_K: 1 << 31 = 0x80000000",
3850 .u.insns_int = {
3851 BPF_LD_IMM64(R0, 1),
3852 BPF_ALU32_IMM(BPF_LSH, R0, 31),
3853 BPF_EXIT_INSN(),
3854 },
3855 INTERNAL,
3856 { },
3857 { { 0, 0x80000000 } },
3858 },
3859 {
3860 "ALU64_LSH_K: 1 << 1 = 2",
3861 .u.insns_int = {
3862 BPF_LD_IMM64(R0, 1),
3863 BPF_ALU64_IMM(BPF_LSH, R0, 1),
3864 BPF_EXIT_INSN(),
3865 },
3866 INTERNAL,
3867 { },
3868 { { 0, 2 } },
3869 },
3870 {
3871 "ALU64_LSH_K: 1 << 31 = 0x80000000",
3872 .u.insns_int = {
3873 BPF_LD_IMM64(R0, 1),
3874 BPF_ALU64_IMM(BPF_LSH, R0, 31),
3875 BPF_EXIT_INSN(),
3876 },
3877 INTERNAL,
3878 { },
3879 { { 0, 0x80000000 } },
3880 },
3881 /* BPF_ALU | BPF_RSH | BPF_X */
3882 {
3883 "ALU_RSH_X: 2 >> 1 = 1",
3884 .u.insns_int = {
3885 BPF_LD_IMM64(R0, 2),
3886 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3887 BPF_ALU32_REG(BPF_RSH, R0, R1),
3888 BPF_EXIT_INSN(),
3889 },
3890 INTERNAL,
3891 { },
3892 { { 0, 1 } },
3893 },
3894 {
3895 "ALU_RSH_X: 0x80000000 >> 31 = 1",
3896 .u.insns_int = {
3897 BPF_LD_IMM64(R0, 0x80000000),
3898 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3899 BPF_ALU32_REG(BPF_RSH, R0, R1),
3900 BPF_EXIT_INSN(),
3901 },
3902 INTERNAL,
3903 { },
3904 { { 0, 1 } },
3905 },
3906 {
3907 "ALU64_RSH_X: 2 >> 1 = 1",
3908 .u.insns_int = {
3909 BPF_LD_IMM64(R0, 2),
3910 BPF_ALU32_IMM(BPF_MOV, R1, 1),
3911 BPF_ALU64_REG(BPF_RSH, R0, R1),
3912 BPF_EXIT_INSN(),
3913 },
3914 INTERNAL,
3915 { },
3916 { { 0, 1 } },
3917 },
3918 {
3919 "ALU64_RSH_X: 0x80000000 >> 31 = 1",
3920 .u.insns_int = {
3921 BPF_LD_IMM64(R0, 0x80000000),
3922 BPF_ALU32_IMM(BPF_MOV, R1, 31),
3923 BPF_ALU64_REG(BPF_RSH, R0, R1),
3924 BPF_EXIT_INSN(),
3925 },
3926 INTERNAL,
3927 { },
3928 { { 0, 1 } },
3929 },
3930 /* BPF_ALU | BPF_RSH | BPF_K */
3931 {
3932 "ALU_RSH_K: 2 >> 1 = 1",
3933 .u.insns_int = {
3934 BPF_LD_IMM64(R0, 2),
3935 BPF_ALU32_IMM(BPF_RSH, R0, 1),
3936 BPF_EXIT_INSN(),
3937 },
3938 INTERNAL,
3939 { },
3940 { { 0, 1 } },
3941 },
3942 {
3943 "ALU_RSH_K: 0x80000000 >> 31 = 1",
3944 .u.insns_int = {
3945 BPF_LD_IMM64(R0, 0x80000000),
3946 BPF_ALU32_IMM(BPF_RSH, R0, 31),
3947 BPF_EXIT_INSN(),
3948 },
3949 INTERNAL,
3950 { },
3951 { { 0, 1 } },
3952 },
3953 {
3954 "ALU64_RSH_K: 2 >> 1 = 1",
3955 .u.insns_int = {
3956 BPF_LD_IMM64(R0, 2),
3957 BPF_ALU64_IMM(BPF_RSH, R0, 1),
3958 BPF_EXIT_INSN(),
3959 },
3960 INTERNAL,
3961 { },
3962 { { 0, 1 } },
3963 },
3964 {
3965 "ALU64_RSH_K: 0x80000000 >> 31 = 1",
3966 .u.insns_int = {
3967 BPF_LD_IMM64(R0, 0x80000000),
3968 BPF_ALU64_IMM(BPF_RSH, R0, 31),
3969 BPF_EXIT_INSN(),
3970 },
3971 INTERNAL,
3972 { },
3973 { { 0, 1 } },
3974 },
3975 /* BPF_ALU | BPF_ARSH | BPF_X */
3976 {
3977 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3978 .u.insns_int = {
3979 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3980 BPF_ALU32_IMM(BPF_MOV, R1, 40),
3981 BPF_ALU64_REG(BPF_ARSH, R0, R1),
3982 BPF_EXIT_INSN(),
3983 },
3984 INTERNAL,
3985 { },
3986 { { 0, 0xffff00ff } },
3987 },
3988 /* BPF_ALU | BPF_ARSH | BPF_K */
3989 {
3990 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff",
3991 .u.insns_int = {
3992 BPF_LD_IMM64(R0, 0xff00ff0000000000LL),
3993 BPF_ALU64_IMM(BPF_ARSH, R0, 40),
3994 BPF_EXIT_INSN(),
3995 },
3996 INTERNAL,
3997 { },
3998 { { 0, 0xffff00ff } },
3999 },
4000 /* BPF_ALU | BPF_NEG */
4001 {
4002 "ALU_NEG: -(3) = -3",
4003 .u.insns_int = {
4004 BPF_ALU32_IMM(BPF_MOV, R0, 3),
4005 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4006 BPF_EXIT_INSN(),
4007 },
4008 INTERNAL,
4009 { },
4010 { { 0, -3 } },
4011 },
4012 {
4013 "ALU_NEG: -(-3) = 3",
4014 .u.insns_int = {
4015 BPF_ALU32_IMM(BPF_MOV, R0, -3),
4016 BPF_ALU32_IMM(BPF_NEG, R0, 0),
4017 BPF_EXIT_INSN(),
4018 },
4019 INTERNAL,
4020 { },
4021 { { 0, 3 } },
4022 },
4023 {
4024 "ALU64_NEG: -(3) = -3",
4025 .u.insns_int = {
4026 BPF_LD_IMM64(R0, 3),
4027 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4028 BPF_EXIT_INSN(),
4029 },
4030 INTERNAL,
4031 { },
4032 { { 0, -3 } },
4033 },
4034 {
4035 "ALU64_NEG: -(-3) = 3",
4036 .u.insns_int = {
4037 BPF_LD_IMM64(R0, -3),
4038 BPF_ALU64_IMM(BPF_NEG, R0, 0),
4039 BPF_EXIT_INSN(),
4040 },
4041 INTERNAL,
4042 { },
4043 { { 0, 3 } },
4044 },
4045 /* BPF_ALU | BPF_END | BPF_FROM_BE */
4046 {
4047 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef",
4048 .u.insns_int = {
4049 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4050 BPF_ENDIAN(BPF_FROM_BE, R0, 16),
4051 BPF_EXIT_INSN(),
4052 },
4053 INTERNAL,
4054 { },
4055 { { 0, cpu_to_be16(0xcdef) } },
4056 },
4057 {
4058 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef",
4059 .u.insns_int = {
4060 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4061 BPF_ENDIAN(BPF_FROM_BE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07004062 BPF_ALU64_REG(BPF_MOV, R1, R0),
4063 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4064 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07004065 BPF_EXIT_INSN(),
4066 },
4067 INTERNAL,
4068 { },
4069 { { 0, cpu_to_be32(0x89abcdef) } },
4070 },
4071 {
4072 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef",
4073 .u.insns_int = {
4074 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4075 BPF_ENDIAN(BPF_FROM_BE, R0, 64),
4076 BPF_EXIT_INSN(),
4077 },
4078 INTERNAL,
4079 { },
4080 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } },
4081 },
4082 /* BPF_ALU | BPF_END | BPF_FROM_LE */
4083 {
4084 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd",
4085 .u.insns_int = {
4086 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4087 BPF_ENDIAN(BPF_FROM_LE, R0, 16),
4088 BPF_EXIT_INSN(),
4089 },
4090 INTERNAL,
4091 { },
4092 { { 0, cpu_to_le16(0xcdef) } },
4093 },
4094 {
4095 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89",
4096 .u.insns_int = {
4097 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4098 BPF_ENDIAN(BPF_FROM_LE, R0, 32),
Xi Wangba29bec2015-07-08 14:00:56 -07004099 BPF_ALU64_REG(BPF_MOV, R1, R0),
4100 BPF_ALU64_IMM(BPF_RSH, R1, 32),
4101 BPF_ALU32_REG(BPF_ADD, R0, R1), /* R1 = 0 */
Michael Holzheucffc6422015-05-11 22:22:44 -07004102 BPF_EXIT_INSN(),
4103 },
4104 INTERNAL,
4105 { },
4106 { { 0, cpu_to_le32(0x89abcdef) } },
4107 },
4108 {
4109 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301",
4110 .u.insns_int = {
4111 BPF_LD_IMM64(R0, 0x0123456789abcdefLL),
4112 BPF_ENDIAN(BPF_FROM_LE, R0, 64),
4113 BPF_EXIT_INSN(),
4114 },
4115 INTERNAL,
4116 { },
4117 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } },
4118 },
4119 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */
4120 {
4121 "ST_MEM_B: Store/Load byte: max negative",
4122 .u.insns_int = {
4123 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4124 BPF_ST_MEM(BPF_B, R10, -40, 0xff),
4125 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4126 BPF_EXIT_INSN(),
4127 },
4128 INTERNAL,
4129 { },
4130 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004131 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004132 },
4133 {
4134 "ST_MEM_B: Store/Load byte: max positive",
4135 .u.insns_int = {
4136 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4137 BPF_ST_MEM(BPF_H, R10, -40, 0x7f),
4138 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4139 BPF_EXIT_INSN(),
4140 },
4141 INTERNAL,
4142 { },
4143 { { 0, 0x7f } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004144 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004145 },
4146 {
4147 "STX_MEM_B: Store/Load byte: max negative",
4148 .u.insns_int = {
4149 BPF_LD_IMM64(R0, 0),
4150 BPF_LD_IMM64(R1, 0xffLL),
4151 BPF_STX_MEM(BPF_B, R10, R1, -40),
4152 BPF_LDX_MEM(BPF_B, R0, R10, -40),
4153 BPF_EXIT_INSN(),
4154 },
4155 INTERNAL,
4156 { },
4157 { { 0, 0xff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004158 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004159 },
4160 {
4161 "ST_MEM_H: Store/Load half word: max negative",
4162 .u.insns_int = {
4163 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4164 BPF_ST_MEM(BPF_H, R10, -40, 0xffff),
4165 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4166 BPF_EXIT_INSN(),
4167 },
4168 INTERNAL,
4169 { },
4170 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004171 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004172 },
4173 {
4174 "ST_MEM_H: Store/Load half word: max positive",
4175 .u.insns_int = {
4176 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4177 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff),
4178 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4179 BPF_EXIT_INSN(),
4180 },
4181 INTERNAL,
4182 { },
4183 { { 0, 0x7fff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004184 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004185 },
4186 {
4187 "STX_MEM_H: Store/Load half word: max negative",
4188 .u.insns_int = {
4189 BPF_LD_IMM64(R0, 0),
4190 BPF_LD_IMM64(R1, 0xffffLL),
4191 BPF_STX_MEM(BPF_H, R10, R1, -40),
4192 BPF_LDX_MEM(BPF_H, R0, R10, -40),
4193 BPF_EXIT_INSN(),
4194 },
4195 INTERNAL,
4196 { },
4197 { { 0, 0xffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004198 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004199 },
4200 {
4201 "ST_MEM_W: Store/Load word: max negative",
4202 .u.insns_int = {
4203 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4204 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff),
4205 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4206 BPF_EXIT_INSN(),
4207 },
4208 INTERNAL,
4209 { },
4210 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004211 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004212 },
4213 {
4214 "ST_MEM_W: Store/Load word: max positive",
4215 .u.insns_int = {
4216 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4217 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff),
4218 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4219 BPF_EXIT_INSN(),
4220 },
4221 INTERNAL,
4222 { },
4223 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004224 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004225 },
4226 {
4227 "STX_MEM_W: Store/Load word: max negative",
4228 .u.insns_int = {
4229 BPF_LD_IMM64(R0, 0),
4230 BPF_LD_IMM64(R1, 0xffffffffLL),
4231 BPF_STX_MEM(BPF_W, R10, R1, -40),
4232 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4233 BPF_EXIT_INSN(),
4234 },
4235 INTERNAL,
4236 { },
4237 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004238 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004239 },
4240 {
4241 "ST_MEM_DW: Store/Load double word: max negative",
4242 .u.insns_int = {
4243 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4244 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4245 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4246 BPF_EXIT_INSN(),
4247 },
4248 INTERNAL,
4249 { },
4250 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004251 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004252 },
4253 {
4254 "ST_MEM_DW: Store/Load double word: max negative 2",
4255 .u.insns_int = {
Michael Holzheu56cbaa42015-05-13 20:40:39 -07004256 BPF_LD_IMM64(R2, 0xffff00000000ffffLL),
4257 BPF_LD_IMM64(R3, 0xffffffffffffffffLL),
Michael Holzheucffc6422015-05-11 22:22:44 -07004258 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff),
4259 BPF_LDX_MEM(BPF_DW, R2, R10, -40),
4260 BPF_JMP_REG(BPF_JEQ, R2, R3, 2),
4261 BPF_MOV32_IMM(R0, 2),
4262 BPF_EXIT_INSN(),
4263 BPF_MOV32_IMM(R0, 1),
4264 BPF_EXIT_INSN(),
4265 },
4266 INTERNAL,
4267 { },
4268 { { 0, 0x1 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004269 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004270 },
4271 {
4272 "ST_MEM_DW: Store/Load double word: max positive",
4273 .u.insns_int = {
4274 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4275 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff),
4276 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4277 BPF_EXIT_INSN(),
4278 },
4279 INTERNAL,
4280 { },
4281 { { 0, 0x7fffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004282 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004283 },
4284 {
4285 "STX_MEM_DW: Store/Load double word: max negative",
4286 .u.insns_int = {
4287 BPF_LD_IMM64(R0, 0),
4288 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
Johan Almbladhae7f4702021-07-21 12:40:58 +02004289 BPF_STX_MEM(BPF_DW, R10, R1, -40),
4290 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
Michael Holzheucffc6422015-05-11 22:22:44 -07004291 BPF_EXIT_INSN(),
4292 },
4293 INTERNAL,
4294 { },
4295 { { 0, 0xffffffff } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004296 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004297 },
Brendan Jackman91c960b2021-01-14 18:17:44 +00004298 /* BPF_STX | BPF_ATOMIC | BPF_W/DW */
Michael Holzheucffc6422015-05-11 22:22:44 -07004299 {
4300 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22",
4301 .u.insns_int = {
4302 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4303 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00004304 BPF_ATOMIC_OP(BPF_W, BPF_ADD, R10, R0, -40),
Michael Holzheucffc6422015-05-11 22:22:44 -07004305 BPF_LDX_MEM(BPF_W, R0, R10, -40),
4306 BPF_EXIT_INSN(),
4307 },
4308 INTERNAL,
4309 { },
4310 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004311 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004312 },
4313 {
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004314 "STX_XADD_W: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4315 .u.insns_int = {
4316 BPF_ALU64_REG(BPF_MOV, R1, R10),
4317 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4318 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00004319 BPF_ATOMIC_OP(BPF_W, BPF_ADD, R10, R0, -40),
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004320 BPF_ALU64_REG(BPF_MOV, R0, R10),
4321 BPF_ALU64_REG(BPF_SUB, R0, R1),
4322 BPF_EXIT_INSN(),
4323 },
4324 INTERNAL,
4325 { },
4326 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004327 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004328 },
4329 {
4330 "STX_XADD_W: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4331 .u.insns_int = {
4332 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4333 BPF_ST_MEM(BPF_W, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00004334 BPF_ATOMIC_OP(BPF_W, BPF_ADD, R10, R0, -40),
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004335 BPF_EXIT_INSN(),
4336 },
4337 INTERNAL,
4338 { },
4339 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004340 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004341 },
4342 {
4343 "STX_XADD_W: X + 1 + 1 + 1 + ...",
4344 { },
4345 INTERNAL,
4346 { },
4347 { { 0, 4134 } },
4348 .fill_helper = bpf_fill_stxw,
4349 },
4350 {
Michael Holzheucffc6422015-05-11 22:22:44 -07004351 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22",
4352 .u.insns_int = {
4353 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4354 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00004355 BPF_ATOMIC_OP(BPF_DW, BPF_ADD, R10, R0, -40),
Michael Holzheucffc6422015-05-11 22:22:44 -07004356 BPF_LDX_MEM(BPF_DW, R0, R10, -40),
4357 BPF_EXIT_INSN(),
4358 },
4359 INTERNAL,
4360 { },
4361 { { 0, 0x22 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004362 .stack_depth = 40,
Michael Holzheucffc6422015-05-11 22:22:44 -07004363 },
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004364 {
4365 "STX_XADD_DW: Test side-effects, r10: 0x12 + 0x10 = 0x22",
4366 .u.insns_int = {
4367 BPF_ALU64_REG(BPF_MOV, R1, R10),
4368 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4369 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00004370 BPF_ATOMIC_OP(BPF_DW, BPF_ADD, R10, R0, -40),
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004371 BPF_ALU64_REG(BPF_MOV, R0, R10),
4372 BPF_ALU64_REG(BPF_SUB, R0, R1),
4373 BPF_EXIT_INSN(),
4374 },
4375 INTERNAL,
4376 { },
4377 { { 0, 0 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004378 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004379 },
4380 {
4381 "STX_XADD_DW: Test side-effects, r0: 0x12 + 0x10 = 0x22",
4382 .u.insns_int = {
4383 BPF_ALU32_IMM(BPF_MOV, R0, 0x12),
4384 BPF_ST_MEM(BPF_DW, R10, -40, 0x10),
Brendan Jackman91c960b2021-01-14 18:17:44 +00004385 BPF_ATOMIC_OP(BPF_DW, BPF_ADD, R10, R0, -40),
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004386 BPF_EXIT_INSN(),
4387 },
4388 INTERNAL,
4389 { },
4390 { { 0, 0x12 } },
Alexei Starovoitov105c0362017-05-30 13:31:32 -07004391 .stack_depth = 40,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +02004392 },
4393 {
4394 "STX_XADD_DW: X + 1 + 1 + 1 + ...",
4395 { },
4396 INTERNAL,
4397 { },
4398 { { 0, 4134 } },
4399 .fill_helper = bpf_fill_stxdw,
4400 },
Johan Almbladhb55dfa82021-08-09 11:18:16 +02004401 /* BPF_JMP32 | BPF_JEQ | BPF_K */
4402 {
4403 "JMP32_JEQ_K: Small immediate",
4404 .u.insns_int = {
4405 BPF_ALU32_IMM(BPF_MOV, R0, 123),
4406 BPF_JMP32_IMM(BPF_JEQ, R0, 321, 1),
4407 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
4408 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4409 BPF_EXIT_INSN(),
4410 },
4411 INTERNAL,
4412 { },
4413 { { 0, 123 } }
4414 },
4415 {
4416 "JMP32_JEQ_K: Large immediate",
4417 .u.insns_int = {
4418 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
4419 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678 & 0xffff, 1),
4420 BPF_JMP32_IMM(BPF_JEQ, R0, 12345678, 1),
4421 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4422 BPF_EXIT_INSN(),
4423 },
4424 INTERNAL,
4425 { },
4426 { { 0, 12345678 } }
4427 },
4428 {
4429 "JMP32_JEQ_K: negative immediate",
4430 .u.insns_int = {
4431 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4432 BPF_JMP32_IMM(BPF_JEQ, R0, 123, 1),
4433 BPF_JMP32_IMM(BPF_JEQ, R0, -123, 1),
4434 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4435 BPF_EXIT_INSN(),
4436 },
4437 INTERNAL,
4438 { },
4439 { { 0, -123 } }
4440 },
4441 /* BPF_JMP32 | BPF_JEQ | BPF_X */
4442 {
4443 "JMP32_JEQ_X",
4444 .u.insns_int = {
4445 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
4446 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
4447 BPF_JMP32_REG(BPF_JEQ, R0, R1, 2),
4448 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
4449 BPF_JMP32_REG(BPF_JEQ, R0, R1, 1),
4450 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4451 BPF_EXIT_INSN(),
4452 },
4453 INTERNAL,
4454 { },
4455 { { 0, 1234 } }
4456 },
4457 /* BPF_JMP32 | BPF_JNE | BPF_K */
4458 {
4459 "JMP32_JNE_K: Small immediate",
4460 .u.insns_int = {
4461 BPF_ALU32_IMM(BPF_MOV, R0, 123),
4462 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
4463 BPF_JMP32_IMM(BPF_JNE, R0, 321, 1),
4464 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4465 BPF_EXIT_INSN(),
4466 },
4467 INTERNAL,
4468 { },
4469 { { 0, 123 } }
4470 },
4471 {
4472 "JMP32_JNE_K: Large immediate",
4473 .u.insns_int = {
4474 BPF_ALU32_IMM(BPF_MOV, R0, 12345678),
4475 BPF_JMP32_IMM(BPF_JNE, R0, 12345678, 1),
4476 BPF_JMP32_IMM(BPF_JNE, R0, 12345678 & 0xffff, 1),
4477 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4478 BPF_EXIT_INSN(),
4479 },
4480 INTERNAL,
4481 { },
4482 { { 0, 12345678 } }
4483 },
4484 {
4485 "JMP32_JNE_K: negative immediate",
4486 .u.insns_int = {
4487 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4488 BPF_JMP32_IMM(BPF_JNE, R0, -123, 1),
4489 BPF_JMP32_IMM(BPF_JNE, R0, 123, 1),
4490 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4491 BPF_EXIT_INSN(),
4492 },
4493 INTERNAL,
4494 { },
4495 { { 0, -123 } }
4496 },
4497 /* BPF_JMP32 | BPF_JNE | BPF_X */
4498 {
4499 "JMP32_JNE_X",
4500 .u.insns_int = {
4501 BPF_ALU32_IMM(BPF_MOV, R0, 1234),
4502 BPF_ALU32_IMM(BPF_MOV, R1, 1234),
4503 BPF_JMP32_REG(BPF_JNE, R0, R1, 2),
4504 BPF_ALU32_IMM(BPF_MOV, R1, 4321),
4505 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
4506 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4507 BPF_EXIT_INSN(),
4508 },
4509 INTERNAL,
4510 { },
4511 { { 0, 1234 } }
4512 },
4513 /* BPF_JMP32 | BPF_JSET | BPF_K */
4514 {
4515 "JMP32_JSET_K: Small immediate",
4516 .u.insns_int = {
4517 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4518 BPF_JMP32_IMM(BPF_JSET, R0, 2, 1),
4519 BPF_JMP32_IMM(BPF_JSET, R0, 3, 1),
4520 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4521 BPF_EXIT_INSN(),
4522 },
4523 INTERNAL,
4524 { },
4525 { { 0, 1 } }
4526 },
4527 {
4528 "JMP32_JSET_K: Large immediate",
4529 .u.insns_int = {
4530 BPF_ALU32_IMM(BPF_MOV, R0, 0x40000000),
4531 BPF_JMP32_IMM(BPF_JSET, R0, 0x3fffffff, 1),
4532 BPF_JMP32_IMM(BPF_JSET, R0, 0x60000000, 1),
4533 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4534 BPF_EXIT_INSN(),
4535 },
4536 INTERNAL,
4537 { },
4538 { { 0, 0x40000000 } }
4539 },
4540 {
4541 "JMP32_JSET_K: negative immediate",
4542 .u.insns_int = {
4543 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4544 BPF_JMP32_IMM(BPF_JSET, R0, -1, 1),
4545 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4546 BPF_EXIT_INSN(),
4547 },
4548 INTERNAL,
4549 { },
4550 { { 0, -123 } }
4551 },
4552 /* BPF_JMP32 | BPF_JSET | BPF_X */
4553 {
4554 "JMP32_JSET_X",
4555 .u.insns_int = {
4556 BPF_ALU32_IMM(BPF_MOV, R0, 8),
4557 BPF_ALU32_IMM(BPF_MOV, R1, 7),
4558 BPF_JMP32_REG(BPF_JSET, R0, R1, 2),
4559 BPF_ALU32_IMM(BPF_MOV, R1, 8 | 2),
4560 BPF_JMP32_REG(BPF_JNE, R0, R1, 1),
4561 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4562 BPF_EXIT_INSN(),
4563 },
4564 INTERNAL,
4565 { },
4566 { { 0, 8 } }
4567 },
4568 /* BPF_JMP32 | BPF_JGT | BPF_K */
4569 {
4570 "JMP32_JGT_K: Small immediate",
4571 .u.insns_int = {
4572 BPF_ALU32_IMM(BPF_MOV, R0, 123),
4573 BPF_JMP32_IMM(BPF_JGT, R0, 123, 1),
4574 BPF_JMP32_IMM(BPF_JGT, R0, 122, 1),
4575 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4576 BPF_EXIT_INSN(),
4577 },
4578 INTERNAL,
4579 { },
4580 { { 0, 123 } }
4581 },
4582 {
4583 "JMP32_JGT_K: Large immediate",
4584 .u.insns_int = {
4585 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
4586 BPF_JMP32_IMM(BPF_JGT, R0, 0xffffffff, 1),
4587 BPF_JMP32_IMM(BPF_JGT, R0, 0xfffffffd, 1),
4588 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4589 BPF_EXIT_INSN(),
4590 },
4591 INTERNAL,
4592 { },
4593 { { 0, 0xfffffffe } }
4594 },
4595 /* BPF_JMP32 | BPF_JGT | BPF_X */
4596 {
4597 "JMP32_JGT_X",
4598 .u.insns_int = {
4599 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
4600 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4601 BPF_JMP32_REG(BPF_JGT, R0, R1, 2),
4602 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
4603 BPF_JMP32_REG(BPF_JGT, R0, R1, 1),
4604 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4605 BPF_EXIT_INSN(),
4606 },
4607 INTERNAL,
4608 { },
4609 { { 0, 0xfffffffe } }
4610 },
4611 /* BPF_JMP32 | BPF_JGE | BPF_K */
4612 {
4613 "JMP32_JGE_K: Small immediate",
4614 .u.insns_int = {
4615 BPF_ALU32_IMM(BPF_MOV, R0, 123),
4616 BPF_JMP32_IMM(BPF_JGE, R0, 124, 1),
4617 BPF_JMP32_IMM(BPF_JGE, R0, 123, 1),
4618 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4619 BPF_EXIT_INSN(),
4620 },
4621 INTERNAL,
4622 { },
4623 { { 0, 123 } }
4624 },
4625 {
4626 "JMP32_JGE_K: Large immediate",
4627 .u.insns_int = {
4628 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
4629 BPF_JMP32_IMM(BPF_JGE, R0, 0xffffffff, 1),
4630 BPF_JMP32_IMM(BPF_JGE, R0, 0xfffffffe, 1),
4631 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4632 BPF_EXIT_INSN(),
4633 },
4634 INTERNAL,
4635 { },
4636 { { 0, 0xfffffffe } }
4637 },
4638 /* BPF_JMP32 | BPF_JGE | BPF_X */
4639 {
4640 "JMP32_JGE_X",
4641 .u.insns_int = {
4642 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
4643 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4644 BPF_JMP32_REG(BPF_JGE, R0, R1, 2),
4645 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
4646 BPF_JMP32_REG(BPF_JGE, R0, R1, 1),
4647 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4648 BPF_EXIT_INSN(),
4649 },
4650 INTERNAL,
4651 { },
4652 { { 0, 0xfffffffe } }
4653 },
4654 /* BPF_JMP32 | BPF_JLT | BPF_K */
4655 {
4656 "JMP32_JLT_K: Small immediate",
4657 .u.insns_int = {
4658 BPF_ALU32_IMM(BPF_MOV, R0, 123),
4659 BPF_JMP32_IMM(BPF_JLT, R0, 123, 1),
4660 BPF_JMP32_IMM(BPF_JLT, R0, 124, 1),
4661 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4662 BPF_EXIT_INSN(),
4663 },
4664 INTERNAL,
4665 { },
4666 { { 0, 123 } }
4667 },
4668 {
4669 "JMP32_JLT_K: Large immediate",
4670 .u.insns_int = {
4671 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
4672 BPF_JMP32_IMM(BPF_JLT, R0, 0xfffffffd, 1),
4673 BPF_JMP32_IMM(BPF_JLT, R0, 0xffffffff, 1),
4674 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4675 BPF_EXIT_INSN(),
4676 },
4677 INTERNAL,
4678 { },
4679 { { 0, 0xfffffffe } }
4680 },
4681 /* BPF_JMP32 | BPF_JLT | BPF_X */
4682 {
4683 "JMP32_JLT_X",
4684 .u.insns_int = {
4685 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
4686 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
4687 BPF_JMP32_REG(BPF_JLT, R0, R1, 2),
4688 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff),
4689 BPF_JMP32_REG(BPF_JLT, R0, R1, 1),
4690 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4691 BPF_EXIT_INSN(),
4692 },
4693 INTERNAL,
4694 { },
4695 { { 0, 0xfffffffe } }
4696 },
4697 /* BPF_JMP32 | BPF_JLE | BPF_K */
4698 {
4699 "JMP32_JLE_K: Small immediate",
4700 .u.insns_int = {
4701 BPF_ALU32_IMM(BPF_MOV, R0, 123),
4702 BPF_JMP32_IMM(BPF_JLE, R0, 122, 1),
4703 BPF_JMP32_IMM(BPF_JLE, R0, 123, 1),
4704 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4705 BPF_EXIT_INSN(),
4706 },
4707 INTERNAL,
4708 { },
4709 { { 0, 123 } }
4710 },
4711 {
4712 "JMP32_JLE_K: Large immediate",
4713 .u.insns_int = {
4714 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
4715 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffd, 1),
4716 BPF_JMP32_IMM(BPF_JLE, R0, 0xfffffffe, 1),
4717 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4718 BPF_EXIT_INSN(),
4719 },
4720 INTERNAL,
4721 { },
4722 { { 0, 0xfffffffe } }
4723 },
4724 /* BPF_JMP32 | BPF_JLE | BPF_X */
4725 {
4726 "JMP32_JLE_X",
4727 .u.insns_int = {
4728 BPF_ALU32_IMM(BPF_MOV, R0, 0xfffffffe),
4729 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffd),
4730 BPF_JMP32_REG(BPF_JLE, R0, R1, 2),
4731 BPF_ALU32_IMM(BPF_MOV, R1, 0xfffffffe),
4732 BPF_JMP32_REG(BPF_JLE, R0, R1, 1),
4733 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4734 BPF_EXIT_INSN(),
4735 },
4736 INTERNAL,
4737 { },
4738 { { 0, 0xfffffffe } }
4739 },
4740 /* BPF_JMP32 | BPF_JSGT | BPF_K */
4741 {
4742 "JMP32_JSGT_K: Small immediate",
4743 .u.insns_int = {
4744 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4745 BPF_JMP32_IMM(BPF_JSGT, R0, -123, 1),
4746 BPF_JMP32_IMM(BPF_JSGT, R0, -124, 1),
4747 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4748 BPF_EXIT_INSN(),
4749 },
4750 INTERNAL,
4751 { },
4752 { { 0, -123 } }
4753 },
4754 {
4755 "JMP32_JSGT_K: Large immediate",
4756 .u.insns_int = {
4757 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
4758 BPF_JMP32_IMM(BPF_JSGT, R0, -12345678, 1),
4759 BPF_JMP32_IMM(BPF_JSGT, R0, -12345679, 1),
4760 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4761 BPF_EXIT_INSN(),
4762 },
4763 INTERNAL,
4764 { },
4765 { { 0, -12345678 } }
4766 },
4767 /* BPF_JMP32 | BPF_JSGT | BPF_X */
4768 {
4769 "JMP32_JSGT_X",
4770 .u.insns_int = {
4771 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
4772 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
4773 BPF_JMP32_REG(BPF_JSGT, R0, R1, 2),
4774 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
4775 BPF_JMP32_REG(BPF_JSGT, R0, R1, 1),
4776 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4777 BPF_EXIT_INSN(),
4778 },
4779 INTERNAL,
4780 { },
4781 { { 0, -12345678 } }
4782 },
4783 /* BPF_JMP32 | BPF_JSGE | BPF_K */
4784 {
4785 "JMP32_JSGE_K: Small immediate",
4786 .u.insns_int = {
4787 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4788 BPF_JMP32_IMM(BPF_JSGE, R0, -122, 1),
4789 BPF_JMP32_IMM(BPF_JSGE, R0, -123, 1),
4790 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4791 BPF_EXIT_INSN(),
4792 },
4793 INTERNAL,
4794 { },
4795 { { 0, -123 } }
4796 },
4797 {
4798 "JMP32_JSGE_K: Large immediate",
4799 .u.insns_int = {
4800 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
4801 BPF_JMP32_IMM(BPF_JSGE, R0, -12345677, 1),
4802 BPF_JMP32_IMM(BPF_JSGE, R0, -12345678, 1),
4803 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4804 BPF_EXIT_INSN(),
4805 },
4806 INTERNAL,
4807 { },
4808 { { 0, -12345678 } }
4809 },
4810 /* BPF_JMP32 | BPF_JSGE | BPF_X */
4811 {
4812 "JMP32_JSGE_X",
4813 .u.insns_int = {
4814 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
4815 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
4816 BPF_JMP32_REG(BPF_JSGE, R0, R1, 2),
4817 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
4818 BPF_JMP32_REG(BPF_JSGE, R0, R1, 1),
4819 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4820 BPF_EXIT_INSN(),
4821 },
4822 INTERNAL,
4823 { },
4824 { { 0, -12345678 } }
4825 },
4826 /* BPF_JMP32 | BPF_JSLT | BPF_K */
4827 {
4828 "JMP32_JSLT_K: Small immediate",
4829 .u.insns_int = {
4830 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4831 BPF_JMP32_IMM(BPF_JSLT, R0, -123, 1),
4832 BPF_JMP32_IMM(BPF_JSLT, R0, -122, 1),
4833 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4834 BPF_EXIT_INSN(),
4835 },
4836 INTERNAL,
4837 { },
4838 { { 0, -123 } }
4839 },
4840 {
4841 "JMP32_JSLT_K: Large immediate",
4842 .u.insns_int = {
4843 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
4844 BPF_JMP32_IMM(BPF_JSLT, R0, -12345678, 1),
4845 BPF_JMP32_IMM(BPF_JSLT, R0, -12345677, 1),
4846 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4847 BPF_EXIT_INSN(),
4848 },
4849 INTERNAL,
4850 { },
4851 { { 0, -12345678 } }
4852 },
4853 /* BPF_JMP32 | BPF_JSLT | BPF_X */
4854 {
4855 "JMP32_JSLT_X",
4856 .u.insns_int = {
4857 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
4858 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
4859 BPF_JMP32_REG(BPF_JSLT, R0, R1, 2),
4860 BPF_ALU32_IMM(BPF_MOV, R1, -12345677),
4861 BPF_JMP32_REG(BPF_JSLT, R0, R1, 1),
4862 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4863 BPF_EXIT_INSN(),
4864 },
4865 INTERNAL,
4866 { },
4867 { { 0, -12345678 } }
4868 },
4869 /* BPF_JMP32 | BPF_JSLE | BPF_K */
4870 {
4871 "JMP32_JSLE_K: Small immediate",
4872 .u.insns_int = {
4873 BPF_ALU32_IMM(BPF_MOV, R0, -123),
4874 BPF_JMP32_IMM(BPF_JSLE, R0, -124, 1),
4875 BPF_JMP32_IMM(BPF_JSLE, R0, -123, 1),
4876 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4877 BPF_EXIT_INSN(),
4878 },
4879 INTERNAL,
4880 { },
4881 { { 0, -123 } }
4882 },
4883 {
4884 "JMP32_JSLE_K: Large immediate",
4885 .u.insns_int = {
4886 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
4887 BPF_JMP32_IMM(BPF_JSLE, R0, -12345679, 1),
4888 BPF_JMP32_IMM(BPF_JSLE, R0, -12345678, 1),
4889 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4890 BPF_EXIT_INSN(),
4891 },
4892 INTERNAL,
4893 { },
4894 { { 0, -12345678 } }
4895 },
4896 /* BPF_JMP32 | BPF_JSLE | BPF_K */
4897 {
4898 "JMP32_JSLE_X",
4899 .u.insns_int = {
4900 BPF_ALU32_IMM(BPF_MOV, R0, -12345678),
4901 BPF_ALU32_IMM(BPF_MOV, R1, -12345679),
4902 BPF_JMP32_REG(BPF_JSLE, R0, R1, 2),
4903 BPF_ALU32_IMM(BPF_MOV, R1, -12345678),
4904 BPF_JMP32_REG(BPF_JSLE, R0, R1, 1),
4905 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4906 BPF_EXIT_INSN(),
4907 },
4908 INTERNAL,
4909 { },
4910 { { 0, -12345678 } }
4911 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004912 /* BPF_JMP | BPF_EXIT */
4913 {
4914 "JMP_EXIT",
4915 .u.insns_int = {
4916 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711),
4917 BPF_EXIT_INSN(),
4918 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712),
4919 },
4920 INTERNAL,
4921 { },
4922 { { 0, 0x4711 } },
4923 },
4924 /* BPF_JMP | BPF_JA */
4925 {
4926 "JMP_JA: Unconditional jump: if (true) return 1",
4927 .u.insns_int = {
4928 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4929 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
4930 BPF_EXIT_INSN(),
4931 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4932 BPF_EXIT_INSN(),
4933 },
4934 INTERNAL,
4935 { },
4936 { { 0, 1 } },
4937 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004938 /* BPF_JMP | BPF_JSLT | BPF_K */
4939 {
4940 "JMP_JSLT_K: Signed jump: if (-2 < -1) return 1",
4941 .u.insns_int = {
4942 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4943 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
4944 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4945 BPF_EXIT_INSN(),
4946 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4947 BPF_EXIT_INSN(),
4948 },
4949 INTERNAL,
4950 { },
4951 { { 0, 1 } },
4952 },
4953 {
4954 "JMP_JSLT_K: Signed jump: if (-1 < -1) return 0",
4955 .u.insns_int = {
4956 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4957 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4958 BPF_JMP_IMM(BPF_JSLT, R1, -1, 1),
4959 BPF_EXIT_INSN(),
4960 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4961 BPF_EXIT_INSN(),
4962 },
4963 INTERNAL,
4964 { },
4965 { { 0, 1 } },
4966 },
Michael Holzheucffc6422015-05-11 22:22:44 -07004967 /* BPF_JMP | BPF_JSGT | BPF_K */
4968 {
4969 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1",
4970 .u.insns_int = {
4971 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4972 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4973 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1),
4974 BPF_EXIT_INSN(),
4975 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4976 BPF_EXIT_INSN(),
4977 },
4978 INTERNAL,
4979 { },
4980 { { 0, 1 } },
4981 },
4982 {
4983 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0",
4984 .u.insns_int = {
4985 BPF_ALU32_IMM(BPF_MOV, R0, 1),
4986 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
4987 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1),
4988 BPF_EXIT_INSN(),
4989 BPF_ALU32_IMM(BPF_MOV, R0, 0),
4990 BPF_EXIT_INSN(),
4991 },
4992 INTERNAL,
4993 { },
4994 { { 0, 1 } },
4995 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02004996 /* BPF_JMP | BPF_JSLE | BPF_K */
4997 {
4998 "JMP_JSLE_K: Signed jump: if (-2 <= -1) return 1",
4999 .u.insns_int = {
5000 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5001 BPF_LD_IMM64(R1, 0xfffffffffffffffeLL),
5002 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
5003 BPF_EXIT_INSN(),
5004 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5005 BPF_EXIT_INSN(),
5006 },
5007 INTERNAL,
5008 { },
5009 { { 0, 1 } },
5010 },
5011 {
5012 "JMP_JSLE_K: Signed jump: if (-1 <= -1) return 1",
5013 .u.insns_int = {
5014 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5015 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
5016 BPF_JMP_IMM(BPF_JSLE, R1, -1, 1),
5017 BPF_EXIT_INSN(),
5018 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5019 BPF_EXIT_INSN(),
5020 },
5021 INTERNAL,
5022 { },
5023 { { 0, 1 } },
5024 },
5025 {
5026 "JMP_JSLE_K: Signed jump: value walk 1",
5027 .u.insns_int = {
5028 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5029 BPF_LD_IMM64(R1, 3),
5030 BPF_JMP_IMM(BPF_JSLE, R1, 0, 6),
5031 BPF_ALU64_IMM(BPF_SUB, R1, 1),
5032 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
5033 BPF_ALU64_IMM(BPF_SUB, R1, 1),
5034 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
5035 BPF_ALU64_IMM(BPF_SUB, R1, 1),
5036 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
5037 BPF_EXIT_INSN(), /* bad exit */
5038 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
5039 BPF_EXIT_INSN(),
5040 },
5041 INTERNAL,
5042 { },
5043 { { 0, 1 } },
5044 },
5045 {
5046 "JMP_JSLE_K: Signed jump: value walk 2",
5047 .u.insns_int = {
5048 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5049 BPF_LD_IMM64(R1, 3),
5050 BPF_JMP_IMM(BPF_JSLE, R1, 0, 4),
5051 BPF_ALU64_IMM(BPF_SUB, R1, 2),
5052 BPF_JMP_IMM(BPF_JSLE, R1, 0, 2),
5053 BPF_ALU64_IMM(BPF_SUB, R1, 2),
5054 BPF_JMP_IMM(BPF_JSLE, R1, 0, 1),
5055 BPF_EXIT_INSN(), /* bad exit */
5056 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
5057 BPF_EXIT_INSN(),
5058 },
5059 INTERNAL,
5060 { },
5061 { { 0, 1 } },
5062 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005063 /* BPF_JMP | BPF_JSGE | BPF_K */
5064 {
5065 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1",
5066 .u.insns_int = {
5067 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5068 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
5069 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1),
5070 BPF_EXIT_INSN(),
5071 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5072 BPF_EXIT_INSN(),
5073 },
5074 INTERNAL,
5075 { },
5076 { { 0, 1 } },
5077 },
5078 {
5079 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1",
5080 .u.insns_int = {
5081 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5082 BPF_LD_IMM64(R1, 0xffffffffffffffffLL),
5083 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1),
5084 BPF_EXIT_INSN(),
5085 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5086 BPF_EXIT_INSN(),
5087 },
5088 INTERNAL,
5089 { },
5090 { { 0, 1 } },
5091 },
David Daney791caeb2017-05-24 16:35:49 -07005092 {
5093 "JMP_JSGE_K: Signed jump: value walk 1",
5094 .u.insns_int = {
5095 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5096 BPF_LD_IMM64(R1, -3),
5097 BPF_JMP_IMM(BPF_JSGE, R1, 0, 6),
5098 BPF_ALU64_IMM(BPF_ADD, R1, 1),
5099 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
5100 BPF_ALU64_IMM(BPF_ADD, R1, 1),
5101 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
5102 BPF_ALU64_IMM(BPF_ADD, R1, 1),
5103 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
5104 BPF_EXIT_INSN(), /* bad exit */
5105 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
5106 BPF_EXIT_INSN(),
5107 },
5108 INTERNAL,
5109 { },
5110 { { 0, 1 } },
5111 },
5112 {
5113 "JMP_JSGE_K: Signed jump: value walk 2",
5114 .u.insns_int = {
5115 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5116 BPF_LD_IMM64(R1, -3),
5117 BPF_JMP_IMM(BPF_JSGE, R1, 0, 4),
5118 BPF_ALU64_IMM(BPF_ADD, R1, 2),
5119 BPF_JMP_IMM(BPF_JSGE, R1, 0, 2),
5120 BPF_ALU64_IMM(BPF_ADD, R1, 2),
5121 BPF_JMP_IMM(BPF_JSGE, R1, 0, 1),
5122 BPF_EXIT_INSN(), /* bad exit */
5123 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* good exit */
5124 BPF_EXIT_INSN(),
5125 },
5126 INTERNAL,
5127 { },
5128 { { 0, 1 } },
5129 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005130 /* BPF_JMP | BPF_JGT | BPF_K */
5131 {
5132 "JMP_JGT_K: if (3 > 2) return 1",
5133 .u.insns_int = {
5134 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5135 BPF_LD_IMM64(R1, 3),
5136 BPF_JMP_IMM(BPF_JGT, R1, 2, 1),
5137 BPF_EXIT_INSN(),
5138 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5139 BPF_EXIT_INSN(),
5140 },
5141 INTERNAL,
5142 { },
5143 { { 0, 1 } },
5144 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05305145 {
5146 "JMP_JGT_K: Unsigned jump: if (-1 > 1) return 1",
5147 .u.insns_int = {
5148 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5149 BPF_LD_IMM64(R1, -1),
5150 BPF_JMP_IMM(BPF_JGT, R1, 1, 1),
5151 BPF_EXIT_INSN(),
5152 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5153 BPF_EXIT_INSN(),
5154 },
5155 INTERNAL,
5156 { },
5157 { { 0, 1 } },
5158 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005159 /* BPF_JMP | BPF_JLT | BPF_K */
5160 {
5161 "JMP_JLT_K: if (2 < 3) return 1",
5162 .u.insns_int = {
5163 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5164 BPF_LD_IMM64(R1, 2),
5165 BPF_JMP_IMM(BPF_JLT, R1, 3, 1),
5166 BPF_EXIT_INSN(),
5167 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5168 BPF_EXIT_INSN(),
5169 },
5170 INTERNAL,
5171 { },
5172 { { 0, 1 } },
5173 },
5174 {
5175 "JMP_JGT_K: Unsigned jump: if (1 < -1) return 1",
5176 .u.insns_int = {
5177 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5178 BPF_LD_IMM64(R1, 1),
5179 BPF_JMP_IMM(BPF_JLT, R1, -1, 1),
5180 BPF_EXIT_INSN(),
5181 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5182 BPF_EXIT_INSN(),
5183 },
5184 INTERNAL,
5185 { },
5186 { { 0, 1 } },
5187 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005188 /* BPF_JMP | BPF_JGE | BPF_K */
5189 {
5190 "JMP_JGE_K: if (3 >= 2) return 1",
5191 .u.insns_int = {
5192 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5193 BPF_LD_IMM64(R1, 3),
5194 BPF_JMP_IMM(BPF_JGE, R1, 2, 1),
5195 BPF_EXIT_INSN(),
5196 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5197 BPF_EXIT_INSN(),
5198 },
5199 INTERNAL,
5200 { },
5201 { { 0, 1 } },
5202 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005203 /* BPF_JMP | BPF_JLE | BPF_K */
5204 {
5205 "JMP_JLE_K: if (2 <= 3) return 1",
5206 .u.insns_int = {
5207 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5208 BPF_LD_IMM64(R1, 2),
5209 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
5210 BPF_EXIT_INSN(),
5211 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5212 BPF_EXIT_INSN(),
5213 },
5214 INTERNAL,
5215 { },
5216 { { 0, 1 } },
5217 },
Michael Holzheufe593842015-05-22 08:36:40 -07005218 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */
5219 {
5220 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)",
5221 .u.insns_int = {
5222 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
5223 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
5224 BPF_EXIT_INSN(),
5225 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
5226 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */
5227 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */
5228 BPF_EXIT_INSN(),
5229 },
5230 INTERNAL,
5231 { },
5232 { { 0, 1 } },
5233 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005234 {
5235 "JMP_JGE_K: if (3 >= 3) return 1",
5236 .u.insns_int = {
5237 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5238 BPF_LD_IMM64(R1, 3),
5239 BPF_JMP_IMM(BPF_JGE, R1, 3, 1),
5240 BPF_EXIT_INSN(),
5241 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5242 BPF_EXIT_INSN(),
5243 },
5244 INTERNAL,
5245 { },
5246 { { 0, 1 } },
5247 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005248 /* BPF_JMP | BPF_JLT | BPF_K jump backwards */
5249 {
5250 "JMP_JGT_K: if (2 < 3) return 1 (jump backwards)",
5251 .u.insns_int = {
5252 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */
5253 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */
5254 BPF_EXIT_INSN(),
5255 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */
5256 BPF_LD_IMM64(R1, 2), /* note: this takes 2 insns */
5257 BPF_JMP_IMM(BPF_JLT, R1, 3, -6), /* goto out */
5258 BPF_EXIT_INSN(),
5259 },
5260 INTERNAL,
5261 { },
5262 { { 0, 1 } },
5263 },
5264 {
5265 "JMP_JLE_K: if (3 <= 3) return 1",
5266 .u.insns_int = {
5267 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5268 BPF_LD_IMM64(R1, 3),
5269 BPF_JMP_IMM(BPF_JLE, R1, 3, 1),
5270 BPF_EXIT_INSN(),
5271 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5272 BPF_EXIT_INSN(),
5273 },
5274 INTERNAL,
5275 { },
5276 { { 0, 1 } },
5277 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005278 /* BPF_JMP | BPF_JNE | BPF_K */
5279 {
5280 "JMP_JNE_K: if (3 != 2) return 1",
5281 .u.insns_int = {
5282 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5283 BPF_LD_IMM64(R1, 3),
5284 BPF_JMP_IMM(BPF_JNE, R1, 2, 1),
5285 BPF_EXIT_INSN(),
5286 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5287 BPF_EXIT_INSN(),
5288 },
5289 INTERNAL,
5290 { },
5291 { { 0, 1 } },
5292 },
5293 /* BPF_JMP | BPF_JEQ | BPF_K */
5294 {
5295 "JMP_JEQ_K: if (3 == 3) return 1",
5296 .u.insns_int = {
5297 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5298 BPF_LD_IMM64(R1, 3),
5299 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1),
5300 BPF_EXIT_INSN(),
5301 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5302 BPF_EXIT_INSN(),
5303 },
5304 INTERNAL,
5305 { },
5306 { { 0, 1 } },
5307 },
5308 /* BPF_JMP | BPF_JSET | BPF_K */
5309 {
5310 "JMP_JSET_K: if (0x3 & 0x2) return 1",
5311 .u.insns_int = {
5312 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5313 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05305314 BPF_JMP_IMM(BPF_JSET, R1, 2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07005315 BPF_EXIT_INSN(),
5316 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5317 BPF_EXIT_INSN(),
5318 },
5319 INTERNAL,
5320 { },
5321 { { 0, 1 } },
5322 },
5323 {
5324 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1",
5325 .u.insns_int = {
5326 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5327 BPF_LD_IMM64(R1, 3),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05305328 BPF_JMP_IMM(BPF_JSET, R1, 0xffffffff, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07005329 BPF_EXIT_INSN(),
5330 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5331 BPF_EXIT_INSN(),
5332 },
5333 INTERNAL,
5334 { },
5335 { { 0, 1 } },
5336 },
5337 /* BPF_JMP | BPF_JSGT | BPF_X */
5338 {
5339 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1",
5340 .u.insns_int = {
5341 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5342 BPF_LD_IMM64(R1, -1),
5343 BPF_LD_IMM64(R2, -2),
5344 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
5345 BPF_EXIT_INSN(),
5346 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5347 BPF_EXIT_INSN(),
5348 },
5349 INTERNAL,
5350 { },
5351 { { 0, 1 } },
5352 },
5353 {
5354 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0",
5355 .u.insns_int = {
5356 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5357 BPF_LD_IMM64(R1, -1),
5358 BPF_LD_IMM64(R2, -1),
5359 BPF_JMP_REG(BPF_JSGT, R1, R2, 1),
5360 BPF_EXIT_INSN(),
5361 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5362 BPF_EXIT_INSN(),
5363 },
5364 INTERNAL,
5365 { },
5366 { { 0, 1 } },
5367 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005368 /* BPF_JMP | BPF_JSLT | BPF_X */
5369 {
5370 "JMP_JSLT_X: Signed jump: if (-2 < -1) return 1",
5371 .u.insns_int = {
5372 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5373 BPF_LD_IMM64(R1, -1),
5374 BPF_LD_IMM64(R2, -2),
5375 BPF_JMP_REG(BPF_JSLT, R2, R1, 1),
5376 BPF_EXIT_INSN(),
5377 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5378 BPF_EXIT_INSN(),
5379 },
5380 INTERNAL,
5381 { },
5382 { { 0, 1 } },
5383 },
5384 {
5385 "JMP_JSLT_X: Signed jump: if (-1 < -1) return 0",
5386 .u.insns_int = {
5387 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5388 BPF_LD_IMM64(R1, -1),
5389 BPF_LD_IMM64(R2, -1),
5390 BPF_JMP_REG(BPF_JSLT, R1, R2, 1),
5391 BPF_EXIT_INSN(),
5392 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5393 BPF_EXIT_INSN(),
5394 },
5395 INTERNAL,
5396 { },
5397 { { 0, 1 } },
5398 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005399 /* BPF_JMP | BPF_JSGE | BPF_X */
5400 {
5401 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1",
5402 .u.insns_int = {
5403 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5404 BPF_LD_IMM64(R1, -1),
5405 BPF_LD_IMM64(R2, -2),
5406 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
5407 BPF_EXIT_INSN(),
5408 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5409 BPF_EXIT_INSN(),
5410 },
5411 INTERNAL,
5412 { },
5413 { { 0, 1 } },
5414 },
5415 {
5416 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1",
5417 .u.insns_int = {
5418 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5419 BPF_LD_IMM64(R1, -1),
5420 BPF_LD_IMM64(R2, -1),
5421 BPF_JMP_REG(BPF_JSGE, R1, R2, 1),
5422 BPF_EXIT_INSN(),
5423 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5424 BPF_EXIT_INSN(),
5425 },
5426 INTERNAL,
5427 { },
5428 { { 0, 1 } },
5429 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005430 /* BPF_JMP | BPF_JSLE | BPF_X */
5431 {
5432 "JMP_JSLE_X: Signed jump: if (-2 <= -1) return 1",
5433 .u.insns_int = {
5434 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5435 BPF_LD_IMM64(R1, -1),
5436 BPF_LD_IMM64(R2, -2),
5437 BPF_JMP_REG(BPF_JSLE, R2, R1, 1),
5438 BPF_EXIT_INSN(),
5439 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5440 BPF_EXIT_INSN(),
5441 },
5442 INTERNAL,
5443 { },
5444 { { 0, 1 } },
5445 },
5446 {
5447 "JMP_JSLE_X: Signed jump: if (-1 <= -1) return 1",
5448 .u.insns_int = {
5449 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5450 BPF_LD_IMM64(R1, -1),
5451 BPF_LD_IMM64(R2, -1),
5452 BPF_JMP_REG(BPF_JSLE, R1, R2, 1),
5453 BPF_EXIT_INSN(),
5454 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5455 BPF_EXIT_INSN(),
5456 },
5457 INTERNAL,
5458 { },
5459 { { 0, 1 } },
5460 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005461 /* BPF_JMP | BPF_JGT | BPF_X */
5462 {
5463 "JMP_JGT_X: if (3 > 2) return 1",
5464 .u.insns_int = {
5465 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5466 BPF_LD_IMM64(R1, 3),
5467 BPF_LD_IMM64(R2, 2),
5468 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
5469 BPF_EXIT_INSN(),
5470 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5471 BPF_EXIT_INSN(),
5472 },
5473 INTERNAL,
5474 { },
5475 { { 0, 1 } },
5476 },
Naveen N. Raoc7395d62016-04-05 15:32:54 +05305477 {
5478 "JMP_JGT_X: Unsigned jump: if (-1 > 1) return 1",
5479 .u.insns_int = {
5480 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5481 BPF_LD_IMM64(R1, -1),
5482 BPF_LD_IMM64(R2, 1),
5483 BPF_JMP_REG(BPF_JGT, R1, R2, 1),
5484 BPF_EXIT_INSN(),
5485 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5486 BPF_EXIT_INSN(),
5487 },
5488 INTERNAL,
5489 { },
5490 { { 0, 1 } },
5491 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005492 /* BPF_JMP | BPF_JLT | BPF_X */
5493 {
5494 "JMP_JLT_X: if (2 < 3) return 1",
5495 .u.insns_int = {
5496 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5497 BPF_LD_IMM64(R1, 3),
5498 BPF_LD_IMM64(R2, 2),
5499 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
5500 BPF_EXIT_INSN(),
5501 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5502 BPF_EXIT_INSN(),
5503 },
5504 INTERNAL,
5505 { },
5506 { { 0, 1 } },
5507 },
5508 {
5509 "JMP_JLT_X: Unsigned jump: if (1 < -1) return 1",
5510 .u.insns_int = {
5511 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5512 BPF_LD_IMM64(R1, -1),
5513 BPF_LD_IMM64(R2, 1),
5514 BPF_JMP_REG(BPF_JLT, R2, R1, 1),
5515 BPF_EXIT_INSN(),
5516 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5517 BPF_EXIT_INSN(),
5518 },
5519 INTERNAL,
5520 { },
5521 { { 0, 1 } },
5522 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005523 /* BPF_JMP | BPF_JGE | BPF_X */
5524 {
5525 "JMP_JGE_X: if (3 >= 2) return 1",
5526 .u.insns_int = {
5527 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5528 BPF_LD_IMM64(R1, 3),
5529 BPF_LD_IMM64(R2, 2),
5530 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5531 BPF_EXIT_INSN(),
5532 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5533 BPF_EXIT_INSN(),
5534 },
5535 INTERNAL,
5536 { },
5537 { { 0, 1 } },
5538 },
5539 {
5540 "JMP_JGE_X: if (3 >= 3) return 1",
5541 .u.insns_int = {
5542 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5543 BPF_LD_IMM64(R1, 3),
5544 BPF_LD_IMM64(R2, 3),
5545 BPF_JMP_REG(BPF_JGE, R1, R2, 1),
5546 BPF_EXIT_INSN(),
5547 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5548 BPF_EXIT_INSN(),
5549 },
5550 INTERNAL,
5551 { },
5552 { { 0, 1 } },
5553 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005554 /* BPF_JMP | BPF_JLE | BPF_X */
5555 {
5556 "JMP_JLE_X: if (2 <= 3) return 1",
5557 .u.insns_int = {
5558 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5559 BPF_LD_IMM64(R1, 3),
5560 BPF_LD_IMM64(R2, 2),
5561 BPF_JMP_REG(BPF_JLE, R2, R1, 1),
5562 BPF_EXIT_INSN(),
5563 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5564 BPF_EXIT_INSN(),
5565 },
5566 INTERNAL,
5567 { },
5568 { { 0, 1 } },
5569 },
5570 {
5571 "JMP_JLE_X: if (3 <= 3) return 1",
5572 .u.insns_int = {
5573 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5574 BPF_LD_IMM64(R1, 3),
5575 BPF_LD_IMM64(R2, 3),
5576 BPF_JMP_REG(BPF_JLE, R1, R2, 1),
5577 BPF_EXIT_INSN(),
5578 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5579 BPF_EXIT_INSN(),
5580 },
5581 INTERNAL,
5582 { },
5583 { { 0, 1 } },
5584 },
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005585 {
5586 /* Mainly testing JIT + imm64 here. */
5587 "JMP_JGE_X: ldimm64 test 1",
5588 .u.insns_int = {
5589 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5590 BPF_LD_IMM64(R1, 3),
5591 BPF_LD_IMM64(R2, 2),
5592 BPF_JMP_REG(BPF_JGE, R1, R2, 2),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005593 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5594 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005595 BPF_EXIT_INSN(),
5596 },
5597 INTERNAL,
5598 { },
5599 { { 0, 0xeeeeeeeeU } },
5600 },
5601 {
5602 "JMP_JGE_X: ldimm64 test 2",
5603 .u.insns_int = {
5604 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5605 BPF_LD_IMM64(R1, 3),
5606 BPF_LD_IMM64(R2, 2),
5607 BPF_JMP_REG(BPF_JGE, R1, R2, 0),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005608 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005609 BPF_EXIT_INSN(),
5610 },
5611 INTERNAL,
5612 { },
5613 { { 0, 0xffffffffU } },
5614 },
5615 {
5616 "JMP_JGE_X: ldimm64 test 3",
5617 .u.insns_int = {
5618 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5619 BPF_LD_IMM64(R1, 3),
5620 BPF_LD_IMM64(R2, 2),
5621 BPF_JMP_REG(BPF_JGE, R1, R2, 4),
Geert Uytterhoeven86f8e242017-05-03 13:31:04 +02005622 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5623 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
Daniel Borkmannddc665a2017-05-02 20:34:54 +02005624 BPF_EXIT_INSN(),
5625 },
5626 INTERNAL,
5627 { },
5628 { { 0, 1 } },
5629 },
Daniel Borkmann92b31a92017-08-10 01:39:55 +02005630 {
5631 "JMP_JLE_X: ldimm64 test 1",
5632 .u.insns_int = {
5633 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5634 BPF_LD_IMM64(R1, 3),
5635 BPF_LD_IMM64(R2, 2),
5636 BPF_JMP_REG(BPF_JLE, R2, R1, 2),
5637 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5638 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5639 BPF_EXIT_INSN(),
5640 },
5641 INTERNAL,
5642 { },
5643 { { 0, 0xeeeeeeeeU } },
5644 },
5645 {
5646 "JMP_JLE_X: ldimm64 test 2",
5647 .u.insns_int = {
5648 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5649 BPF_LD_IMM64(R1, 3),
5650 BPF_LD_IMM64(R2, 2),
5651 BPF_JMP_REG(BPF_JLE, R2, R1, 0),
5652 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5653 BPF_EXIT_INSN(),
5654 },
5655 INTERNAL,
5656 { },
5657 { { 0, 0xffffffffU } },
5658 },
5659 {
5660 "JMP_JLE_X: ldimm64 test 3",
5661 .u.insns_int = {
5662 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5663 BPF_LD_IMM64(R1, 3),
5664 BPF_LD_IMM64(R2, 2),
5665 BPF_JMP_REG(BPF_JLE, R2, R1, 4),
5666 BPF_LD_IMM64(R0, 0xffffffffffffffffULL),
5667 BPF_LD_IMM64(R0, 0xeeeeeeeeeeeeeeeeULL),
5668 BPF_EXIT_INSN(),
5669 },
5670 INTERNAL,
5671 { },
5672 { { 0, 1 } },
5673 },
Michael Holzheucffc6422015-05-11 22:22:44 -07005674 /* BPF_JMP | BPF_JNE | BPF_X */
5675 {
5676 "JMP_JNE_X: if (3 != 2) return 1",
5677 .u.insns_int = {
5678 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5679 BPF_LD_IMM64(R1, 3),
5680 BPF_LD_IMM64(R2, 2),
5681 BPF_JMP_REG(BPF_JNE, R1, R2, 1),
5682 BPF_EXIT_INSN(),
5683 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5684 BPF_EXIT_INSN(),
5685 },
5686 INTERNAL,
5687 { },
5688 { { 0, 1 } },
5689 },
5690 /* BPF_JMP | BPF_JEQ | BPF_X */
5691 {
5692 "JMP_JEQ_X: if (3 == 3) return 1",
5693 .u.insns_int = {
5694 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5695 BPF_LD_IMM64(R1, 3),
5696 BPF_LD_IMM64(R2, 3),
5697 BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
5698 BPF_EXIT_INSN(),
5699 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5700 BPF_EXIT_INSN(),
5701 },
5702 INTERNAL,
5703 { },
5704 { { 0, 1 } },
5705 },
5706 /* BPF_JMP | BPF_JSET | BPF_X */
5707 {
5708 "JMP_JSET_X: if (0x3 & 0x2) return 1",
5709 .u.insns_int = {
5710 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5711 BPF_LD_IMM64(R1, 3),
5712 BPF_LD_IMM64(R2, 2),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05305713 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07005714 BPF_EXIT_INSN(),
5715 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5716 BPF_EXIT_INSN(),
5717 },
5718 INTERNAL,
5719 { },
5720 { { 0, 1 } },
5721 },
5722 {
5723 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1",
5724 .u.insns_int = {
5725 BPF_ALU32_IMM(BPF_MOV, R0, 0),
5726 BPF_LD_IMM64(R1, 3),
5727 BPF_LD_IMM64(R2, 0xffffffff),
Naveen N. Rao9f134c32016-04-05 15:32:53 +05305728 BPF_JMP_REG(BPF_JSET, R1, R2, 1),
Michael Holzheucffc6422015-05-11 22:22:44 -07005729 BPF_EXIT_INSN(),
5730 BPF_ALU32_IMM(BPF_MOV, R0, 1),
5731 BPF_EXIT_INSN(),
5732 },
5733 INTERNAL,
5734 { },
5735 { { 0, 1 } },
5736 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005737 {
5738 "JMP_JA: Jump, gap, jump, ...",
5739 { },
5740 CLASSIC | FLAG_NO_DATA,
5741 { },
5742 { { 0, 0xababcbac } },
5743 .fill_helper = bpf_fill_ja,
5744 },
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005745 { /* Mainly checking JIT here. */
5746 "BPF_MAXINSNS: Maximum possible literals",
5747 { },
5748 CLASSIC | FLAG_NO_DATA,
5749 { },
5750 { { 0, 0xffffffff } },
5751 .fill_helper = bpf_fill_maxinsns1,
5752 },
5753 { /* Mainly checking JIT here. */
5754 "BPF_MAXINSNS: Single literal",
5755 { },
5756 CLASSIC | FLAG_NO_DATA,
5757 { },
5758 { { 0, 0xfefefefe } },
5759 .fill_helper = bpf_fill_maxinsns2,
5760 },
5761 { /* Mainly checking JIT here. */
5762 "BPF_MAXINSNS: Run/add until end",
5763 { },
5764 CLASSIC | FLAG_NO_DATA,
5765 { },
5766 { { 0, 0x947bf368 } },
5767 .fill_helper = bpf_fill_maxinsns3,
5768 },
5769 {
5770 "BPF_MAXINSNS: Too many instructions",
5771 { },
5772 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5773 { },
5774 { },
5775 .fill_helper = bpf_fill_maxinsns4,
Yonghong Song09584b42018-02-02 22:37:15 -08005776 .expected_errcode = -EINVAL,
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005777 },
5778 { /* Mainly checking JIT here. */
5779 "BPF_MAXINSNS: Very long jump",
5780 { },
5781 CLASSIC | FLAG_NO_DATA,
5782 { },
5783 { { 0, 0xabababab } },
5784 .fill_helper = bpf_fill_maxinsns5,
5785 },
5786 { /* Mainly checking JIT here. */
5787 "BPF_MAXINSNS: Ctx heavy transformations",
5788 { },
5789 CLASSIC,
5790 { },
5791 {
Michał Mirosław0c4b2d32018-11-10 19:58:36 +01005792 { 1, SKB_VLAN_PRESENT },
5793 { 10, SKB_VLAN_PRESENT }
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02005794 },
5795 .fill_helper = bpf_fill_maxinsns6,
5796 },
5797 { /* Mainly checking JIT here. */
5798 "BPF_MAXINSNS: Call heavy transformations",
5799 { },
5800 CLASSIC | FLAG_NO_DATA,
5801 { },
5802 { { 1, 0 }, { 10, 0 } },
5803 .fill_helper = bpf_fill_maxinsns7,
5804 },
5805 { /* Mainly checking JIT here. */
5806 "BPF_MAXINSNS: Jump heavy test",
5807 { },
5808 CLASSIC | FLAG_NO_DATA,
5809 { },
5810 { { 0, 0xffffffff } },
5811 .fill_helper = bpf_fill_maxinsns8,
5812 },
Daniel Borkmann3b529602015-05-23 01:10:07 +02005813 { /* Mainly checking JIT here. */
5814 "BPF_MAXINSNS: Very long jump backwards",
5815 { },
5816 INTERNAL | FLAG_NO_DATA,
5817 { },
5818 { { 0, 0xcbababab } },
5819 .fill_helper = bpf_fill_maxinsns9,
5820 },
5821 { /* Mainly checking JIT here. */
5822 "BPF_MAXINSNS: Edge hopping nuthouse",
5823 { },
5824 INTERNAL | FLAG_NO_DATA,
5825 { },
5826 { { 0, 0xabababac } },
5827 .fill_helper = bpf_fill_maxinsns10,
5828 },
Daniel Borkmannbde28bc2015-05-26 22:35:43 +02005829 {
5830 "BPF_MAXINSNS: Jump, gap, jump, ...",
5831 { },
5832 CLASSIC | FLAG_NO_DATA,
5833 { },
5834 { { 0, 0xababcbac } },
5835 .fill_helper = bpf_fill_maxinsns11,
5836 },
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005837 {
Daniel Borkmannbe088152018-06-02 23:06:32 +02005838 "BPF_MAXINSNS: jump over MSH",
5839 { },
5840 CLASSIC | FLAG_EXPECTED_FAIL,
5841 { 0xfa, 0xfb, 0xfc, 0xfd, },
5842 { { 4, 0xabababab } },
5843 .fill_helper = bpf_fill_maxinsns12,
5844 .expected_errcode = -EINVAL,
5845 },
5846 {
5847 "BPF_MAXINSNS: exec all MSH",
5848 { },
5849 CLASSIC,
5850 { 0xfa, 0xfb, 0xfc, 0xfd, },
5851 { { 4, 0xababab83 } },
5852 .fill_helper = bpf_fill_maxinsns13,
5853 },
5854 {
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07005855 "BPF_MAXINSNS: ld_abs+get_processor_id",
5856 { },
5857 CLASSIC,
5858 { },
5859 { { 1, 0xbee } },
5860 .fill_helper = bpf_fill_ld_abs_get_processor_id,
5861 },
Nicolas Schichan2cf1ad72015-08-04 15:19:09 +02005862 /*
5863 * LD_IND / LD_ABS on fragmented SKBs
5864 */
5865 {
5866 "LD_IND byte frag",
5867 .u.insns = {
5868 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5869 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x0),
5870 BPF_STMT(BPF_RET | BPF_A, 0x0),
5871 },
5872 CLASSIC | FLAG_SKB_FRAG,
5873 { },
5874 { {0x40, 0x42} },
5875 .frag_data = {
5876 0x42, 0x00, 0x00, 0x00,
5877 0x43, 0x44, 0x00, 0x00,
5878 0x21, 0x07, 0x19, 0x83,
5879 },
5880 },
5881 {
5882 "LD_IND halfword frag",
5883 .u.insns = {
5884 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5885 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x4),
5886 BPF_STMT(BPF_RET | BPF_A, 0x0),
5887 },
5888 CLASSIC | FLAG_SKB_FRAG,
5889 { },
5890 { {0x40, 0x4344} },
5891 .frag_data = {
5892 0x42, 0x00, 0x00, 0x00,
5893 0x43, 0x44, 0x00, 0x00,
5894 0x21, 0x07, 0x19, 0x83,
5895 },
5896 },
5897 {
5898 "LD_IND word frag",
5899 .u.insns = {
5900 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5901 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x8),
5902 BPF_STMT(BPF_RET | BPF_A, 0x0),
5903 },
5904 CLASSIC | FLAG_SKB_FRAG,
5905 { },
5906 { {0x40, 0x21071983} },
5907 .frag_data = {
5908 0x42, 0x00, 0x00, 0x00,
5909 0x43, 0x44, 0x00, 0x00,
5910 0x21, 0x07, 0x19, 0x83,
5911 },
5912 },
5913 {
5914 "LD_IND halfword mixed head/frag",
5915 .u.insns = {
5916 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5917 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
5918 BPF_STMT(BPF_RET | BPF_A, 0x0),
5919 },
5920 CLASSIC | FLAG_SKB_FRAG,
5921 { [0x3e] = 0x25, [0x3f] = 0x05, },
5922 { {0x40, 0x0519} },
5923 .frag_data = { 0x19, 0x82 },
5924 },
5925 {
5926 "LD_IND word mixed head/frag",
5927 .u.insns = {
5928 BPF_STMT(BPF_LDX | BPF_IMM, 0x40),
5929 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
5930 BPF_STMT(BPF_RET | BPF_A, 0x0),
5931 },
5932 CLASSIC | FLAG_SKB_FRAG,
5933 { [0x3e] = 0x25, [0x3f] = 0x05, },
5934 { {0x40, 0x25051982} },
5935 .frag_data = { 0x19, 0x82 },
5936 },
5937 {
5938 "LD_ABS byte frag",
5939 .u.insns = {
5940 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x40),
5941 BPF_STMT(BPF_RET | BPF_A, 0x0),
5942 },
5943 CLASSIC | FLAG_SKB_FRAG,
5944 { },
5945 { {0x40, 0x42} },
5946 .frag_data = {
5947 0x42, 0x00, 0x00, 0x00,
5948 0x43, 0x44, 0x00, 0x00,
5949 0x21, 0x07, 0x19, 0x83,
5950 },
5951 },
5952 {
5953 "LD_ABS halfword frag",
5954 .u.insns = {
5955 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x44),
5956 BPF_STMT(BPF_RET | BPF_A, 0x0),
5957 },
5958 CLASSIC | FLAG_SKB_FRAG,
5959 { },
5960 { {0x40, 0x4344} },
5961 .frag_data = {
5962 0x42, 0x00, 0x00, 0x00,
5963 0x43, 0x44, 0x00, 0x00,
5964 0x21, 0x07, 0x19, 0x83,
5965 },
5966 },
5967 {
5968 "LD_ABS word frag",
5969 .u.insns = {
5970 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x48),
5971 BPF_STMT(BPF_RET | BPF_A, 0x0),
5972 },
5973 CLASSIC | FLAG_SKB_FRAG,
5974 { },
5975 { {0x40, 0x21071983} },
5976 .frag_data = {
5977 0x42, 0x00, 0x00, 0x00,
5978 0x43, 0x44, 0x00, 0x00,
5979 0x21, 0x07, 0x19, 0x83,
5980 },
5981 },
5982 {
5983 "LD_ABS halfword mixed head/frag",
5984 .u.insns = {
5985 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
5986 BPF_STMT(BPF_RET | BPF_A, 0x0),
5987 },
5988 CLASSIC | FLAG_SKB_FRAG,
5989 { [0x3e] = 0x25, [0x3f] = 0x05, },
5990 { {0x40, 0x0519} },
5991 .frag_data = { 0x19, 0x82 },
5992 },
5993 {
5994 "LD_ABS word mixed head/frag",
5995 .u.insns = {
5996 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3e),
5997 BPF_STMT(BPF_RET | BPF_A, 0x0),
5998 },
5999 CLASSIC | FLAG_SKB_FRAG,
6000 { [0x3e] = 0x25, [0x3f] = 0x05, },
6001 { {0x40, 0x25051982} },
6002 .frag_data = { 0x19, 0x82 },
6003 },
Nicolas Schichan08fcb082015-08-04 15:19:11 +02006004 /*
6005 * LD_IND / LD_ABS on non fragmented SKBs
6006 */
6007 {
6008 /*
6009 * this tests that the JIT/interpreter correctly resets X
6010 * before using it in an LD_IND instruction.
6011 */
6012 "LD_IND byte default X",
6013 .u.insns = {
6014 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
6015 BPF_STMT(BPF_RET | BPF_A, 0x0),
6016 },
6017 CLASSIC,
6018 { [0x1] = 0x42 },
6019 { {0x40, 0x42 } },
6020 },
6021 {
6022 "LD_IND byte positive offset",
6023 .u.insns = {
6024 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6025 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
6026 BPF_STMT(BPF_RET | BPF_A, 0x0),
6027 },
6028 CLASSIC,
6029 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6030 { {0x40, 0x82 } },
6031 },
6032 {
6033 "LD_IND byte negative offset",
6034 .u.insns = {
6035 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6036 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x1),
6037 BPF_STMT(BPF_RET | BPF_A, 0x0),
6038 },
6039 CLASSIC,
6040 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6041 { {0x40, 0x05 } },
6042 },
6043 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02006044 "LD_IND byte positive offset, all ff",
6045 .u.insns = {
6046 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6047 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
6048 BPF_STMT(BPF_RET | BPF_A, 0x0),
6049 },
6050 CLASSIC,
6051 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6052 { {0x40, 0xff } },
6053 },
6054 {
6055 "LD_IND byte positive offset, out of bounds",
6056 .u.insns = {
6057 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6058 BPF_STMT(BPF_LD | BPF_IND | BPF_B, 0x1),
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_IND byte negative offset, out of bounds",
6067 .u.insns = {
6068 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6069 BPF_STMT(BPF_LD | BPF_IND | BPF_B, -0x3f),
6070 BPF_STMT(BPF_RET | BPF_A, 0x0),
6071 },
6072 CLASSIC,
6073 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6074 { {0x3f, 0 } },
6075 },
6076 {
6077 "LD_IND byte negative offset, multiple calls",
6078 .u.insns = {
6079 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
6080 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 1),
6081 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 2),
6082 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 3),
6083 BPF_STMT(BPF_LD | BPF_IND | BPF_B, SKF_LL_OFF + 4),
6084 BPF_STMT(BPF_RET | BPF_A, 0x0),
6085 },
6086 CLASSIC,
6087 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6088 { {0x40, 0x82 }, },
6089 },
6090 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02006091 "LD_IND halfword positive offset",
6092 .u.insns = {
6093 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
6094 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x2),
6095 BPF_STMT(BPF_RET | BPF_A, 0x0),
6096 },
6097 CLASSIC,
6098 {
6099 [0x1c] = 0xaa, [0x1d] = 0x55,
6100 [0x1e] = 0xbb, [0x1f] = 0x66,
6101 [0x20] = 0xcc, [0x21] = 0x77,
6102 [0x22] = 0xdd, [0x23] = 0x88,
6103 },
6104 { {0x40, 0xdd88 } },
6105 },
6106 {
6107 "LD_IND halfword negative offset",
6108 .u.insns = {
6109 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
6110 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x2),
6111 BPF_STMT(BPF_RET | BPF_A, 0x0),
6112 },
6113 CLASSIC,
6114 {
6115 [0x1c] = 0xaa, [0x1d] = 0x55,
6116 [0x1e] = 0xbb, [0x1f] = 0x66,
6117 [0x20] = 0xcc, [0x21] = 0x77,
6118 [0x22] = 0xdd, [0x23] = 0x88,
6119 },
6120 { {0x40, 0xbb66 } },
6121 },
6122 {
6123 "LD_IND halfword unaligned",
6124 .u.insns = {
6125 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
6126 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x1),
6127 BPF_STMT(BPF_RET | BPF_A, 0x0),
6128 },
6129 CLASSIC,
6130 {
6131 [0x1c] = 0xaa, [0x1d] = 0x55,
6132 [0x1e] = 0xbb, [0x1f] = 0x66,
6133 [0x20] = 0xcc, [0x21] = 0x77,
6134 [0x22] = 0xdd, [0x23] = 0x88,
6135 },
6136 { {0x40, 0x66cc } },
6137 },
6138 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02006139 "LD_IND halfword positive offset, all ff",
6140 .u.insns = {
6141 BPF_STMT(BPF_LDX | BPF_IMM, 0x3d),
6142 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
6143 BPF_STMT(BPF_RET | BPF_A, 0x0),
6144 },
6145 CLASSIC,
6146 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6147 { {0x40, 0xffff } },
6148 },
6149 {
6150 "LD_IND halfword positive offset, out of bounds",
6151 .u.insns = {
6152 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6153 BPF_STMT(BPF_LD | BPF_IND | BPF_H, 0x1),
6154 BPF_STMT(BPF_RET | BPF_A, 0x0),
6155 },
6156 CLASSIC,
6157 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6158 { {0x3f, 0 }, },
6159 },
6160 {
6161 "LD_IND halfword negative offset, out of bounds",
6162 .u.insns = {
6163 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6164 BPF_STMT(BPF_LD | BPF_IND | BPF_H, -0x3f),
6165 BPF_STMT(BPF_RET | BPF_A, 0x0),
6166 },
6167 CLASSIC,
6168 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6169 { {0x3f, 0 } },
6170 },
6171 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02006172 "LD_IND word positive offset",
6173 .u.insns = {
6174 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
6175 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x4),
6176 BPF_STMT(BPF_RET | BPF_A, 0x0),
6177 },
6178 CLASSIC,
6179 {
6180 [0x1c] = 0xaa, [0x1d] = 0x55,
6181 [0x1e] = 0xbb, [0x1f] = 0x66,
6182 [0x20] = 0xcc, [0x21] = 0x77,
6183 [0x22] = 0xdd, [0x23] = 0x88,
6184 [0x24] = 0xee, [0x25] = 0x99,
6185 [0x26] = 0xff, [0x27] = 0xaa,
6186 },
6187 { {0x40, 0xee99ffaa } },
6188 },
6189 {
6190 "LD_IND word negative offset",
6191 .u.insns = {
6192 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
6193 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x4),
6194 BPF_STMT(BPF_RET | BPF_A, 0x0),
6195 },
6196 CLASSIC,
6197 {
6198 [0x1c] = 0xaa, [0x1d] = 0x55,
6199 [0x1e] = 0xbb, [0x1f] = 0x66,
6200 [0x20] = 0xcc, [0x21] = 0x77,
6201 [0x22] = 0xdd, [0x23] = 0x88,
6202 [0x24] = 0xee, [0x25] = 0x99,
6203 [0x26] = 0xff, [0x27] = 0xaa,
6204 },
6205 { {0x40, 0xaa55bb66 } },
6206 },
6207 {
6208 "LD_IND word unaligned (addr & 3 == 2)",
6209 .u.insns = {
6210 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
6211 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x2),
6212 BPF_STMT(BPF_RET | BPF_A, 0x0),
6213 },
6214 CLASSIC,
6215 {
6216 [0x1c] = 0xaa, [0x1d] = 0x55,
6217 [0x1e] = 0xbb, [0x1f] = 0x66,
6218 [0x20] = 0xcc, [0x21] = 0x77,
6219 [0x22] = 0xdd, [0x23] = 0x88,
6220 [0x24] = 0xee, [0x25] = 0x99,
6221 [0x26] = 0xff, [0x27] = 0xaa,
6222 },
6223 { {0x40, 0xbb66cc77 } },
6224 },
6225 {
6226 "LD_IND word unaligned (addr & 3 == 1)",
6227 .u.insns = {
6228 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
6229 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3),
6230 BPF_STMT(BPF_RET | BPF_A, 0x0),
6231 },
6232 CLASSIC,
6233 {
6234 [0x1c] = 0xaa, [0x1d] = 0x55,
6235 [0x1e] = 0xbb, [0x1f] = 0x66,
6236 [0x20] = 0xcc, [0x21] = 0x77,
6237 [0x22] = 0xdd, [0x23] = 0x88,
6238 [0x24] = 0xee, [0x25] = 0x99,
6239 [0x26] = 0xff, [0x27] = 0xaa,
6240 },
6241 { {0x40, 0x55bb66cc } },
6242 },
6243 {
6244 "LD_IND word unaligned (addr & 3 == 3)",
6245 .u.insns = {
6246 BPF_STMT(BPF_LDX | BPF_IMM, 0x20),
6247 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x1),
6248 BPF_STMT(BPF_RET | BPF_A, 0x0),
6249 },
6250 CLASSIC,
6251 {
6252 [0x1c] = 0xaa, [0x1d] = 0x55,
6253 [0x1e] = 0xbb, [0x1f] = 0x66,
6254 [0x20] = 0xcc, [0x21] = 0x77,
6255 [0x22] = 0xdd, [0x23] = 0x88,
6256 [0x24] = 0xee, [0x25] = 0x99,
6257 [0x26] = 0xff, [0x27] = 0xaa,
6258 },
6259 { {0x40, 0x66cc77dd } },
6260 },
6261 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02006262 "LD_IND word positive offset, all ff",
6263 .u.insns = {
6264 BPF_STMT(BPF_LDX | BPF_IMM, 0x3b),
6265 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
6266 BPF_STMT(BPF_RET | BPF_A, 0x0),
6267 },
6268 CLASSIC,
6269 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6270 { {0x40, 0xffffffff } },
6271 },
6272 {
6273 "LD_IND word positive offset, out of bounds",
6274 .u.insns = {
6275 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6276 BPF_STMT(BPF_LD | BPF_IND | BPF_W, 0x1),
6277 BPF_STMT(BPF_RET | BPF_A, 0x0),
6278 },
6279 CLASSIC,
6280 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6281 { {0x3f, 0 }, },
6282 },
6283 {
6284 "LD_IND word negative offset, out of bounds",
6285 .u.insns = {
6286 BPF_STMT(BPF_LDX | BPF_IMM, 0x3e),
6287 BPF_STMT(BPF_LD | BPF_IND | BPF_W, -0x3f),
6288 BPF_STMT(BPF_RET | BPF_A, 0x0),
6289 },
6290 CLASSIC,
6291 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6292 { {0x3f, 0 } },
6293 },
6294 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02006295 "LD_ABS byte",
6296 .u.insns = {
6297 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x20),
6298 BPF_STMT(BPF_RET | BPF_A, 0x0),
6299 },
6300 CLASSIC,
6301 {
6302 [0x1c] = 0xaa, [0x1d] = 0x55,
6303 [0x1e] = 0xbb, [0x1f] = 0x66,
6304 [0x20] = 0xcc, [0x21] = 0x77,
6305 [0x22] = 0xdd, [0x23] = 0x88,
6306 [0x24] = 0xee, [0x25] = 0x99,
6307 [0x26] = 0xff, [0x27] = 0xaa,
6308 },
6309 { {0x40, 0xcc } },
6310 },
6311 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02006312 "LD_ABS byte positive offset, all ff",
6313 .u.insns = {
6314 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
6315 BPF_STMT(BPF_RET | BPF_A, 0x0),
6316 },
6317 CLASSIC,
6318 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6319 { {0x40, 0xff } },
6320 },
6321 {
6322 "LD_ABS byte positive offset, out of bounds",
6323 .u.insns = {
6324 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, 0x3f),
6325 BPF_STMT(BPF_RET | BPF_A, 0x0),
6326 },
6327 CLASSIC,
6328 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6329 { {0x3f, 0 }, },
6330 },
6331 {
6332 "LD_ABS byte negative offset, out of bounds load",
6333 .u.insns = {
6334 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, -1),
6335 BPF_STMT(BPF_RET | BPF_A, 0x0),
6336 },
6337 CLASSIC | FLAG_EXPECTED_FAIL,
6338 .expected_errcode = -EINVAL,
6339 },
6340 {
6341 "LD_ABS byte negative offset, in bounds",
6342 .u.insns = {
6343 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
6344 BPF_STMT(BPF_RET | BPF_A, 0x0),
6345 },
6346 CLASSIC,
6347 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6348 { {0x40, 0x82 }, },
6349 },
6350 {
6351 "LD_ABS byte negative offset, out of bounds",
6352 .u.insns = {
6353 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
6354 BPF_STMT(BPF_RET | BPF_A, 0x0),
6355 },
6356 CLASSIC,
6357 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6358 { {0x3f, 0 }, },
6359 },
6360 {
6361 "LD_ABS byte negative offset, multiple calls",
6362 .u.insns = {
6363 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3c),
6364 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3d),
6365 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3e),
6366 BPF_STMT(BPF_LD | BPF_ABS | BPF_B, SKF_LL_OFF + 0x3f),
6367 BPF_STMT(BPF_RET | BPF_A, 0x0),
6368 },
6369 CLASSIC,
6370 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6371 { {0x40, 0x82 }, },
6372 },
6373 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02006374 "LD_ABS halfword",
6375 .u.insns = {
6376 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x22),
6377 BPF_STMT(BPF_RET | BPF_A, 0x0),
6378 },
6379 CLASSIC,
6380 {
6381 [0x1c] = 0xaa, [0x1d] = 0x55,
6382 [0x1e] = 0xbb, [0x1f] = 0x66,
6383 [0x20] = 0xcc, [0x21] = 0x77,
6384 [0x22] = 0xdd, [0x23] = 0x88,
6385 [0x24] = 0xee, [0x25] = 0x99,
6386 [0x26] = 0xff, [0x27] = 0xaa,
6387 },
6388 { {0x40, 0xdd88 } },
6389 },
6390 {
6391 "LD_ABS halfword unaligned",
6392 .u.insns = {
6393 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x25),
6394 BPF_STMT(BPF_RET | BPF_A, 0x0),
6395 },
6396 CLASSIC,
6397 {
6398 [0x1c] = 0xaa, [0x1d] = 0x55,
6399 [0x1e] = 0xbb, [0x1f] = 0x66,
6400 [0x20] = 0xcc, [0x21] = 0x77,
6401 [0x22] = 0xdd, [0x23] = 0x88,
6402 [0x24] = 0xee, [0x25] = 0x99,
6403 [0x26] = 0xff, [0x27] = 0xaa,
6404 },
6405 { {0x40, 0x99ff } },
6406 },
6407 {
Daniel Borkmann93731ef2018-05-04 01:08:13 +02006408 "LD_ABS halfword positive offset, all ff",
6409 .u.insns = {
6410 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3e),
6411 BPF_STMT(BPF_RET | BPF_A, 0x0),
6412 },
6413 CLASSIC,
6414 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6415 { {0x40, 0xffff } },
6416 },
6417 {
6418 "LD_ABS halfword positive offset, out of bounds",
6419 .u.insns = {
6420 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, 0x3f),
6421 BPF_STMT(BPF_RET | BPF_A, 0x0),
6422 },
6423 CLASSIC,
6424 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6425 { {0x3f, 0 }, },
6426 },
6427 {
6428 "LD_ABS halfword negative offset, out of bounds load",
6429 .u.insns = {
6430 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, -1),
6431 BPF_STMT(BPF_RET | BPF_A, 0x0),
6432 },
6433 CLASSIC | FLAG_EXPECTED_FAIL,
6434 .expected_errcode = -EINVAL,
6435 },
6436 {
6437 "LD_ABS halfword negative offset, in bounds",
6438 .u.insns = {
6439 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
6440 BPF_STMT(BPF_RET | BPF_A, 0x0),
6441 },
6442 CLASSIC,
6443 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6444 { {0x40, 0x1982 }, },
6445 },
6446 {
6447 "LD_ABS halfword negative offset, out of bounds",
6448 .u.insns = {
6449 BPF_STMT(BPF_LD | BPF_ABS | BPF_H, SKF_LL_OFF + 0x3e),
6450 BPF_STMT(BPF_RET | BPF_A, 0x0),
6451 },
6452 CLASSIC,
6453 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6454 { {0x3f, 0 }, },
6455 },
6456 {
Nicolas Schichan08fcb082015-08-04 15:19:11 +02006457 "LD_ABS word",
6458 .u.insns = {
6459 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x1c),
6460 BPF_STMT(BPF_RET | BPF_A, 0x0),
6461 },
6462 CLASSIC,
6463 {
6464 [0x1c] = 0xaa, [0x1d] = 0x55,
6465 [0x1e] = 0xbb, [0x1f] = 0x66,
6466 [0x20] = 0xcc, [0x21] = 0x77,
6467 [0x22] = 0xdd, [0x23] = 0x88,
6468 [0x24] = 0xee, [0x25] = 0x99,
6469 [0x26] = 0xff, [0x27] = 0xaa,
6470 },
6471 { {0x40, 0xaa55bb66 } },
6472 },
6473 {
6474 "LD_ABS word unaligned (addr & 3 == 2)",
6475 .u.insns = {
6476 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x22),
6477 BPF_STMT(BPF_RET | BPF_A, 0x0),
6478 },
6479 CLASSIC,
6480 {
6481 [0x1c] = 0xaa, [0x1d] = 0x55,
6482 [0x1e] = 0xbb, [0x1f] = 0x66,
6483 [0x20] = 0xcc, [0x21] = 0x77,
6484 [0x22] = 0xdd, [0x23] = 0x88,
6485 [0x24] = 0xee, [0x25] = 0x99,
6486 [0x26] = 0xff, [0x27] = 0xaa,
6487 },
6488 { {0x40, 0xdd88ee99 } },
6489 },
6490 {
6491 "LD_ABS word unaligned (addr & 3 == 1)",
6492 .u.insns = {
6493 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x21),
6494 BPF_STMT(BPF_RET | BPF_A, 0x0),
6495 },
6496 CLASSIC,
6497 {
6498 [0x1c] = 0xaa, [0x1d] = 0x55,
6499 [0x1e] = 0xbb, [0x1f] = 0x66,
6500 [0x20] = 0xcc, [0x21] = 0x77,
6501 [0x22] = 0xdd, [0x23] = 0x88,
6502 [0x24] = 0xee, [0x25] = 0x99,
6503 [0x26] = 0xff, [0x27] = 0xaa,
6504 },
6505 { {0x40, 0x77dd88ee } },
6506 },
6507 {
6508 "LD_ABS word unaligned (addr & 3 == 3)",
6509 .u.insns = {
6510 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x23),
6511 BPF_STMT(BPF_RET | BPF_A, 0x0),
6512 },
6513 CLASSIC,
6514 {
6515 [0x1c] = 0xaa, [0x1d] = 0x55,
6516 [0x1e] = 0xbb, [0x1f] = 0x66,
6517 [0x20] = 0xcc, [0x21] = 0x77,
6518 [0x22] = 0xdd, [0x23] = 0x88,
6519 [0x24] = 0xee, [0x25] = 0x99,
6520 [0x26] = 0xff, [0x27] = 0xaa,
6521 },
6522 { {0x40, 0x88ee99ff } },
6523 },
Daniel Borkmann93731ef2018-05-04 01:08:13 +02006524 {
6525 "LD_ABS word positive offset, all ff",
6526 .u.insns = {
6527 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3c),
6528 BPF_STMT(BPF_RET | BPF_A, 0x0),
6529 },
6530 CLASSIC,
6531 { [0x3c] = 0xff, [0x3d] = 0xff, [0x3e] = 0xff, [0x3f] = 0xff },
6532 { {0x40, 0xffffffff } },
6533 },
6534 {
6535 "LD_ABS word positive offset, out of bounds",
6536 .u.insns = {
6537 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, 0x3f),
6538 BPF_STMT(BPF_RET | BPF_A, 0x0),
6539 },
6540 CLASSIC,
6541 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6542 { {0x3f, 0 }, },
6543 },
6544 {
6545 "LD_ABS word negative offset, out of bounds load",
6546 .u.insns = {
6547 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, -1),
6548 BPF_STMT(BPF_RET | BPF_A, 0x0),
6549 },
6550 CLASSIC | FLAG_EXPECTED_FAIL,
6551 .expected_errcode = -EINVAL,
6552 },
6553 {
6554 "LD_ABS word negative offset, in bounds",
6555 .u.insns = {
6556 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
6557 BPF_STMT(BPF_RET | BPF_A, 0x0),
6558 },
6559 CLASSIC,
6560 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6561 { {0x40, 0x25051982 }, },
6562 },
6563 {
6564 "LD_ABS word negative offset, out of bounds",
6565 .u.insns = {
6566 BPF_STMT(BPF_LD | BPF_ABS | BPF_W, SKF_LL_OFF + 0x3c),
6567 BPF_STMT(BPF_RET | BPF_A, 0x0),
6568 },
6569 CLASSIC,
6570 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6571 { {0x3f, 0 }, },
6572 },
6573 {
6574 "LDX_MSH standalone, preserved A",
6575 .u.insns = {
6576 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6577 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6578 BPF_STMT(BPF_RET | BPF_A, 0x0),
6579 },
6580 CLASSIC,
6581 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6582 { {0x40, 0xffeebbaa }, },
6583 },
6584 {
6585 "LDX_MSH standalone, preserved A 2",
6586 .u.insns = {
6587 BPF_STMT(BPF_LD | BPF_IMM, 0x175e9d63),
6588 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6589 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3d),
6590 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
6591 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3f),
6592 BPF_STMT(BPF_RET | BPF_A, 0x0),
6593 },
6594 CLASSIC,
6595 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6596 { {0x40, 0x175e9d63 }, },
6597 },
6598 {
6599 "LDX_MSH standalone, test result 1",
6600 .u.insns = {
6601 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6602 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3c),
6603 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6604 BPF_STMT(BPF_RET | BPF_A, 0x0),
6605 },
6606 CLASSIC,
6607 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6608 { {0x40, 0x14 }, },
6609 },
6610 {
6611 "LDX_MSH standalone, test result 2",
6612 .u.insns = {
6613 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6614 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x3e),
6615 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6616 BPF_STMT(BPF_RET | BPF_A, 0x0),
6617 },
6618 CLASSIC,
6619 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6620 { {0x40, 0x24 }, },
6621 },
6622 {
6623 "LDX_MSH standalone, negative offset",
6624 .u.insns = {
6625 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6626 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, -1),
6627 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6628 BPF_STMT(BPF_RET | BPF_A, 0x0),
6629 },
6630 CLASSIC,
6631 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6632 { {0x40, 0 }, },
6633 },
6634 {
6635 "LDX_MSH standalone, negative offset 2",
6636 .u.insns = {
6637 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6638 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, SKF_LL_OFF + 0x3e),
6639 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6640 BPF_STMT(BPF_RET | BPF_A, 0x0),
6641 },
6642 CLASSIC,
6643 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6644 { {0x40, 0x24 }, },
6645 },
6646 {
6647 "LDX_MSH standalone, out of bounds",
6648 .u.insns = {
6649 BPF_STMT(BPF_LD | BPF_IMM, 0xffeebbaa),
6650 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 0x40),
6651 BPF_STMT(BPF_MISC | BPF_TXA, 0),
6652 BPF_STMT(BPF_RET | BPF_A, 0x0),
6653 },
6654 CLASSIC,
6655 { [0x3c] = 0x25, [0x3d] = 0x05, [0x3e] = 0x19, [0x3f] = 0x82 },
6656 { {0x40, 0 }, },
6657 },
Nicolas Schichan86bf1722015-08-04 15:19:12 +02006658 /*
6659 * verify that the interpreter or JIT correctly sets A and X
6660 * to 0.
6661 */
6662 {
6663 "ADD default X",
6664 .u.insns = {
6665 /*
6666 * A = 0x42
6667 * A = A + X
6668 * ret A
6669 */
6670 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6671 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
6672 BPF_STMT(BPF_RET | BPF_A, 0x0),
6673 },
6674 CLASSIC | FLAG_NO_DATA,
6675 {},
6676 { {0x1, 0x42 } },
6677 },
6678 {
6679 "ADD default A",
6680 .u.insns = {
6681 /*
6682 * A = A + 0x42
6683 * ret A
6684 */
6685 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0x42),
6686 BPF_STMT(BPF_RET | BPF_A, 0x0),
6687 },
6688 CLASSIC | FLAG_NO_DATA,
6689 {},
6690 { {0x1, 0x42 } },
6691 },
6692 {
6693 "SUB default X",
6694 .u.insns = {
6695 /*
6696 * A = 0x66
6697 * A = A - X
6698 * ret A
6699 */
6700 BPF_STMT(BPF_LD | BPF_IMM, 0x66),
6701 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
6702 BPF_STMT(BPF_RET | BPF_A, 0x0),
6703 },
6704 CLASSIC | FLAG_NO_DATA,
6705 {},
6706 { {0x1, 0x66 } },
6707 },
6708 {
6709 "SUB default A",
6710 .u.insns = {
6711 /*
6712 * A = A - -0x66
6713 * ret A
6714 */
6715 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, -0x66),
6716 BPF_STMT(BPF_RET | BPF_A, 0x0),
6717 },
6718 CLASSIC | FLAG_NO_DATA,
6719 {},
6720 { {0x1, 0x66 } },
6721 },
6722 {
6723 "MUL default X",
6724 .u.insns = {
6725 /*
6726 * A = 0x42
6727 * A = A * X
6728 * ret A
6729 */
6730 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6731 BPF_STMT(BPF_ALU | BPF_MUL | BPF_X, 0),
6732 BPF_STMT(BPF_RET | BPF_A, 0x0),
6733 },
6734 CLASSIC | FLAG_NO_DATA,
6735 {},
6736 { {0x1, 0x0 } },
6737 },
6738 {
6739 "MUL default A",
6740 .u.insns = {
6741 /*
6742 * A = A * 0x66
6743 * ret A
6744 */
6745 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 0x66),
6746 BPF_STMT(BPF_RET | BPF_A, 0x0),
6747 },
6748 CLASSIC | FLAG_NO_DATA,
6749 {},
6750 { {0x1, 0x0 } },
6751 },
6752 {
6753 "DIV default X",
6754 .u.insns = {
6755 /*
6756 * A = 0x42
6757 * A = A / X ; this halt the filter execution if X is 0
6758 * ret 0x42
6759 */
6760 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6761 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
6762 BPF_STMT(BPF_RET | BPF_K, 0x42),
6763 },
6764 CLASSIC | FLAG_NO_DATA,
6765 {},
6766 { {0x1, 0x0 } },
6767 },
6768 {
6769 "DIV default A",
6770 .u.insns = {
6771 /*
6772 * A = A / 1
6773 * ret A
6774 */
6775 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x1),
6776 BPF_STMT(BPF_RET | BPF_A, 0x0),
6777 },
6778 CLASSIC | FLAG_NO_DATA,
6779 {},
6780 { {0x1, 0x0 } },
6781 },
6782 {
Yang Shid4e4bc12015-11-04 11:36:37 -08006783 "MOD default X",
6784 .u.insns = {
6785 /*
6786 * A = 0x42
6787 * A = A mod X ; this halt the filter execution if X is 0
6788 * ret 0x42
6789 */
6790 BPF_STMT(BPF_LD | BPF_IMM, 0x42),
6791 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
6792 BPF_STMT(BPF_RET | BPF_K, 0x42),
6793 },
6794 CLASSIC | FLAG_NO_DATA,
6795 {},
6796 { {0x1, 0x0 } },
6797 },
6798 {
6799 "MOD default A",
6800 .u.insns = {
6801 /*
6802 * A = A mod 1
6803 * ret A
6804 */
6805 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
6806 BPF_STMT(BPF_RET | BPF_A, 0x0),
6807 },
6808 CLASSIC | FLAG_NO_DATA,
6809 {},
6810 { {0x1, 0x0 } },
6811 },
6812 {
Nicolas Schichan86bf1722015-08-04 15:19:12 +02006813 "JMP EQ default A",
6814 .u.insns = {
6815 /*
6816 * cmp A, 0x0, 0, 1
6817 * ret 0x42
6818 * ret 0x66
6819 */
6820 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0, 0, 1),
6821 BPF_STMT(BPF_RET | BPF_K, 0x42),
6822 BPF_STMT(BPF_RET | BPF_K, 0x66),
6823 },
6824 CLASSIC | FLAG_NO_DATA,
6825 {},
6826 { {0x1, 0x42 } },
6827 },
6828 {
6829 "JMP EQ default X",
6830 .u.insns = {
6831 /*
6832 * A = 0x0
6833 * cmp A, X, 0, 1
6834 * ret 0x42
6835 * ret 0x66
6836 */
6837 BPF_STMT(BPF_LD | BPF_IMM, 0x0),
6838 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0x0, 0, 1),
6839 BPF_STMT(BPF_RET | BPF_K, 0x42),
6840 BPF_STMT(BPF_RET | BPF_K, 0x66),
6841 },
6842 CLASSIC | FLAG_NO_DATA,
6843 {},
6844 { {0x1, 0x42 } },
6845 },
Daniel Borkmannfcd1c912018-01-20 01:24:31 +01006846 /* Checking interpreter vs JIT wrt signed extended imms. */
6847 {
6848 "JNE signed compare, test 1",
6849 .u.insns_int = {
6850 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6851 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6852 BPF_MOV64_REG(R2, R1),
6853 BPF_ALU64_REG(BPF_AND, R2, R3),
6854 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6855 BPF_JMP_IMM(BPF_JNE, R2, -17104896, 1),
6856 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6857 BPF_EXIT_INSN(),
6858 },
6859 INTERNAL,
6860 { },
6861 { { 0, 1 } },
6862 },
6863 {
6864 "JNE signed compare, test 2",
6865 .u.insns_int = {
6866 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6867 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6868 BPF_MOV64_REG(R2, R1),
6869 BPF_ALU64_REG(BPF_AND, R2, R3),
6870 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6871 BPF_JMP_IMM(BPF_JNE, R2, 0xfefb0000, 1),
6872 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6873 BPF_EXIT_INSN(),
6874 },
6875 INTERNAL,
6876 { },
6877 { { 0, 1 } },
6878 },
6879 {
6880 "JNE signed compare, test 3",
6881 .u.insns_int = {
6882 BPF_ALU32_IMM(BPF_MOV, R1, 0xfefbbc12),
6883 BPF_ALU32_IMM(BPF_MOV, R3, 0xffff0000),
6884 BPF_ALU32_IMM(BPF_MOV, R4, 0xfefb0000),
6885 BPF_MOV64_REG(R2, R1),
6886 BPF_ALU64_REG(BPF_AND, R2, R3),
6887 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6888 BPF_JMP_REG(BPF_JNE, R2, R4, 1),
6889 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6890 BPF_EXIT_INSN(),
6891 },
6892 INTERNAL,
6893 { },
6894 { { 0, 2 } },
6895 },
6896 {
6897 "JNE signed compare, test 4",
6898 .u.insns_int = {
6899 BPF_LD_IMM64(R1, -17104896),
6900 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6901 BPF_JMP_IMM(BPF_JNE, R1, -17104896, 1),
6902 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6903 BPF_EXIT_INSN(),
6904 },
6905 INTERNAL,
6906 { },
6907 { { 0, 2 } },
6908 },
6909 {
6910 "JNE signed compare, test 5",
6911 .u.insns_int = {
6912 BPF_LD_IMM64(R1, 0xfefb0000),
6913 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6914 BPF_JMP_IMM(BPF_JNE, R1, 0xfefb0000, 1),
6915 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6916 BPF_EXIT_INSN(),
6917 },
6918 INTERNAL,
6919 { },
6920 { { 0, 1 } },
6921 },
6922 {
6923 "JNE signed compare, test 6",
6924 .u.insns_int = {
6925 BPF_LD_IMM64(R1, 0x7efb0000),
6926 BPF_ALU32_IMM(BPF_MOV, R0, 1),
6927 BPF_JMP_IMM(BPF_JNE, R1, 0x7efb0000, 1),
6928 BPF_ALU32_IMM(BPF_MOV, R0, 2),
6929 BPF_EXIT_INSN(),
6930 },
6931 INTERNAL,
6932 { },
6933 { { 0, 2 } },
6934 },
6935 {
6936 "JNE signed compare, test 7",
6937 .u.insns = {
6938 BPF_STMT(BPF_LD | BPF_IMM, 0xffff0000),
6939 BPF_STMT(BPF_MISC | BPF_TAX, 0),
6940 BPF_STMT(BPF_LD | BPF_IMM, 0xfefbbc12),
6941 BPF_STMT(BPF_ALU | BPF_AND | BPF_X, 0),
6942 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xfefb0000, 1, 0),
6943 BPF_STMT(BPF_RET | BPF_K, 1),
6944 BPF_STMT(BPF_RET | BPF_K, 2),
6945 },
6946 CLASSIC | FLAG_NO_DATA,
6947 {},
6948 { { 0, 2 } },
6949 },
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006950};
6951
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006952static struct net_device dev;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006953
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006954static struct sk_buff *populate_skb(char *buf, int size)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006955{
6956 struct sk_buff *skb;
6957
6958 if (size >= MAX_DATA)
6959 return NULL;
6960
6961 skb = alloc_skb(MAX_DATA, GFP_KERNEL);
6962 if (!skb)
6963 return NULL;
6964
yuan linyude77b962017-06-18 22:48:17 +08006965 __skb_put_data(skb, buf, size);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006966
6967 /* Initialize a fake skb with test pattern. */
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006968 skb_reset_mac_header(skb);
6969 skb->protocol = htons(ETH_P_IP);
6970 skb->pkt_type = SKB_TYPE;
6971 skb->mark = SKB_MARK;
6972 skb->hash = SKB_HASH;
6973 skb->queue_mapping = SKB_QUEUE_MAP;
6974 skb->vlan_tci = SKB_VLAN_TCI;
Michał Mirosław0c4b2d32018-11-10 19:58:36 +01006975 skb->vlan_present = SKB_VLAN_PRESENT;
Jakub Kicinski5c0ca3f2016-09-12 13:04:57 +01006976 skb->vlan_proto = htons(ETH_P_IP);
Song Liu100811932018-09-27 09:34:41 -07006977 dev_net_set(&dev, &init_net);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006978 skb->dev = &dev;
6979 skb->dev->ifindex = SKB_DEV_IFINDEX;
6980 skb->dev->type = SKB_DEV_TYPE;
6981 skb_set_network_header(skb, min(size, ETH_HLEN));
6982
6983 return skb;
6984}
6985
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006986static void *generate_test_data(struct bpf_test *test, int sub)
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006987{
Nicolas Schichanbac142a2015-08-04 15:19:08 +02006988 struct sk_buff *skb;
6989 struct page *page;
6990
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006991 if (test->aux & FLAG_NO_DATA)
6992 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07006993
Daniel Borkmann10f18e02014-05-23 18:44:00 +02006994 /* Test case expects an skb, so populate one. Various
6995 * subtests generate skbs of different sizes based on
6996 * the same data.
6997 */
Nicolas Schichanbac142a2015-08-04 15:19:08 +02006998 skb = populate_skb(test->data, test->test[sub].data_size);
6999 if (!skb)
7000 return NULL;
7001
7002 if (test->aux & FLAG_SKB_FRAG) {
7003 /*
7004 * when the test requires a fragmented skb, add a
7005 * single fragment to the skb, filled with
7006 * test->frag_data.
7007 */
7008 void *ptr;
7009
7010 page = alloc_page(GFP_KERNEL);
7011
7012 if (!page)
7013 goto err_kfree_skb;
7014
7015 ptr = kmap(page);
7016 if (!ptr)
7017 goto err_free_page;
7018 memcpy(ptr, test->frag_data, MAX_DATA);
7019 kunmap(page);
7020 skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
7021 }
7022
7023 return skb;
7024
7025err_free_page:
7026 __free_page(page);
7027err_kfree_skb:
7028 kfree_skb(skb);
7029 return NULL;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007030}
7031
7032static void release_test_data(const struct bpf_test *test, void *data)
7033{
7034 if (test->aux & FLAG_NO_DATA)
7035 return;
7036
7037 kfree_skb(data);
7038}
7039
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007040static int filter_length(int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007041{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007042 struct sock_filter *fp;
7043 int len;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007044
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007045 if (tests[which].fill_helper)
7046 return tests[which].u.ptr.len;
7047
7048 fp = tests[which].u.insns;
Chema Gonzaleze9d94502014-05-30 10:15:12 -07007049 for (len = MAX_INSNS - 1; len > 0; --len)
7050 if (fp[len].code != 0 || fp[len].k != 0)
7051 break;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007052
Chema Gonzaleze9d94502014-05-30 10:15:12 -07007053 return len + 1;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007054}
7055
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007056static void *filter_pointer(int which)
7057{
7058 if (tests[which].fill_helper)
7059 return tests[which].u.ptr.insns;
7060 else
7061 return tests[which].u.insns;
7062}
7063
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007064static struct bpf_prog *generate_filter(int which, int *err)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007065{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007066 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007067 unsigned int flen = filter_length(which);
7068 void *fptr = filter_pointer(which);
7069 struct sock_fprog_kern fprog;
7070 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007071
7072 switch (test_type) {
7073 case CLASSIC:
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007074 fprog.filter = fptr;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007075 fprog.len = flen;
7076
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007077 *err = bpf_prog_create(&fp, &fprog);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007078 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
Yonghong Song09584b42018-02-02 22:37:15 -08007079 if (*err == tests[which].expected_errcode) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007080 pr_cont("PASS\n");
7081 /* Verifier rejected filter as expected. */
7082 *err = 0;
7083 return NULL;
7084 } else {
7085 pr_cont("UNEXPECTED_PASS\n");
7086 /* Verifier didn't reject the test that's
7087 * bad enough, just return!
7088 */
7089 *err = -EINVAL;
7090 return NULL;
7091 }
7092 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007093 if (*err) {
Alexei Starovoitov290af862018-01-09 10:04:29 -08007094 pr_cont("FAIL to prog_create err=%d len=%d\n",
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007095 *err, fprog.len);
7096 return NULL;
7097 }
7098 break;
7099
7100 case INTERNAL:
Daniel Borkmann60a3b222014-09-02 22:53:44 +02007101 fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007102 if (fp == NULL) {
7103 pr_cont("UNEXPECTED_FAIL no memory left\n");
7104 *err = -ENOMEM;
7105 return NULL;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007106 }
7107
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007108 fp->len = flen;
Daniel Borkmann4962fa12015-07-30 12:42:46 +02007109 /* Type doesn't really matter here as long as it's not unspec. */
7110 fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007111 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));
Alexei Starovoitov105c0362017-05-30 13:31:32 -07007112 fp->aux->stack_depth = tests[which].stack_depth;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007113
Daniel Borkmannd1c55ab2016-05-13 19:08:31 +02007114 /* We cannot error here as we don't need type compatibility
7115 * checks.
7116 */
7117 fp = bpf_prog_select_runtime(fp, err);
Alexei Starovoitov290af862018-01-09 10:04:29 -08007118 if (*err) {
7119 pr_cont("FAIL to select_runtime err=%d\n", *err);
7120 return NULL;
7121 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007122 break;
7123 }
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007124
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007125 *err = 0;
7126 return fp;
7127}
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007128
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007129static void release_filter(struct bpf_prog *fp, int which)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007130{
7131 __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007132
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007133 switch (test_type) {
7134 case CLASSIC:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007135 bpf_prog_destroy(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007136 break;
7137 case INTERNAL:
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007138 bpf_prog_free(fp);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007139 break;
7140 }
7141}
7142
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007143static int __run_one(const struct bpf_prog *fp, const void *data,
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007144 int runs, u64 *duration)
7145{
7146 u64 start, finish;
Alexei Starovoitov25ee7322014-09-19 13:53:51 -07007147 int ret = 0, i;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007148
David Miller6eac7792020-02-24 15:01:44 +01007149 migrate_disable();
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07007150 start = ktime_get_ns();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007151
7152 for (i = 0; i < runs; i++)
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007153 ret = BPF_PROG_RUN(fp, data);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007154
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07007155 finish = ktime_get_ns();
David Miller6eac7792020-02-24 15:01:44 +01007156 migrate_enable();
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007157
Alexei Starovoitov4d9c5c52015-07-20 20:34:19 -07007158 *duration = finish - start;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007159 do_div(*duration, runs);
7160
7161 return ret;
7162}
7163
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007164static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007165{
7166 int err_cnt = 0, i, runs = MAX_TESTRUNS;
7167
7168 for (i = 0; i < MAX_SUBTESTS; i++) {
7169 void *data;
7170 u64 duration;
7171 u32 ret;
7172
Johan Almbladh2b7e9f22021-07-21 12:38:22 +02007173 /*
7174 * NOTE: Several sub-tests may be present, in which case
7175 * a zero {data_size, result} tuple indicates the end of
7176 * the sub-test array. The first test is always run,
7177 * even if both data_size and result happen to be zero.
7178 */
7179 if (i > 0 &&
7180 test->test[i].data_size == 0 &&
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007181 test->test[i].result == 0)
7182 break;
7183
7184 data = generate_test_data(test, i);
Nicolas Schichane34684f2015-08-04 15:19:07 +02007185 if (!data && !(test->aux & FLAG_NO_DATA)) {
7186 pr_cont("data generation failed ");
7187 err_cnt++;
7188 break;
7189 }
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007190 ret = __run_one(fp, data, runs, &duration);
7191 release_test_data(test, data);
7192
7193 if (ret == test->test[i].result) {
7194 pr_cont("%lld ", duration);
7195 } else {
7196 pr_cont("ret %d != %d ", ret,
7197 test->test[i].result);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007198 err_cnt++;
7199 }
7200 }
7201
7202 return err_cnt;
7203}
7204
Nicolas Schichand2648d42015-08-04 15:19:10 +02007205static char test_name[64];
7206module_param_string(test_name, test_name, sizeof(test_name), 0);
7207
7208static int test_id = -1;
7209module_param(test_id, int, 0);
7210
7211static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
7212module_param_array(test_range, int, NULL, 0);
7213
7214static __init int find_test_index(const char *test_name)
7215{
7216 int i;
7217
7218 for (i = 0; i < ARRAY_SIZE(tests); i++) {
7219 if (!strcmp(tests[i].descr, test_name))
7220 return i;
7221 }
7222 return -1;
7223}
7224
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007225static __init int prepare_bpf_tests(void)
7226{
7227 int i;
7228
Nicolas Schichand2648d42015-08-04 15:19:10 +02007229 if (test_id >= 0) {
7230 /*
7231 * if a test_id was specified, use test_range to
7232 * cover only that test.
7233 */
7234 if (test_id >= ARRAY_SIZE(tests)) {
7235 pr_err("test_bpf: invalid test_id specified.\n");
7236 return -EINVAL;
7237 }
7238
7239 test_range[0] = test_id;
7240 test_range[1] = test_id;
7241 } else if (*test_name) {
7242 /*
7243 * if a test_name was specified, find it and setup
7244 * test_range to cover only that test.
7245 */
7246 int idx = find_test_index(test_name);
7247
7248 if (idx < 0) {
7249 pr_err("test_bpf: no test named '%s' found.\n",
7250 test_name);
7251 return -EINVAL;
7252 }
7253 test_range[0] = idx;
7254 test_range[1] = idx;
7255 } else {
7256 /*
7257 * check that the supplied test_range is valid.
7258 */
7259 if (test_range[0] >= ARRAY_SIZE(tests) ||
7260 test_range[1] >= ARRAY_SIZE(tests) ||
7261 test_range[0] < 0 || test_range[1] < 0) {
7262 pr_err("test_bpf: test_range is out of bound.\n");
7263 return -EINVAL;
7264 }
7265
7266 if (test_range[1] < test_range[0]) {
7267 pr_err("test_bpf: test_range is ending before it starts.\n");
7268 return -EINVAL;
7269 }
7270 }
7271
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007272 for (i = 0; i < ARRAY_SIZE(tests); i++) {
7273 if (tests[i].fill_helper &&
7274 tests[i].fill_helper(&tests[i]) < 0)
7275 return -ENOMEM;
7276 }
7277
7278 return 0;
7279}
7280
7281static __init void destroy_bpf_tests(void)
7282{
7283 int i;
7284
7285 for (i = 0; i < ARRAY_SIZE(tests); i++) {
7286 if (tests[i].fill_helper)
7287 kfree(tests[i].u.ptr.insns);
7288 }
7289}
7290
Nicolas Schichand2648d42015-08-04 15:19:10 +02007291static bool exclude_test(int test_id)
7292{
7293 return test_id < test_range[0] || test_id > test_range[1];
7294}
7295
Yonghong Song76db8082018-03-21 16:31:04 -07007296static __init struct sk_buff *build_test_skb(void)
7297{
7298 u32 headroom = NET_SKB_PAD + NET_IP_ALIGN + ETH_HLEN;
7299 struct sk_buff *skb[2];
7300 struct page *page[2];
7301 int i, data_size = 8;
7302
7303 for (i = 0; i < 2; i++) {
7304 page[i] = alloc_page(GFP_KERNEL);
7305 if (!page[i]) {
7306 if (i == 0)
7307 goto err_page0;
7308 else
7309 goto err_page1;
7310 }
7311
7312 /* this will set skb[i]->head_frag */
7313 skb[i] = dev_alloc_skb(headroom + data_size);
7314 if (!skb[i]) {
7315 if (i == 0)
7316 goto err_skb0;
7317 else
7318 goto err_skb1;
7319 }
7320
7321 skb_reserve(skb[i], headroom);
7322 skb_put(skb[i], data_size);
7323 skb[i]->protocol = htons(ETH_P_IP);
7324 skb_reset_network_header(skb[i]);
7325 skb_set_mac_header(skb[i], -ETH_HLEN);
7326
7327 skb_add_rx_frag(skb[i], 0, page[i], 0, 64, 64);
7328 // skb_headlen(skb[i]): 8, skb[i]->head_frag = 1
7329 }
7330
7331 /* setup shinfo */
7332 skb_shinfo(skb[0])->gso_size = 1448;
7333 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV4;
7334 skb_shinfo(skb[0])->gso_type |= SKB_GSO_DODGY;
7335 skb_shinfo(skb[0])->gso_segs = 0;
7336 skb_shinfo(skb[0])->frag_list = skb[1];
7337
7338 /* adjust skb[0]'s len */
7339 skb[0]->len += skb[1]->len;
7340 skb[0]->data_len += skb[1]->data_len;
7341 skb[0]->truesize += skb[1]->truesize;
7342
7343 return skb[0];
7344
7345err_skb1:
7346 __free_page(page[1]);
7347err_page1:
7348 kfree_skb(skb[0]);
7349err_skb0:
7350 __free_page(page[0]);
7351err_page0:
7352 return NULL;
7353}
7354
Shmulik Ladkanicf204a72019-10-25 16:42:23 +03007355static __init struct sk_buff *build_test_skb_linear_no_head_frag(void)
7356{
7357 unsigned int alloc_size = 2000;
7358 unsigned int headroom = 102, doffset = 72, data_size = 1308;
7359 struct sk_buff *skb[2];
7360 int i;
7361
7362 /* skbs linked in a frag_list, both with linear data, with head_frag=0
7363 * (data allocated by kmalloc), both have tcp data of 1308 bytes
7364 * (total payload is 2616 bytes).
7365 * Data offset is 72 bytes (40 ipv6 hdr, 32 tcp hdr). Some headroom.
7366 */
7367 for (i = 0; i < 2; i++) {
7368 skb[i] = alloc_skb(alloc_size, GFP_KERNEL);
7369 if (!skb[i]) {
7370 if (i == 0)
7371 goto err_skb0;
7372 else
7373 goto err_skb1;
7374 }
7375
7376 skb[i]->protocol = htons(ETH_P_IPV6);
7377 skb_reserve(skb[i], headroom);
7378 skb_put(skb[i], doffset + data_size);
7379 skb_reset_network_header(skb[i]);
7380 if (i == 0)
7381 skb_reset_mac_header(skb[i]);
7382 else
7383 skb_set_mac_header(skb[i], -ETH_HLEN);
7384 __skb_pull(skb[i], doffset);
7385 }
7386
7387 /* setup shinfo.
7388 * mimic bpf_skb_proto_4_to_6, which resets gso_segs and assigns a
7389 * reduced gso_size.
7390 */
7391 skb_shinfo(skb[0])->gso_size = 1288;
7392 skb_shinfo(skb[0])->gso_type = SKB_GSO_TCPV6 | SKB_GSO_DODGY;
7393 skb_shinfo(skb[0])->gso_segs = 0;
7394 skb_shinfo(skb[0])->frag_list = skb[1];
7395
7396 /* adjust skb[0]'s len */
7397 skb[0]->len += skb[1]->len;
7398 skb[0]->data_len += skb[1]->len;
7399 skb[0]->truesize += skb[1]->truesize;
7400
7401 return skb[0];
7402
7403err_skb1:
7404 kfree_skb(skb[0]);
7405err_skb0:
7406 return NULL;
7407}
7408
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03007409struct skb_segment_test {
7410 const char *descr;
7411 struct sk_buff *(*build_skb)(void);
Yonghong Song76db8082018-03-21 16:31:04 -07007412 netdev_features_t features;
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03007413};
7414
7415static struct skb_segment_test skb_segment_tests[] __initconst = {
7416 {
7417 .descr = "gso_with_rx_frags",
7418 .build_skb = build_test_skb,
7419 .features = NETIF_F_SG | NETIF_F_GSO_PARTIAL | NETIF_F_IP_CSUM |
7420 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM
Shmulik Ladkanicf204a72019-10-25 16:42:23 +03007421 },
7422 {
7423 .descr = "gso_linear_no_head_frag",
7424 .build_skb = build_test_skb_linear_no_head_frag,
7425 .features = NETIF_F_SG | NETIF_F_FRAGLIST |
7426 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_GSO |
7427 NETIF_F_LLTX_BIT | NETIF_F_GRO |
7428 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
7429 NETIF_F_HW_VLAN_STAG_TX_BIT
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03007430 }
7431};
7432
7433static __init int test_skb_segment_single(const struct skb_segment_test *test)
7434{
Yonghong Song76db8082018-03-21 16:31:04 -07007435 struct sk_buff *skb, *segs;
7436 int ret = -1;
7437
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03007438 skb = test->build_skb();
Yonghong Song76db8082018-03-21 16:31:04 -07007439 if (!skb) {
7440 pr_info("%s: failed to build_test_skb", __func__);
7441 goto done;
7442 }
7443
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03007444 segs = skb_segment(skb, test->features);
Dan Carpenter99fe29d2018-03-28 14:48:36 +03007445 if (!IS_ERR(segs)) {
Yonghong Song76db8082018-03-21 16:31:04 -07007446 kfree_skb_list(segs);
7447 ret = 0;
Yonghong Song76db8082018-03-21 16:31:04 -07007448 }
7449 kfree_skb(skb);
7450done:
7451 return ret;
7452}
7453
Shmulik Ladkaniaf21c712019-10-25 16:42:22 +03007454static __init int test_skb_segment(void)
7455{
7456 int i, err_cnt = 0, pass_cnt = 0;
7457
7458 for (i = 0; i < ARRAY_SIZE(skb_segment_tests); i++) {
7459 const struct skb_segment_test *test = &skb_segment_tests[i];
7460
7461 pr_info("#%d %s ", i, test->descr);
7462
7463 if (test_skb_segment_single(test)) {
7464 pr_cont("FAIL\n");
7465 err_cnt++;
7466 } else {
7467 pr_cont("PASS\n");
7468 pass_cnt++;
7469 }
7470 }
7471
7472 pr_info("%s: Summary: %d PASSED, %d FAILED\n", __func__,
7473 pass_cnt, err_cnt);
7474 return err_cnt ? -EINVAL : 0;
7475}
7476
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007477static __init int test_bpf(void)
7478{
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007479 int i, err_cnt = 0, pass_cnt = 0;
Daniel Borkmann327941f2015-04-30 16:17:27 +02007480 int jit_cnt = 0, run_cnt = 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007481
7482 for (i = 0; i < ARRAY_SIZE(tests); i++) {
Alexei Starovoitov7ae457c2014-07-30 20:34:16 -07007483 struct bpf_prog *fp;
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007484 int err;
7485
Eric Dumazetd40bc962018-02-26 10:52:46 -08007486 cond_resched();
Nicolas Schichand2648d42015-08-04 15:19:10 +02007487 if (exclude_test(i))
7488 continue;
7489
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007490 pr_info("#%d %s ", i, tests[i].descr);
7491
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007492 fp = generate_filter(i, &err);
7493 if (fp == NULL) {
7494 if (err == 0) {
7495 pass_cnt++;
7496 continue;
7497 }
Alexei Starovoitov290af862018-01-09 10:04:29 -08007498 err_cnt++;
7499 continue;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007500 }
Daniel Borkmann327941f2015-04-30 16:17:27 +02007501
7502 pr_cont("jited:%u ", fp->jited);
7503
7504 run_cnt++;
7505 if (fp->jited)
7506 jit_cnt++;
7507
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007508 err = run_one(fp, &tests[i]);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007509 release_filter(fp, i);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007510
7511 if (err) {
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007512 pr_cont("FAIL (%d times)\n", err);
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007513 err_cnt++;
7514 } else {
7515 pr_cont("PASS\n");
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007516 pass_cnt++;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007517 }
7518 }
7519
Daniel Borkmann327941f2015-04-30 16:17:27 +02007520 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n",
7521 pass_cnt, err_cnt, jit_cnt, run_cnt);
7522
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007523 return err_cnt ? -EINVAL : 0;
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007524}
7525
7526static int __init test_bpf_init(void)
7527{
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007528 int ret;
7529
7530 ret = prepare_bpf_tests();
7531 if (ret < 0)
7532 return ret;
7533
7534 ret = test_bpf();
Daniel Borkmanna4afd37b2015-05-13 13:12:43 +02007535 destroy_bpf_tests();
Yonghong Song76db8082018-03-21 16:31:04 -07007536 if (ret)
7537 return ret;
7538
7539 return test_skb_segment();
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007540}
7541
7542static void __exit test_bpf_exit(void)
7543{
7544}
7545
7546module_init(test_bpf_init);
7547module_exit(test_bpf_exit);
Daniel Borkmann10f18e02014-05-23 18:44:00 +02007548
Alexei Starovoitov64a89462014-05-08 14:10:52 -07007549MODULE_LICENSE("GPL");