1 /* 2 * Testsuite for BPF interpreter and BPF JIT compiler 3 * 4 * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of version 2 of the GNU General Public 8 * License as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 */ 15 16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17 18 #include <linux/init.h> 19 #include <linux/module.h> 20 #include <linux/filter.h> 21 #include <linux/skbuff.h> 22 #include <linux/netdevice.h> 23 #include <linux/if_vlan.h> 24 #include <linux/random.h> 25 26 /* General test specific settings */ 27 #define MAX_SUBTESTS 3 28 #define MAX_TESTRUNS 10000 29 #define MAX_DATA 128 30 #define MAX_INSNS 512 31 #define MAX_K 0xffffFFFF 32 33 /* Few constants used to init test 'skb' */ 34 #define SKB_TYPE 3 35 #define SKB_MARK 0x1234aaaa 36 #define SKB_HASH 0x1234aaab 37 #define SKB_QUEUE_MAP 123 38 #define SKB_VLAN_TCI 0xffff 39 #define SKB_DEV_IFINDEX 577 40 #define SKB_DEV_TYPE 588 41 42 /* Redefine REGs to make tests less verbose */ 43 #define R0 BPF_REG_0 44 #define R1 BPF_REG_1 45 #define R2 BPF_REG_2 46 #define R3 BPF_REG_3 47 #define R4 BPF_REG_4 48 #define R5 BPF_REG_5 49 #define R6 BPF_REG_6 50 #define R7 BPF_REG_7 51 #define R8 BPF_REG_8 52 #define R9 BPF_REG_9 53 #define R10 BPF_REG_10 54 55 /* Flags that can be passed to test cases */ 56 #define FLAG_NO_DATA BIT(0) 57 #define FLAG_EXPECTED_FAIL BIT(1) 58 59 enum { 60 CLASSIC = BIT(6), /* Old BPF instructions only. */ 61 INTERNAL = BIT(7), /* Extended instruction set. */ 62 }; 63 64 #define TEST_TYPE_MASK (CLASSIC | INTERNAL) 65 66 struct bpf_test { 67 const char *descr; 68 union { 69 struct sock_filter insns[MAX_INSNS]; 70 struct bpf_insn insns_int[MAX_INSNS]; 71 struct { 72 void *insns; 73 unsigned int len; 74 } ptr; 75 } u; 76 __u8 aux; 77 __u8 data[MAX_DATA]; 78 struct { 79 int data_size; 80 __u32 result; 81 } test[MAX_SUBTESTS]; 82 int (*fill_helper)(struct bpf_test *self); 83 }; 84 85 /* Large test cases need separate allocation and fill handler. */ 86 87 static 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 107 static 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 126 static 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 153 static 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 172 static 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 195 static 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 217 static 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 243 static 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 266 static struct bpf_test tests[] = { 267 { 268 "TAX", 269 .u.insns = { 270 BPF_STMT(BPF_LD | BPF_IMM, 1), 271 BPF_STMT(BPF_MISC | BPF_TAX, 0), 272 BPF_STMT(BPF_LD | BPF_IMM, 2), 273 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 274 BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */ 275 BPF_STMT(BPF_MISC | BPF_TAX, 0), 276 BPF_STMT(BPF_LD | BPF_LEN, 0), 277 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 278 BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */ 279 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), 280 BPF_STMT(BPF_RET | BPF_A, 0) 281 }, 282 CLASSIC, 283 { 10, 20, 30, 40, 50 }, 284 { { 2, 10 }, { 3, 20 }, { 4, 30 } }, 285 }, 286 { 287 "TXA", 288 .u.insns = { 289 BPF_STMT(BPF_LDX | BPF_LEN, 0), 290 BPF_STMT(BPF_MISC | BPF_TXA, 0), 291 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 292 BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */ 293 }, 294 CLASSIC, 295 { 10, 20, 30, 40, 50 }, 296 { { 1, 2 }, { 3, 6 }, { 4, 8 } }, 297 }, 298 { 299 "ADD_SUB_MUL_K", 300 .u.insns = { 301 BPF_STMT(BPF_LD | BPF_IMM, 1), 302 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2), 303 BPF_STMT(BPF_LDX | BPF_IMM, 3), 304 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), 305 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff), 306 BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3), 307 BPF_STMT(BPF_RET | BPF_A, 0) 308 }, 309 CLASSIC | FLAG_NO_DATA, 310 { }, 311 { { 0, 0xfffffffd } } 312 }, 313 { 314 "DIV_MOD_KX", 315 .u.insns = { 316 BPF_STMT(BPF_LD | BPF_IMM, 8), 317 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2), 318 BPF_STMT(BPF_MISC | BPF_TAX, 0), 319 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), 320 BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0), 321 BPF_STMT(BPF_MISC | BPF_TAX, 0), 322 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), 323 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000), 324 BPF_STMT(BPF_MISC | BPF_TAX, 0), 325 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), 326 BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0), 327 BPF_STMT(BPF_MISC | BPF_TAX, 0), 328 BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff), 329 BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x70000000), 330 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 331 BPF_STMT(BPF_RET | BPF_A, 0) 332 }, 333 CLASSIC | FLAG_NO_DATA, 334 { }, 335 { { 0, 0x20000000 } } 336 }, 337 { 338 "AND_OR_LSH_K", 339 .u.insns = { 340 BPF_STMT(BPF_LD | BPF_IMM, 0xff), 341 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0), 342 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27), 343 BPF_STMT(BPF_MISC | BPF_TAX, 0), 344 BPF_STMT(BPF_LD | BPF_IMM, 0xf), 345 BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0), 346 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 347 BPF_STMT(BPF_RET | BPF_A, 0) 348 }, 349 CLASSIC | FLAG_NO_DATA, 350 { }, 351 { { 0, 0x800000ff }, { 1, 0x800000ff } }, 352 }, 353 { 354 "LD_IMM_0", 355 .u.insns = { 356 BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */ 357 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0), 358 BPF_STMT(BPF_RET | BPF_K, 0), 359 BPF_STMT(BPF_RET | BPF_K, 1), 360 }, 361 CLASSIC, 362 { }, 363 { { 1, 1 } }, 364 }, 365 { 366 "LD_IND", 367 .u.insns = { 368 BPF_STMT(BPF_LDX | BPF_LEN, 0), 369 BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K), 370 BPF_STMT(BPF_RET | BPF_K, 1) 371 }, 372 CLASSIC, 373 { }, 374 { { 1, 0 }, { 10, 0 }, { 60, 0 } }, 375 }, 376 { 377 "LD_ABS", 378 .u.insns = { 379 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000), 380 BPF_STMT(BPF_RET | BPF_K, 1) 381 }, 382 CLASSIC, 383 { }, 384 { { 1, 0 }, { 10, 0 }, { 60, 0 } }, 385 }, 386 { 387 "LD_ABS_LL", 388 .u.insns = { 389 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF), 390 BPF_STMT(BPF_MISC | BPF_TAX, 0), 391 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1), 392 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 393 BPF_STMT(BPF_RET | BPF_A, 0) 394 }, 395 CLASSIC, 396 { 1, 2, 3 }, 397 { { 1, 0 }, { 2, 3 } }, 398 }, 399 { 400 "LD_IND_LL", 401 .u.insns = { 402 BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1), 403 BPF_STMT(BPF_LDX | BPF_LEN, 0), 404 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 405 BPF_STMT(BPF_MISC | BPF_TAX, 0), 406 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), 407 BPF_STMT(BPF_RET | BPF_A, 0) 408 }, 409 CLASSIC, 410 { 1, 2, 3, 0xff }, 411 { { 1, 1 }, { 3, 3 }, { 4, 0xff } }, 412 }, 413 { 414 "LD_ABS_NET", 415 .u.insns = { 416 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF), 417 BPF_STMT(BPF_MISC | BPF_TAX, 0), 418 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1), 419 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 420 BPF_STMT(BPF_RET | BPF_A, 0) 421 }, 422 CLASSIC, 423 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, 424 { { 15, 0 }, { 16, 3 } }, 425 }, 426 { 427 "LD_IND_NET", 428 .u.insns = { 429 BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15), 430 BPF_STMT(BPF_LDX | BPF_LEN, 0), 431 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 432 BPF_STMT(BPF_MISC | BPF_TAX, 0), 433 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), 434 BPF_STMT(BPF_RET | BPF_A, 0) 435 }, 436 CLASSIC, 437 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, 438 { { 14, 0 }, { 15, 1 }, { 17, 3 } }, 439 }, 440 { 441 "LD_PKTTYPE", 442 .u.insns = { 443 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 444 SKF_AD_OFF + SKF_AD_PKTTYPE), 445 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), 446 BPF_STMT(BPF_RET | BPF_K, 1), 447 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 448 SKF_AD_OFF + SKF_AD_PKTTYPE), 449 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), 450 BPF_STMT(BPF_RET | BPF_K, 1), 451 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 452 SKF_AD_OFF + SKF_AD_PKTTYPE), 453 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0), 454 BPF_STMT(BPF_RET | BPF_K, 1), 455 BPF_STMT(BPF_RET | BPF_A, 0) 456 }, 457 CLASSIC, 458 { }, 459 { { 1, 3 }, { 10, 3 } }, 460 }, 461 { 462 "LD_MARK", 463 .u.insns = { 464 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 465 SKF_AD_OFF + SKF_AD_MARK), 466 BPF_STMT(BPF_RET | BPF_A, 0) 467 }, 468 CLASSIC, 469 { }, 470 { { 1, SKB_MARK}, { 10, SKB_MARK} }, 471 }, 472 { 473 "LD_RXHASH", 474 .u.insns = { 475 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 476 SKF_AD_OFF + SKF_AD_RXHASH), 477 BPF_STMT(BPF_RET | BPF_A, 0) 478 }, 479 CLASSIC, 480 { }, 481 { { 1, SKB_HASH}, { 10, SKB_HASH} }, 482 }, 483 { 484 "LD_QUEUE", 485 .u.insns = { 486 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 487 SKF_AD_OFF + SKF_AD_QUEUE), 488 BPF_STMT(BPF_RET | BPF_A, 0) 489 }, 490 CLASSIC, 491 { }, 492 { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } }, 493 }, 494 { 495 "LD_PROTOCOL", 496 .u.insns = { 497 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1), 498 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0), 499 BPF_STMT(BPF_RET | BPF_K, 0), 500 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 501 SKF_AD_OFF + SKF_AD_PROTOCOL), 502 BPF_STMT(BPF_MISC | BPF_TAX, 0), 503 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), 504 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0), 505 BPF_STMT(BPF_RET | BPF_K, 0), 506 BPF_STMT(BPF_MISC | BPF_TXA, 0), 507 BPF_STMT(BPF_RET | BPF_A, 0) 508 }, 509 CLASSIC, 510 { 10, 20, 30 }, 511 { { 10, ETH_P_IP }, { 100, ETH_P_IP } }, 512 }, 513 { 514 "LD_VLAN_TAG", 515 .u.insns = { 516 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 517 SKF_AD_OFF + SKF_AD_VLAN_TAG), 518 BPF_STMT(BPF_RET | BPF_A, 0) 519 }, 520 CLASSIC, 521 { }, 522 { 523 { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }, 524 { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT } 525 }, 526 }, 527 { 528 "LD_VLAN_TAG_PRESENT", 529 .u.insns = { 530 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 531 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT), 532 BPF_STMT(BPF_RET | BPF_A, 0) 533 }, 534 CLASSIC, 535 { }, 536 { 537 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }, 538 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) } 539 }, 540 }, 541 { 542 "LD_IFINDEX", 543 .u.insns = { 544 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 545 SKF_AD_OFF + SKF_AD_IFINDEX), 546 BPF_STMT(BPF_RET | BPF_A, 0) 547 }, 548 CLASSIC, 549 { }, 550 { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } }, 551 }, 552 { 553 "LD_HATYPE", 554 .u.insns = { 555 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 556 SKF_AD_OFF + SKF_AD_HATYPE), 557 BPF_STMT(BPF_RET | BPF_A, 0) 558 }, 559 CLASSIC, 560 { }, 561 { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } }, 562 }, 563 { 564 "LD_CPU", 565 .u.insns = { 566 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 567 SKF_AD_OFF + SKF_AD_CPU), 568 BPF_STMT(BPF_MISC | BPF_TAX, 0), 569 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 570 SKF_AD_OFF + SKF_AD_CPU), 571 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), 572 BPF_STMT(BPF_RET | BPF_A, 0) 573 }, 574 CLASSIC, 575 { }, 576 { { 1, 0 }, { 10, 0 } }, 577 }, 578 { 579 "LD_NLATTR", 580 .u.insns = { 581 BPF_STMT(BPF_LDX | BPF_IMM, 2), 582 BPF_STMT(BPF_MISC | BPF_TXA, 0), 583 BPF_STMT(BPF_LDX | BPF_IMM, 3), 584 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 585 SKF_AD_OFF + SKF_AD_NLATTR), 586 BPF_STMT(BPF_RET | BPF_A, 0) 587 }, 588 CLASSIC, 589 #ifdef __BIG_ENDIAN 590 { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 }, 591 #else 592 { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 }, 593 #endif 594 { { 4, 0 }, { 20, 6 } }, 595 }, 596 { 597 "LD_NLATTR_NEST", 598 .u.insns = { 599 BPF_STMT(BPF_LD | BPF_IMM, 2), 600 BPF_STMT(BPF_LDX | BPF_IMM, 3), 601 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 602 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 603 BPF_STMT(BPF_LD | BPF_IMM, 2), 604 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 605 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 606 BPF_STMT(BPF_LD | BPF_IMM, 2), 607 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 608 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 609 BPF_STMT(BPF_LD | BPF_IMM, 2), 610 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 611 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 612 BPF_STMT(BPF_LD | BPF_IMM, 2), 613 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 614 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 615 BPF_STMT(BPF_LD | BPF_IMM, 2), 616 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 617 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 618 BPF_STMT(BPF_LD | BPF_IMM, 2), 619 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 620 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 621 BPF_STMT(BPF_LD | BPF_IMM, 2), 622 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 623 SKF_AD_OFF + SKF_AD_NLATTR_NEST), 624 BPF_STMT(BPF_RET | BPF_A, 0) 625 }, 626 CLASSIC, 627 #ifdef __BIG_ENDIAN 628 { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 }, 629 #else 630 { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 }, 631 #endif 632 { { 4, 0 }, { 20, 10 } }, 633 }, 634 { 635 "LD_PAYLOAD_OFF", 636 .u.insns = { 637 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 638 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 639 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 640 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 641 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 642 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 643 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 644 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 645 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 646 SKF_AD_OFF + SKF_AD_PAY_OFFSET), 647 BPF_STMT(BPF_RET | BPF_A, 0) 648 }, 649 CLASSIC, 650 /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800), 651 * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request, 652 * id 9737, seq 1, length 64 653 */ 654 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 655 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 656 0x08, 0x00, 657 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40, 658 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 }, 659 { { 30, 0 }, { 100, 42 } }, 660 }, 661 { 662 "LD_ANC_XOR", 663 .u.insns = { 664 BPF_STMT(BPF_LD | BPF_IMM, 10), 665 BPF_STMT(BPF_LDX | BPF_IMM, 300), 666 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 667 SKF_AD_OFF + SKF_AD_ALU_XOR_X), 668 BPF_STMT(BPF_RET | BPF_A, 0) 669 }, 670 CLASSIC, 671 { }, 672 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } }, 673 }, 674 { 675 "SPILL_FILL", 676 .u.insns = { 677 BPF_STMT(BPF_LDX | BPF_LEN, 0), 678 BPF_STMT(BPF_LD | BPF_IMM, 2), 679 BPF_STMT(BPF_ALU | BPF_RSH, 1), 680 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), 681 BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */ 682 BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000), 683 BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */ 684 BPF_STMT(BPF_STX, 15), /* M3 = len */ 685 BPF_STMT(BPF_LDX | BPF_MEM, 1), 686 BPF_STMT(BPF_LD | BPF_MEM, 2), 687 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), 688 BPF_STMT(BPF_LDX | BPF_MEM, 15), 689 BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0), 690 BPF_STMT(BPF_RET | BPF_A, 0) 691 }, 692 CLASSIC, 693 { }, 694 { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } } 695 }, 696 { 697 "JEQ", 698 .u.insns = { 699 BPF_STMT(BPF_LDX | BPF_LEN, 0), 700 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), 701 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1), 702 BPF_STMT(BPF_RET | BPF_K, 1), 703 BPF_STMT(BPF_RET | BPF_K, MAX_K) 704 }, 705 CLASSIC, 706 { 3, 3, 3, 3, 3 }, 707 { { 1, 0 }, { 3, 1 }, { 4, MAX_K } }, 708 }, 709 { 710 "JGT", 711 .u.insns = { 712 BPF_STMT(BPF_LDX | BPF_LEN, 0), 713 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), 714 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1), 715 BPF_STMT(BPF_RET | BPF_K, 1), 716 BPF_STMT(BPF_RET | BPF_K, MAX_K) 717 }, 718 CLASSIC, 719 { 4, 4, 4, 3, 3 }, 720 { { 2, 0 }, { 3, 1 }, { 4, MAX_K } }, 721 }, 722 { 723 "JGE", 724 .u.insns = { 725 BPF_STMT(BPF_LDX | BPF_LEN, 0), 726 BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K), 727 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0), 728 BPF_STMT(BPF_RET | BPF_K, 10), 729 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0), 730 BPF_STMT(BPF_RET | BPF_K, 20), 731 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0), 732 BPF_STMT(BPF_RET | BPF_K, 30), 733 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0), 734 BPF_STMT(BPF_RET | BPF_K, 40), 735 BPF_STMT(BPF_RET | BPF_K, MAX_K) 736 }, 737 CLASSIC, 738 { 1, 2, 3, 4, 5 }, 739 { { 1, 20 }, { 3, 40 }, { 5, MAX_K } }, 740 }, 741 { 742 "JSET", 743 .u.insns = { 744 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), 745 BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1), 746 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), 747 BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0), 748 BPF_STMT(BPF_LDX | BPF_LEN, 0), 749 BPF_STMT(BPF_MISC | BPF_TXA, 0), 750 BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4), 751 BPF_STMT(BPF_MISC | BPF_TAX, 0), 752 BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), 753 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1), 754 BPF_STMT(BPF_RET | BPF_K, 10), 755 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1), 756 BPF_STMT(BPF_RET | BPF_K, 20), 757 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 758 BPF_STMT(BPF_RET | BPF_K, 30), 759 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 760 BPF_STMT(BPF_RET | BPF_K, 30), 761 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 762 BPF_STMT(BPF_RET | BPF_K, 30), 763 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 764 BPF_STMT(BPF_RET | BPF_K, 30), 765 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0), 766 BPF_STMT(BPF_RET | BPF_K, 30), 767 BPF_STMT(BPF_RET | BPF_K, MAX_K) 768 }, 769 CLASSIC, 770 { 0, 0xAA, 0x55, 1 }, 771 { { 4, 10 }, { 5, 20 }, { 6, MAX_K } }, 772 }, 773 { 774 "tcpdump port 22", 775 .u.insns = { 776 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), 777 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */ 778 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20), 779 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0), 780 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0), 781 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17), 782 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54), 783 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0), 784 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56), 785 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13), 786 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */ 787 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23), 788 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0), 789 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0), 790 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8), 791 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), 792 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0), 793 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), 794 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14), 795 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0), 796 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16), 797 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1), 798 BPF_STMT(BPF_RET | BPF_K, 0xffff), 799 BPF_STMT(BPF_RET | BPF_K, 0), 800 }, 801 CLASSIC, 802 /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800) 803 * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.], 804 * seq 1305692979:1305693027, ack 3650467037, win 65535, 805 * options [nop,nop,TS val 2502645400 ecr 3971138], length 48 806 */ 807 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, 808 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76, 809 0x08, 0x00, 810 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5, 811 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */ 812 0x0a, 0x01, 0x01, 0x95, /* ip src */ 813 0x0a, 0x01, 0x02, 0x0a, /* ip dst */ 814 0xc2, 0x24, 815 0x00, 0x16 /* dst port */ }, 816 { { 10, 0 }, { 30, 0 }, { 100, 65535 } }, 817 }, 818 { 819 "tcpdump complex", 820 .u.insns = { 821 /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] - 822 * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and 823 * (len > 115 or len < 30000000000)' -d 824 */ 825 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), 826 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0), 827 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29), 828 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23), 829 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27), 830 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), 831 BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0), 832 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), 833 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14), 834 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0), 835 BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16), 836 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20), 837 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16), 838 BPF_STMT(BPF_ST, 1), 839 BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14), 840 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf), 841 BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2), 842 BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */ 843 BPF_STMT(BPF_LD | BPF_MEM, 1), 844 BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), 845 BPF_STMT(BPF_ST, 5), 846 BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), 847 BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26), 848 BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0), 849 BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2), 850 BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */ 851 BPF_STMT(BPF_LD | BPF_MEM, 5), 852 BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0), 853 BPF_STMT(BPF_LD | BPF_LEN, 0), 854 BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0), 855 BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0), 856 BPF_STMT(BPF_RET | BPF_K, 0xffff), 857 BPF_STMT(BPF_RET | BPF_K, 0), 858 }, 859 CLASSIC, 860 { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, 861 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76, 862 0x08, 0x00, 863 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5, 864 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */ 865 0x0a, 0x01, 0x01, 0x95, /* ip src */ 866 0x0a, 0x01, 0x02, 0x0a, /* ip dst */ 867 0xc2, 0x24, 868 0x00, 0x16 /* dst port */ }, 869 { { 10, 0 }, { 30, 0 }, { 100, 65535 } }, 870 }, 871 { 872 "RET_A", 873 .u.insns = { 874 /* check that unitialized X and A contain zeros */ 875 BPF_STMT(BPF_MISC | BPF_TXA, 0), 876 BPF_STMT(BPF_RET | BPF_A, 0) 877 }, 878 CLASSIC, 879 { }, 880 { {1, 0}, {2, 0} }, 881 }, 882 { 883 "INT: ADD trivial", 884 .u.insns_int = { 885 BPF_ALU64_IMM(BPF_MOV, R1, 1), 886 BPF_ALU64_IMM(BPF_ADD, R1, 2), 887 BPF_ALU64_IMM(BPF_MOV, R2, 3), 888 BPF_ALU64_REG(BPF_SUB, R1, R2), 889 BPF_ALU64_IMM(BPF_ADD, R1, -1), 890 BPF_ALU64_IMM(BPF_MUL, R1, 3), 891 BPF_ALU64_REG(BPF_MOV, R0, R1), 892 BPF_EXIT_INSN(), 893 }, 894 INTERNAL, 895 { }, 896 { { 0, 0xfffffffd } } 897 }, 898 { 899 "INT: MUL_X", 900 .u.insns_int = { 901 BPF_ALU64_IMM(BPF_MOV, R0, -1), 902 BPF_ALU64_IMM(BPF_MOV, R1, -1), 903 BPF_ALU64_IMM(BPF_MOV, R2, 3), 904 BPF_ALU64_REG(BPF_MUL, R1, R2), 905 BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1), 906 BPF_EXIT_INSN(), 907 BPF_ALU64_IMM(BPF_MOV, R0, 1), 908 BPF_EXIT_INSN(), 909 }, 910 INTERNAL, 911 { }, 912 { { 0, 1 } } 913 }, 914 { 915 "INT: MUL_X2", 916 .u.insns_int = { 917 BPF_ALU32_IMM(BPF_MOV, R0, -1), 918 BPF_ALU32_IMM(BPF_MOV, R1, -1), 919 BPF_ALU32_IMM(BPF_MOV, R2, 3), 920 BPF_ALU64_REG(BPF_MUL, R1, R2), 921 BPF_ALU64_IMM(BPF_RSH, R1, 8), 922 BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1), 923 BPF_EXIT_INSN(), 924 BPF_ALU32_IMM(BPF_MOV, R0, 1), 925 BPF_EXIT_INSN(), 926 }, 927 INTERNAL, 928 { }, 929 { { 0, 1 } } 930 }, 931 { 932 "INT: MUL32_X", 933 .u.insns_int = { 934 BPF_ALU32_IMM(BPF_MOV, R0, -1), 935 BPF_ALU64_IMM(BPF_MOV, R1, -1), 936 BPF_ALU32_IMM(BPF_MOV, R2, 3), 937 BPF_ALU32_REG(BPF_MUL, R1, R2), 938 BPF_ALU64_IMM(BPF_RSH, R1, 8), 939 BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1), 940 BPF_EXIT_INSN(), 941 BPF_ALU32_IMM(BPF_MOV, R0, 1), 942 BPF_EXIT_INSN(), 943 }, 944 INTERNAL, 945 { }, 946 { { 0, 1 } } 947 }, 948 { 949 /* Have to test all register combinations, since 950 * JITing of different registers will produce 951 * different asm code. 952 */ 953 "INT: ADD 64-bit", 954 .u.insns_int = { 955 BPF_ALU64_IMM(BPF_MOV, R0, 0), 956 BPF_ALU64_IMM(BPF_MOV, R1, 1), 957 BPF_ALU64_IMM(BPF_MOV, R2, 2), 958 BPF_ALU64_IMM(BPF_MOV, R3, 3), 959 BPF_ALU64_IMM(BPF_MOV, R4, 4), 960 BPF_ALU64_IMM(BPF_MOV, R5, 5), 961 BPF_ALU64_IMM(BPF_MOV, R6, 6), 962 BPF_ALU64_IMM(BPF_MOV, R7, 7), 963 BPF_ALU64_IMM(BPF_MOV, R8, 8), 964 BPF_ALU64_IMM(BPF_MOV, R9, 9), 965 BPF_ALU64_IMM(BPF_ADD, R0, 20), 966 BPF_ALU64_IMM(BPF_ADD, R1, 20), 967 BPF_ALU64_IMM(BPF_ADD, R2, 20), 968 BPF_ALU64_IMM(BPF_ADD, R3, 20), 969 BPF_ALU64_IMM(BPF_ADD, R4, 20), 970 BPF_ALU64_IMM(BPF_ADD, R5, 20), 971 BPF_ALU64_IMM(BPF_ADD, R6, 20), 972 BPF_ALU64_IMM(BPF_ADD, R7, 20), 973 BPF_ALU64_IMM(BPF_ADD, R8, 20), 974 BPF_ALU64_IMM(BPF_ADD, R9, 20), 975 BPF_ALU64_IMM(BPF_SUB, R0, 10), 976 BPF_ALU64_IMM(BPF_SUB, R1, 10), 977 BPF_ALU64_IMM(BPF_SUB, R2, 10), 978 BPF_ALU64_IMM(BPF_SUB, R3, 10), 979 BPF_ALU64_IMM(BPF_SUB, R4, 10), 980 BPF_ALU64_IMM(BPF_SUB, R5, 10), 981 BPF_ALU64_IMM(BPF_SUB, R6, 10), 982 BPF_ALU64_IMM(BPF_SUB, R7, 10), 983 BPF_ALU64_IMM(BPF_SUB, R8, 10), 984 BPF_ALU64_IMM(BPF_SUB, R9, 10), 985 BPF_ALU64_REG(BPF_ADD, R0, R0), 986 BPF_ALU64_REG(BPF_ADD, R0, R1), 987 BPF_ALU64_REG(BPF_ADD, R0, R2), 988 BPF_ALU64_REG(BPF_ADD, R0, R3), 989 BPF_ALU64_REG(BPF_ADD, R0, R4), 990 BPF_ALU64_REG(BPF_ADD, R0, R5), 991 BPF_ALU64_REG(BPF_ADD, R0, R6), 992 BPF_ALU64_REG(BPF_ADD, R0, R7), 993 BPF_ALU64_REG(BPF_ADD, R0, R8), 994 BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */ 995 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1), 996 BPF_EXIT_INSN(), 997 BPF_ALU64_REG(BPF_ADD, R1, R0), 998 BPF_ALU64_REG(BPF_ADD, R1, R1), 999 BPF_ALU64_REG(BPF_ADD, R1, R2), 1000 BPF_ALU64_REG(BPF_ADD, R1, R3), 1001 BPF_ALU64_REG(BPF_ADD, R1, R4), 1002 BPF_ALU64_REG(BPF_ADD, R1, R5), 1003 BPF_ALU64_REG(BPF_ADD, R1, R6), 1004 BPF_ALU64_REG(BPF_ADD, R1, R7), 1005 BPF_ALU64_REG(BPF_ADD, R1, R8), 1006 BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */ 1007 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1), 1008 BPF_EXIT_INSN(), 1009 BPF_ALU64_REG(BPF_ADD, R2, R0), 1010 BPF_ALU64_REG(BPF_ADD, R2, R1), 1011 BPF_ALU64_REG(BPF_ADD, R2, R2), 1012 BPF_ALU64_REG(BPF_ADD, R2, R3), 1013 BPF_ALU64_REG(BPF_ADD, R2, R4), 1014 BPF_ALU64_REG(BPF_ADD, R2, R5), 1015 BPF_ALU64_REG(BPF_ADD, R2, R6), 1016 BPF_ALU64_REG(BPF_ADD, R2, R7), 1017 BPF_ALU64_REG(BPF_ADD, R2, R8), 1018 BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */ 1019 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1), 1020 BPF_EXIT_INSN(), 1021 BPF_ALU64_REG(BPF_ADD, R3, R0), 1022 BPF_ALU64_REG(BPF_ADD, R3, R1), 1023 BPF_ALU64_REG(BPF_ADD, R3, R2), 1024 BPF_ALU64_REG(BPF_ADD, R3, R3), 1025 BPF_ALU64_REG(BPF_ADD, R3, R4), 1026 BPF_ALU64_REG(BPF_ADD, R3, R5), 1027 BPF_ALU64_REG(BPF_ADD, R3, R6), 1028 BPF_ALU64_REG(BPF_ADD, R3, R7), 1029 BPF_ALU64_REG(BPF_ADD, R3, R8), 1030 BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */ 1031 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1), 1032 BPF_EXIT_INSN(), 1033 BPF_ALU64_REG(BPF_ADD, R4, R0), 1034 BPF_ALU64_REG(BPF_ADD, R4, R1), 1035 BPF_ALU64_REG(BPF_ADD, R4, R2), 1036 BPF_ALU64_REG(BPF_ADD, R4, R3), 1037 BPF_ALU64_REG(BPF_ADD, R4, R4), 1038 BPF_ALU64_REG(BPF_ADD, R4, R5), 1039 BPF_ALU64_REG(BPF_ADD, R4, R6), 1040 BPF_ALU64_REG(BPF_ADD, R4, R7), 1041 BPF_ALU64_REG(BPF_ADD, R4, R8), 1042 BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */ 1043 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1), 1044 BPF_EXIT_INSN(), 1045 BPF_ALU64_REG(BPF_ADD, R5, R0), 1046 BPF_ALU64_REG(BPF_ADD, R5, R1), 1047 BPF_ALU64_REG(BPF_ADD, R5, R2), 1048 BPF_ALU64_REG(BPF_ADD, R5, R3), 1049 BPF_ALU64_REG(BPF_ADD, R5, R4), 1050 BPF_ALU64_REG(BPF_ADD, R5, R5), 1051 BPF_ALU64_REG(BPF_ADD, R5, R6), 1052 BPF_ALU64_REG(BPF_ADD, R5, R7), 1053 BPF_ALU64_REG(BPF_ADD, R5, R8), 1054 BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */ 1055 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1), 1056 BPF_EXIT_INSN(), 1057 BPF_ALU64_REG(BPF_ADD, R6, R0), 1058 BPF_ALU64_REG(BPF_ADD, R6, R1), 1059 BPF_ALU64_REG(BPF_ADD, R6, R2), 1060 BPF_ALU64_REG(BPF_ADD, R6, R3), 1061 BPF_ALU64_REG(BPF_ADD, R6, R4), 1062 BPF_ALU64_REG(BPF_ADD, R6, R5), 1063 BPF_ALU64_REG(BPF_ADD, R6, R6), 1064 BPF_ALU64_REG(BPF_ADD, R6, R7), 1065 BPF_ALU64_REG(BPF_ADD, R6, R8), 1066 BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */ 1067 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1), 1068 BPF_EXIT_INSN(), 1069 BPF_ALU64_REG(BPF_ADD, R7, R0), 1070 BPF_ALU64_REG(BPF_ADD, R7, R1), 1071 BPF_ALU64_REG(BPF_ADD, R7, R2), 1072 BPF_ALU64_REG(BPF_ADD, R7, R3), 1073 BPF_ALU64_REG(BPF_ADD, R7, R4), 1074 BPF_ALU64_REG(BPF_ADD, R7, R5), 1075 BPF_ALU64_REG(BPF_ADD, R7, R6), 1076 BPF_ALU64_REG(BPF_ADD, R7, R7), 1077 BPF_ALU64_REG(BPF_ADD, R7, R8), 1078 BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */ 1079 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1), 1080 BPF_EXIT_INSN(), 1081 BPF_ALU64_REG(BPF_ADD, R8, R0), 1082 BPF_ALU64_REG(BPF_ADD, R8, R1), 1083 BPF_ALU64_REG(BPF_ADD, R8, R2), 1084 BPF_ALU64_REG(BPF_ADD, R8, R3), 1085 BPF_ALU64_REG(BPF_ADD, R8, R4), 1086 BPF_ALU64_REG(BPF_ADD, R8, R5), 1087 BPF_ALU64_REG(BPF_ADD, R8, R6), 1088 BPF_ALU64_REG(BPF_ADD, R8, R7), 1089 BPF_ALU64_REG(BPF_ADD, R8, R8), 1090 BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */ 1091 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1), 1092 BPF_EXIT_INSN(), 1093 BPF_ALU64_REG(BPF_ADD, R9, R0), 1094 BPF_ALU64_REG(BPF_ADD, R9, R1), 1095 BPF_ALU64_REG(BPF_ADD, R9, R2), 1096 BPF_ALU64_REG(BPF_ADD, R9, R3), 1097 BPF_ALU64_REG(BPF_ADD, R9, R4), 1098 BPF_ALU64_REG(BPF_ADD, R9, R5), 1099 BPF_ALU64_REG(BPF_ADD, R9, R6), 1100 BPF_ALU64_REG(BPF_ADD, R9, R7), 1101 BPF_ALU64_REG(BPF_ADD, R9, R8), 1102 BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */ 1103 BPF_ALU64_REG(BPF_MOV, R0, R9), 1104 BPF_EXIT_INSN(), 1105 }, 1106 INTERNAL, 1107 { }, 1108 { { 0, 2957380 } } 1109 }, 1110 { 1111 "INT: ADD 32-bit", 1112 .u.insns_int = { 1113 BPF_ALU32_IMM(BPF_MOV, R0, 20), 1114 BPF_ALU32_IMM(BPF_MOV, R1, 1), 1115 BPF_ALU32_IMM(BPF_MOV, R2, 2), 1116 BPF_ALU32_IMM(BPF_MOV, R3, 3), 1117 BPF_ALU32_IMM(BPF_MOV, R4, 4), 1118 BPF_ALU32_IMM(BPF_MOV, R5, 5), 1119 BPF_ALU32_IMM(BPF_MOV, R6, 6), 1120 BPF_ALU32_IMM(BPF_MOV, R7, 7), 1121 BPF_ALU32_IMM(BPF_MOV, R8, 8), 1122 BPF_ALU32_IMM(BPF_MOV, R9, 9), 1123 BPF_ALU64_IMM(BPF_ADD, R1, 10), 1124 BPF_ALU64_IMM(BPF_ADD, R2, 10), 1125 BPF_ALU64_IMM(BPF_ADD, R3, 10), 1126 BPF_ALU64_IMM(BPF_ADD, R4, 10), 1127 BPF_ALU64_IMM(BPF_ADD, R5, 10), 1128 BPF_ALU64_IMM(BPF_ADD, R6, 10), 1129 BPF_ALU64_IMM(BPF_ADD, R7, 10), 1130 BPF_ALU64_IMM(BPF_ADD, R8, 10), 1131 BPF_ALU64_IMM(BPF_ADD, R9, 10), 1132 BPF_ALU32_REG(BPF_ADD, R0, R1), 1133 BPF_ALU32_REG(BPF_ADD, R0, R2), 1134 BPF_ALU32_REG(BPF_ADD, R0, R3), 1135 BPF_ALU32_REG(BPF_ADD, R0, R4), 1136 BPF_ALU32_REG(BPF_ADD, R0, R5), 1137 BPF_ALU32_REG(BPF_ADD, R0, R6), 1138 BPF_ALU32_REG(BPF_ADD, R0, R7), 1139 BPF_ALU32_REG(BPF_ADD, R0, R8), 1140 BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */ 1141 BPF_JMP_IMM(BPF_JEQ, R0, 155, 1), 1142 BPF_EXIT_INSN(), 1143 BPF_ALU32_REG(BPF_ADD, R1, R0), 1144 BPF_ALU32_REG(BPF_ADD, R1, R1), 1145 BPF_ALU32_REG(BPF_ADD, R1, R2), 1146 BPF_ALU32_REG(BPF_ADD, R1, R3), 1147 BPF_ALU32_REG(BPF_ADD, R1, R4), 1148 BPF_ALU32_REG(BPF_ADD, R1, R5), 1149 BPF_ALU32_REG(BPF_ADD, R1, R6), 1150 BPF_ALU32_REG(BPF_ADD, R1, R7), 1151 BPF_ALU32_REG(BPF_ADD, R1, R8), 1152 BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */ 1153 BPF_JMP_IMM(BPF_JEQ, R1, 456, 1), 1154 BPF_EXIT_INSN(), 1155 BPF_ALU32_REG(BPF_ADD, R2, R0), 1156 BPF_ALU32_REG(BPF_ADD, R2, R1), 1157 BPF_ALU32_REG(BPF_ADD, R2, R2), 1158 BPF_ALU32_REG(BPF_ADD, R2, R3), 1159 BPF_ALU32_REG(BPF_ADD, R2, R4), 1160 BPF_ALU32_REG(BPF_ADD, R2, R5), 1161 BPF_ALU32_REG(BPF_ADD, R2, R6), 1162 BPF_ALU32_REG(BPF_ADD, R2, R7), 1163 BPF_ALU32_REG(BPF_ADD, R2, R8), 1164 BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */ 1165 BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1), 1166 BPF_EXIT_INSN(), 1167 BPF_ALU32_REG(BPF_ADD, R3, R0), 1168 BPF_ALU32_REG(BPF_ADD, R3, R1), 1169 BPF_ALU32_REG(BPF_ADD, R3, R2), 1170 BPF_ALU32_REG(BPF_ADD, R3, R3), 1171 BPF_ALU32_REG(BPF_ADD, R3, R4), 1172 BPF_ALU32_REG(BPF_ADD, R3, R5), 1173 BPF_ALU32_REG(BPF_ADD, R3, R6), 1174 BPF_ALU32_REG(BPF_ADD, R3, R7), 1175 BPF_ALU32_REG(BPF_ADD, R3, R8), 1176 BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */ 1177 BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1), 1178 BPF_EXIT_INSN(), 1179 BPF_ALU32_REG(BPF_ADD, R4, R0), 1180 BPF_ALU32_REG(BPF_ADD, R4, R1), 1181 BPF_ALU32_REG(BPF_ADD, R4, R2), 1182 BPF_ALU32_REG(BPF_ADD, R4, R3), 1183 BPF_ALU32_REG(BPF_ADD, R4, R4), 1184 BPF_ALU32_REG(BPF_ADD, R4, R5), 1185 BPF_ALU32_REG(BPF_ADD, R4, R6), 1186 BPF_ALU32_REG(BPF_ADD, R4, R7), 1187 BPF_ALU32_REG(BPF_ADD, R4, R8), 1188 BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */ 1189 BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1), 1190 BPF_EXIT_INSN(), 1191 BPF_ALU32_REG(BPF_ADD, R5, R0), 1192 BPF_ALU32_REG(BPF_ADD, R5, R1), 1193 BPF_ALU32_REG(BPF_ADD, R5, R2), 1194 BPF_ALU32_REG(BPF_ADD, R5, R3), 1195 BPF_ALU32_REG(BPF_ADD, R5, R4), 1196 BPF_ALU32_REG(BPF_ADD, R5, R5), 1197 BPF_ALU32_REG(BPF_ADD, R5, R6), 1198 BPF_ALU32_REG(BPF_ADD, R5, R7), 1199 BPF_ALU32_REG(BPF_ADD, R5, R8), 1200 BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */ 1201 BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1), 1202 BPF_EXIT_INSN(), 1203 BPF_ALU32_REG(BPF_ADD, R6, R0), 1204 BPF_ALU32_REG(BPF_ADD, R6, R1), 1205 BPF_ALU32_REG(BPF_ADD, R6, R2), 1206 BPF_ALU32_REG(BPF_ADD, R6, R3), 1207 BPF_ALU32_REG(BPF_ADD, R6, R4), 1208 BPF_ALU32_REG(BPF_ADD, R6, R5), 1209 BPF_ALU32_REG(BPF_ADD, R6, R6), 1210 BPF_ALU32_REG(BPF_ADD, R6, R7), 1211 BPF_ALU32_REG(BPF_ADD, R6, R8), 1212 BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */ 1213 BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1), 1214 BPF_EXIT_INSN(), 1215 BPF_ALU32_REG(BPF_ADD, R7, R0), 1216 BPF_ALU32_REG(BPF_ADD, R7, R1), 1217 BPF_ALU32_REG(BPF_ADD, R7, R2), 1218 BPF_ALU32_REG(BPF_ADD, R7, R3), 1219 BPF_ALU32_REG(BPF_ADD, R7, R4), 1220 BPF_ALU32_REG(BPF_ADD, R7, R5), 1221 BPF_ALU32_REG(BPF_ADD, R7, R6), 1222 BPF_ALU32_REG(BPF_ADD, R7, R7), 1223 BPF_ALU32_REG(BPF_ADD, R7, R8), 1224 BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */ 1225 BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1), 1226 BPF_EXIT_INSN(), 1227 BPF_ALU32_REG(BPF_ADD, R8, R0), 1228 BPF_ALU32_REG(BPF_ADD, R8, R1), 1229 BPF_ALU32_REG(BPF_ADD, R8, R2), 1230 BPF_ALU32_REG(BPF_ADD, R8, R3), 1231 BPF_ALU32_REG(BPF_ADD, R8, R4), 1232 BPF_ALU32_REG(BPF_ADD, R8, R5), 1233 BPF_ALU32_REG(BPF_ADD, R8, R6), 1234 BPF_ALU32_REG(BPF_ADD, R8, R7), 1235 BPF_ALU32_REG(BPF_ADD, R8, R8), 1236 BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */ 1237 BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1), 1238 BPF_EXIT_INSN(), 1239 BPF_ALU32_REG(BPF_ADD, R9, R0), 1240 BPF_ALU32_REG(BPF_ADD, R9, R1), 1241 BPF_ALU32_REG(BPF_ADD, R9, R2), 1242 BPF_ALU32_REG(BPF_ADD, R9, R3), 1243 BPF_ALU32_REG(BPF_ADD, R9, R4), 1244 BPF_ALU32_REG(BPF_ADD, R9, R5), 1245 BPF_ALU32_REG(BPF_ADD, R9, R6), 1246 BPF_ALU32_REG(BPF_ADD, R9, R7), 1247 BPF_ALU32_REG(BPF_ADD, R9, R8), 1248 BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */ 1249 BPF_ALU32_REG(BPF_MOV, R0, R9), 1250 BPF_EXIT_INSN(), 1251 }, 1252 INTERNAL, 1253 { }, 1254 { { 0, 2957380 } } 1255 }, 1256 { /* Mainly checking JIT here. */ 1257 "INT: SUB", 1258 .u.insns_int = { 1259 BPF_ALU64_IMM(BPF_MOV, R0, 0), 1260 BPF_ALU64_IMM(BPF_MOV, R1, 1), 1261 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1262 BPF_ALU64_IMM(BPF_MOV, R3, 3), 1263 BPF_ALU64_IMM(BPF_MOV, R4, 4), 1264 BPF_ALU64_IMM(BPF_MOV, R5, 5), 1265 BPF_ALU64_IMM(BPF_MOV, R6, 6), 1266 BPF_ALU64_IMM(BPF_MOV, R7, 7), 1267 BPF_ALU64_IMM(BPF_MOV, R8, 8), 1268 BPF_ALU64_IMM(BPF_MOV, R9, 9), 1269 BPF_ALU64_REG(BPF_SUB, R0, R0), 1270 BPF_ALU64_REG(BPF_SUB, R0, R1), 1271 BPF_ALU64_REG(BPF_SUB, R0, R2), 1272 BPF_ALU64_REG(BPF_SUB, R0, R3), 1273 BPF_ALU64_REG(BPF_SUB, R0, R4), 1274 BPF_ALU64_REG(BPF_SUB, R0, R5), 1275 BPF_ALU64_REG(BPF_SUB, R0, R6), 1276 BPF_ALU64_REG(BPF_SUB, R0, R7), 1277 BPF_ALU64_REG(BPF_SUB, R0, R8), 1278 BPF_ALU64_REG(BPF_SUB, R0, R9), 1279 BPF_ALU64_IMM(BPF_SUB, R0, 10), 1280 BPF_JMP_IMM(BPF_JEQ, R0, -55, 1), 1281 BPF_EXIT_INSN(), 1282 BPF_ALU64_REG(BPF_SUB, R1, R0), 1283 BPF_ALU64_REG(BPF_SUB, R1, R2), 1284 BPF_ALU64_REG(BPF_SUB, R1, R3), 1285 BPF_ALU64_REG(BPF_SUB, R1, R4), 1286 BPF_ALU64_REG(BPF_SUB, R1, R5), 1287 BPF_ALU64_REG(BPF_SUB, R1, R6), 1288 BPF_ALU64_REG(BPF_SUB, R1, R7), 1289 BPF_ALU64_REG(BPF_SUB, R1, R8), 1290 BPF_ALU64_REG(BPF_SUB, R1, R9), 1291 BPF_ALU64_IMM(BPF_SUB, R1, 10), 1292 BPF_ALU64_REG(BPF_SUB, R2, R0), 1293 BPF_ALU64_REG(BPF_SUB, R2, R1), 1294 BPF_ALU64_REG(BPF_SUB, R2, R3), 1295 BPF_ALU64_REG(BPF_SUB, R2, R4), 1296 BPF_ALU64_REG(BPF_SUB, R2, R5), 1297 BPF_ALU64_REG(BPF_SUB, R2, R6), 1298 BPF_ALU64_REG(BPF_SUB, R2, R7), 1299 BPF_ALU64_REG(BPF_SUB, R2, R8), 1300 BPF_ALU64_REG(BPF_SUB, R2, R9), 1301 BPF_ALU64_IMM(BPF_SUB, R2, 10), 1302 BPF_ALU64_REG(BPF_SUB, R3, R0), 1303 BPF_ALU64_REG(BPF_SUB, R3, R1), 1304 BPF_ALU64_REG(BPF_SUB, R3, R2), 1305 BPF_ALU64_REG(BPF_SUB, R3, R4), 1306 BPF_ALU64_REG(BPF_SUB, R3, R5), 1307 BPF_ALU64_REG(BPF_SUB, R3, R6), 1308 BPF_ALU64_REG(BPF_SUB, R3, R7), 1309 BPF_ALU64_REG(BPF_SUB, R3, R8), 1310 BPF_ALU64_REG(BPF_SUB, R3, R9), 1311 BPF_ALU64_IMM(BPF_SUB, R3, 10), 1312 BPF_ALU64_REG(BPF_SUB, R4, R0), 1313 BPF_ALU64_REG(BPF_SUB, R4, R1), 1314 BPF_ALU64_REG(BPF_SUB, R4, R2), 1315 BPF_ALU64_REG(BPF_SUB, R4, R3), 1316 BPF_ALU64_REG(BPF_SUB, R4, R5), 1317 BPF_ALU64_REG(BPF_SUB, R4, R6), 1318 BPF_ALU64_REG(BPF_SUB, R4, R7), 1319 BPF_ALU64_REG(BPF_SUB, R4, R8), 1320 BPF_ALU64_REG(BPF_SUB, R4, R9), 1321 BPF_ALU64_IMM(BPF_SUB, R4, 10), 1322 BPF_ALU64_REG(BPF_SUB, R5, R0), 1323 BPF_ALU64_REG(BPF_SUB, R5, R1), 1324 BPF_ALU64_REG(BPF_SUB, R5, R2), 1325 BPF_ALU64_REG(BPF_SUB, R5, R3), 1326 BPF_ALU64_REG(BPF_SUB, R5, R4), 1327 BPF_ALU64_REG(BPF_SUB, R5, R6), 1328 BPF_ALU64_REG(BPF_SUB, R5, R7), 1329 BPF_ALU64_REG(BPF_SUB, R5, R8), 1330 BPF_ALU64_REG(BPF_SUB, R5, R9), 1331 BPF_ALU64_IMM(BPF_SUB, R5, 10), 1332 BPF_ALU64_REG(BPF_SUB, R6, R0), 1333 BPF_ALU64_REG(BPF_SUB, R6, R1), 1334 BPF_ALU64_REG(BPF_SUB, R6, R2), 1335 BPF_ALU64_REG(BPF_SUB, R6, R3), 1336 BPF_ALU64_REG(BPF_SUB, R6, R4), 1337 BPF_ALU64_REG(BPF_SUB, R6, R5), 1338 BPF_ALU64_REG(BPF_SUB, R6, R7), 1339 BPF_ALU64_REG(BPF_SUB, R6, R8), 1340 BPF_ALU64_REG(BPF_SUB, R6, R9), 1341 BPF_ALU64_IMM(BPF_SUB, R6, 10), 1342 BPF_ALU64_REG(BPF_SUB, R7, R0), 1343 BPF_ALU64_REG(BPF_SUB, R7, R1), 1344 BPF_ALU64_REG(BPF_SUB, R7, R2), 1345 BPF_ALU64_REG(BPF_SUB, R7, R3), 1346 BPF_ALU64_REG(BPF_SUB, R7, R4), 1347 BPF_ALU64_REG(BPF_SUB, R7, R5), 1348 BPF_ALU64_REG(BPF_SUB, R7, R6), 1349 BPF_ALU64_REG(BPF_SUB, R7, R8), 1350 BPF_ALU64_REG(BPF_SUB, R7, R9), 1351 BPF_ALU64_IMM(BPF_SUB, R7, 10), 1352 BPF_ALU64_REG(BPF_SUB, R8, R0), 1353 BPF_ALU64_REG(BPF_SUB, R8, R1), 1354 BPF_ALU64_REG(BPF_SUB, R8, R2), 1355 BPF_ALU64_REG(BPF_SUB, R8, R3), 1356 BPF_ALU64_REG(BPF_SUB, R8, R4), 1357 BPF_ALU64_REG(BPF_SUB, R8, R5), 1358 BPF_ALU64_REG(BPF_SUB, R8, R6), 1359 BPF_ALU64_REG(BPF_SUB, R8, R7), 1360 BPF_ALU64_REG(BPF_SUB, R8, R9), 1361 BPF_ALU64_IMM(BPF_SUB, R8, 10), 1362 BPF_ALU64_REG(BPF_SUB, R9, R0), 1363 BPF_ALU64_REG(BPF_SUB, R9, R1), 1364 BPF_ALU64_REG(BPF_SUB, R9, R2), 1365 BPF_ALU64_REG(BPF_SUB, R9, R3), 1366 BPF_ALU64_REG(BPF_SUB, R9, R4), 1367 BPF_ALU64_REG(BPF_SUB, R9, R5), 1368 BPF_ALU64_REG(BPF_SUB, R9, R6), 1369 BPF_ALU64_REG(BPF_SUB, R9, R7), 1370 BPF_ALU64_REG(BPF_SUB, R9, R8), 1371 BPF_ALU64_IMM(BPF_SUB, R9, 10), 1372 BPF_ALU64_IMM(BPF_SUB, R0, 10), 1373 BPF_ALU64_IMM(BPF_NEG, R0, 0), 1374 BPF_ALU64_REG(BPF_SUB, R0, R1), 1375 BPF_ALU64_REG(BPF_SUB, R0, R2), 1376 BPF_ALU64_REG(BPF_SUB, R0, R3), 1377 BPF_ALU64_REG(BPF_SUB, R0, R4), 1378 BPF_ALU64_REG(BPF_SUB, R0, R5), 1379 BPF_ALU64_REG(BPF_SUB, R0, R6), 1380 BPF_ALU64_REG(BPF_SUB, R0, R7), 1381 BPF_ALU64_REG(BPF_SUB, R0, R8), 1382 BPF_ALU64_REG(BPF_SUB, R0, R9), 1383 BPF_EXIT_INSN(), 1384 }, 1385 INTERNAL, 1386 { }, 1387 { { 0, 11 } } 1388 }, 1389 { /* Mainly checking JIT here. */ 1390 "INT: XOR", 1391 .u.insns_int = { 1392 BPF_ALU64_REG(BPF_SUB, R0, R0), 1393 BPF_ALU64_REG(BPF_XOR, R1, R1), 1394 BPF_JMP_REG(BPF_JEQ, R0, R1, 1), 1395 BPF_EXIT_INSN(), 1396 BPF_ALU64_IMM(BPF_MOV, R0, 10), 1397 BPF_ALU64_IMM(BPF_MOV, R1, -1), 1398 BPF_ALU64_REG(BPF_SUB, R1, R1), 1399 BPF_ALU64_REG(BPF_XOR, R2, R2), 1400 BPF_JMP_REG(BPF_JEQ, R1, R2, 1), 1401 BPF_EXIT_INSN(), 1402 BPF_ALU64_REG(BPF_SUB, R2, R2), 1403 BPF_ALU64_REG(BPF_XOR, R3, R3), 1404 BPF_ALU64_IMM(BPF_MOV, R0, 10), 1405 BPF_ALU64_IMM(BPF_MOV, R1, -1), 1406 BPF_JMP_REG(BPF_JEQ, R2, R3, 1), 1407 BPF_EXIT_INSN(), 1408 BPF_ALU64_REG(BPF_SUB, R3, R3), 1409 BPF_ALU64_REG(BPF_XOR, R4, R4), 1410 BPF_ALU64_IMM(BPF_MOV, R2, 1), 1411 BPF_ALU64_IMM(BPF_MOV, R5, -1), 1412 BPF_JMP_REG(BPF_JEQ, R3, R4, 1), 1413 BPF_EXIT_INSN(), 1414 BPF_ALU64_REG(BPF_SUB, R4, R4), 1415 BPF_ALU64_REG(BPF_XOR, R5, R5), 1416 BPF_ALU64_IMM(BPF_MOV, R3, 1), 1417 BPF_ALU64_IMM(BPF_MOV, R7, -1), 1418 BPF_JMP_REG(BPF_JEQ, R5, R4, 1), 1419 BPF_EXIT_INSN(), 1420 BPF_ALU64_IMM(BPF_MOV, R5, 1), 1421 BPF_ALU64_REG(BPF_SUB, R5, R5), 1422 BPF_ALU64_REG(BPF_XOR, R6, R6), 1423 BPF_ALU64_IMM(BPF_MOV, R1, 1), 1424 BPF_ALU64_IMM(BPF_MOV, R8, -1), 1425 BPF_JMP_REG(BPF_JEQ, R5, R6, 1), 1426 BPF_EXIT_INSN(), 1427 BPF_ALU64_REG(BPF_SUB, R6, R6), 1428 BPF_ALU64_REG(BPF_XOR, R7, R7), 1429 BPF_JMP_REG(BPF_JEQ, R7, R6, 1), 1430 BPF_EXIT_INSN(), 1431 BPF_ALU64_REG(BPF_SUB, R7, R7), 1432 BPF_ALU64_REG(BPF_XOR, R8, R8), 1433 BPF_JMP_REG(BPF_JEQ, R7, R8, 1), 1434 BPF_EXIT_INSN(), 1435 BPF_ALU64_REG(BPF_SUB, R8, R8), 1436 BPF_ALU64_REG(BPF_XOR, R9, R9), 1437 BPF_JMP_REG(BPF_JEQ, R9, R8, 1), 1438 BPF_EXIT_INSN(), 1439 BPF_ALU64_REG(BPF_SUB, R9, R9), 1440 BPF_ALU64_REG(BPF_XOR, R0, R0), 1441 BPF_JMP_REG(BPF_JEQ, R9, R0, 1), 1442 BPF_EXIT_INSN(), 1443 BPF_ALU64_REG(BPF_SUB, R1, R1), 1444 BPF_ALU64_REG(BPF_XOR, R0, R0), 1445 BPF_JMP_REG(BPF_JEQ, R9, R0, 2), 1446 BPF_ALU64_IMM(BPF_MOV, R0, 0), 1447 BPF_EXIT_INSN(), 1448 BPF_ALU64_IMM(BPF_MOV, R0, 1), 1449 BPF_EXIT_INSN(), 1450 }, 1451 INTERNAL, 1452 { }, 1453 { { 0, 1 } } 1454 }, 1455 { /* Mainly checking JIT here. */ 1456 "INT: MUL", 1457 .u.insns_int = { 1458 BPF_ALU64_IMM(BPF_MOV, R0, 11), 1459 BPF_ALU64_IMM(BPF_MOV, R1, 1), 1460 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1461 BPF_ALU64_IMM(BPF_MOV, R3, 3), 1462 BPF_ALU64_IMM(BPF_MOV, R4, 4), 1463 BPF_ALU64_IMM(BPF_MOV, R5, 5), 1464 BPF_ALU64_IMM(BPF_MOV, R6, 6), 1465 BPF_ALU64_IMM(BPF_MOV, R7, 7), 1466 BPF_ALU64_IMM(BPF_MOV, R8, 8), 1467 BPF_ALU64_IMM(BPF_MOV, R9, 9), 1468 BPF_ALU64_REG(BPF_MUL, R0, R0), 1469 BPF_ALU64_REG(BPF_MUL, R0, R1), 1470 BPF_ALU64_REG(BPF_MUL, R0, R2), 1471 BPF_ALU64_REG(BPF_MUL, R0, R3), 1472 BPF_ALU64_REG(BPF_MUL, R0, R4), 1473 BPF_ALU64_REG(BPF_MUL, R0, R5), 1474 BPF_ALU64_REG(BPF_MUL, R0, R6), 1475 BPF_ALU64_REG(BPF_MUL, R0, R7), 1476 BPF_ALU64_REG(BPF_MUL, R0, R8), 1477 BPF_ALU64_REG(BPF_MUL, R0, R9), 1478 BPF_ALU64_IMM(BPF_MUL, R0, 10), 1479 BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1), 1480 BPF_EXIT_INSN(), 1481 BPF_ALU64_REG(BPF_MUL, R1, R0), 1482 BPF_ALU64_REG(BPF_MUL, R1, R2), 1483 BPF_ALU64_REG(BPF_MUL, R1, R3), 1484 BPF_ALU64_REG(BPF_MUL, R1, R4), 1485 BPF_ALU64_REG(BPF_MUL, R1, R5), 1486 BPF_ALU64_REG(BPF_MUL, R1, R6), 1487 BPF_ALU64_REG(BPF_MUL, R1, R7), 1488 BPF_ALU64_REG(BPF_MUL, R1, R8), 1489 BPF_ALU64_REG(BPF_MUL, R1, R9), 1490 BPF_ALU64_IMM(BPF_MUL, R1, 10), 1491 BPF_ALU64_REG(BPF_MOV, R2, R1), 1492 BPF_ALU64_IMM(BPF_RSH, R2, 32), 1493 BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1), 1494 BPF_EXIT_INSN(), 1495 BPF_ALU64_IMM(BPF_LSH, R1, 32), 1496 BPF_ALU64_IMM(BPF_ARSH, R1, 32), 1497 BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1), 1498 BPF_EXIT_INSN(), 1499 BPF_ALU64_REG(BPF_MUL, R2, R0), 1500 BPF_ALU64_REG(BPF_MUL, R2, R1), 1501 BPF_ALU64_REG(BPF_MUL, R2, R3), 1502 BPF_ALU64_REG(BPF_MUL, R2, R4), 1503 BPF_ALU64_REG(BPF_MUL, R2, R5), 1504 BPF_ALU64_REG(BPF_MUL, R2, R6), 1505 BPF_ALU64_REG(BPF_MUL, R2, R7), 1506 BPF_ALU64_REG(BPF_MUL, R2, R8), 1507 BPF_ALU64_REG(BPF_MUL, R2, R9), 1508 BPF_ALU64_IMM(BPF_MUL, R2, 10), 1509 BPF_ALU64_IMM(BPF_RSH, R2, 32), 1510 BPF_ALU64_REG(BPF_MOV, R0, R2), 1511 BPF_EXIT_INSN(), 1512 }, 1513 INTERNAL, 1514 { }, 1515 { { 0, 0x35d97ef2 } } 1516 }, 1517 { 1518 "INT: ALU MIX", 1519 .u.insns_int = { 1520 BPF_ALU64_IMM(BPF_MOV, R0, 11), 1521 BPF_ALU64_IMM(BPF_ADD, R0, -1), 1522 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1523 BPF_ALU64_IMM(BPF_XOR, R2, 3), 1524 BPF_ALU64_REG(BPF_DIV, R0, R2), 1525 BPF_JMP_IMM(BPF_JEQ, R0, 10, 1), 1526 BPF_EXIT_INSN(), 1527 BPF_ALU64_IMM(BPF_MOD, R0, 3), 1528 BPF_JMP_IMM(BPF_JEQ, R0, 1, 1), 1529 BPF_EXIT_INSN(), 1530 BPF_ALU64_IMM(BPF_MOV, R0, -1), 1531 BPF_EXIT_INSN(), 1532 }, 1533 INTERNAL, 1534 { }, 1535 { { 0, -1 } } 1536 }, 1537 { 1538 "INT: shifts by register", 1539 .u.insns_int = { 1540 BPF_MOV64_IMM(R0, -1234), 1541 BPF_MOV64_IMM(R1, 1), 1542 BPF_ALU32_REG(BPF_RSH, R0, R1), 1543 BPF_JMP_IMM(BPF_JEQ, R0, 0x7ffffd97, 1), 1544 BPF_EXIT_INSN(), 1545 BPF_MOV64_IMM(R2, 1), 1546 BPF_ALU64_REG(BPF_LSH, R0, R2), 1547 BPF_MOV32_IMM(R4, -1234), 1548 BPF_JMP_REG(BPF_JEQ, R0, R4, 1), 1549 BPF_EXIT_INSN(), 1550 BPF_ALU64_IMM(BPF_AND, R4, 63), 1551 BPF_ALU64_REG(BPF_LSH, R0, R4), /* R0 <= 46 */ 1552 BPF_MOV64_IMM(R3, 47), 1553 BPF_ALU64_REG(BPF_ARSH, R0, R3), 1554 BPF_JMP_IMM(BPF_JEQ, R0, -617, 1), 1555 BPF_EXIT_INSN(), 1556 BPF_MOV64_IMM(R2, 1), 1557 BPF_ALU64_REG(BPF_LSH, R4, R2), /* R4 = 46 << 1 */ 1558 BPF_JMP_IMM(BPF_JEQ, R4, 92, 1), 1559 BPF_EXIT_INSN(), 1560 BPF_MOV64_IMM(R4, 4), 1561 BPF_ALU64_REG(BPF_LSH, R4, R4), /* R4 = 4 << 4 */ 1562 BPF_JMP_IMM(BPF_JEQ, R4, 64, 1), 1563 BPF_EXIT_INSN(), 1564 BPF_MOV64_IMM(R4, 5), 1565 BPF_ALU32_REG(BPF_LSH, R4, R4), /* R4 = 5 << 5 */ 1566 BPF_JMP_IMM(BPF_JEQ, R4, 160, 1), 1567 BPF_EXIT_INSN(), 1568 BPF_MOV64_IMM(R0, -1), 1569 BPF_EXIT_INSN(), 1570 }, 1571 INTERNAL, 1572 { }, 1573 { { 0, -1 } } 1574 }, 1575 { 1576 "INT: DIV + ABS", 1577 .u.insns_int = { 1578 BPF_ALU64_REG(BPF_MOV, R6, R1), 1579 BPF_LD_ABS(BPF_B, 3), 1580 BPF_ALU64_IMM(BPF_MOV, R2, 2), 1581 BPF_ALU32_REG(BPF_DIV, R0, R2), 1582 BPF_ALU64_REG(BPF_MOV, R8, R0), 1583 BPF_LD_ABS(BPF_B, 4), 1584 BPF_ALU64_REG(BPF_ADD, R8, R0), 1585 BPF_LD_IND(BPF_B, R8, -70), 1586 BPF_EXIT_INSN(), 1587 }, 1588 INTERNAL, 1589 { 10, 20, 30, 40, 50 }, 1590 { { 4, 0 }, { 5, 10 } } 1591 }, 1592 { 1593 "INT: DIV by zero", 1594 .u.insns_int = { 1595 BPF_ALU64_REG(BPF_MOV, R6, R1), 1596 BPF_ALU64_IMM(BPF_MOV, R7, 0), 1597 BPF_LD_ABS(BPF_B, 3), 1598 BPF_ALU32_REG(BPF_DIV, R0, R7), 1599 BPF_EXIT_INSN(), 1600 }, 1601 INTERNAL, 1602 { 10, 20, 30, 40, 50 }, 1603 { { 3, 0 }, { 4, 0 } } 1604 }, 1605 { 1606 "check: missing ret", 1607 .u.insns = { 1608 BPF_STMT(BPF_LD | BPF_IMM, 1), 1609 }, 1610 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1611 { }, 1612 { } 1613 }, 1614 { 1615 "check: div_k_0", 1616 .u.insns = { 1617 BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0), 1618 BPF_STMT(BPF_RET | BPF_K, 0) 1619 }, 1620 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1621 { }, 1622 { } 1623 }, 1624 { 1625 "check: unknown insn", 1626 .u.insns = { 1627 /* seccomp insn, rejected in socket filter */ 1628 BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0), 1629 BPF_STMT(BPF_RET | BPF_K, 0) 1630 }, 1631 CLASSIC | FLAG_EXPECTED_FAIL, 1632 { }, 1633 { } 1634 }, 1635 { 1636 "check: out of range spill/fill", 1637 .u.insns = { 1638 BPF_STMT(BPF_STX, 16), 1639 BPF_STMT(BPF_RET | BPF_K, 0) 1640 }, 1641 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1642 { }, 1643 { } 1644 }, 1645 { 1646 "JUMPS + HOLES", 1647 .u.insns = { 1648 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1649 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15), 1650 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1651 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1652 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1653 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1654 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1655 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1656 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1657 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1658 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1659 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1660 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1661 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1662 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1663 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4), 1664 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1665 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2), 1666 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1667 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15), 1668 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14), 1669 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1670 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1671 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1672 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1673 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1674 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1675 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1676 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1677 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1678 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1679 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1680 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1681 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1682 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3), 1683 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2), 1684 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1685 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15), 1686 BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14), 1687 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1688 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1689 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1690 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1691 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1692 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1693 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1694 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1695 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1696 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1697 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1698 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1699 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1700 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3), 1701 BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2), 1702 BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0), 1703 BPF_STMT(BPF_RET | BPF_A, 0), 1704 BPF_STMT(BPF_RET | BPF_A, 0), 1705 }, 1706 CLASSIC, 1707 { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8, 1708 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4, 1709 0x08, 0x00, 1710 0x45, 0x00, 0x00, 0x28, 0x00, 0x00, 1711 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */ 1712 0xc0, 0xa8, 0x33, 0x01, 1713 0xc0, 0xa8, 0x33, 0x02, 1714 0xbb, 0xb6, 1715 0xa9, 0xfa, 1716 0x00, 0x14, 0x00, 0x00, 1717 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1718 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1719 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1720 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1721 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1722 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1723 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 1724 0xcc, 0xcc, 0xcc, 0xcc }, 1725 { { 88, 0x001b } } 1726 }, 1727 { 1728 "check: RET X", 1729 .u.insns = { 1730 BPF_STMT(BPF_RET | BPF_X, 0), 1731 }, 1732 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1733 { }, 1734 { }, 1735 }, 1736 { 1737 "check: LDX + RET X", 1738 .u.insns = { 1739 BPF_STMT(BPF_LDX | BPF_IMM, 42), 1740 BPF_STMT(BPF_RET | BPF_X, 0), 1741 }, 1742 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1743 { }, 1744 { }, 1745 }, 1746 { /* Mainly checking JIT here. */ 1747 "M[]: alt STX + LDX", 1748 .u.insns = { 1749 BPF_STMT(BPF_LDX | BPF_IMM, 100), 1750 BPF_STMT(BPF_STX, 0), 1751 BPF_STMT(BPF_LDX | BPF_MEM, 0), 1752 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1753 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1754 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1755 BPF_STMT(BPF_STX, 1), 1756 BPF_STMT(BPF_LDX | BPF_MEM, 1), 1757 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1758 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1759 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1760 BPF_STMT(BPF_STX, 2), 1761 BPF_STMT(BPF_LDX | BPF_MEM, 2), 1762 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1763 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1764 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1765 BPF_STMT(BPF_STX, 3), 1766 BPF_STMT(BPF_LDX | BPF_MEM, 3), 1767 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1768 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1769 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1770 BPF_STMT(BPF_STX, 4), 1771 BPF_STMT(BPF_LDX | BPF_MEM, 4), 1772 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1773 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1774 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1775 BPF_STMT(BPF_STX, 5), 1776 BPF_STMT(BPF_LDX | BPF_MEM, 5), 1777 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1778 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1779 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1780 BPF_STMT(BPF_STX, 6), 1781 BPF_STMT(BPF_LDX | BPF_MEM, 6), 1782 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1783 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1784 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1785 BPF_STMT(BPF_STX, 7), 1786 BPF_STMT(BPF_LDX | BPF_MEM, 7), 1787 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1788 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1789 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1790 BPF_STMT(BPF_STX, 8), 1791 BPF_STMT(BPF_LDX | BPF_MEM, 8), 1792 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1793 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1794 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1795 BPF_STMT(BPF_STX, 9), 1796 BPF_STMT(BPF_LDX | BPF_MEM, 9), 1797 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1798 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1799 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1800 BPF_STMT(BPF_STX, 10), 1801 BPF_STMT(BPF_LDX | BPF_MEM, 10), 1802 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1803 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1804 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1805 BPF_STMT(BPF_STX, 11), 1806 BPF_STMT(BPF_LDX | BPF_MEM, 11), 1807 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1808 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1809 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1810 BPF_STMT(BPF_STX, 12), 1811 BPF_STMT(BPF_LDX | BPF_MEM, 12), 1812 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1813 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1814 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1815 BPF_STMT(BPF_STX, 13), 1816 BPF_STMT(BPF_LDX | BPF_MEM, 13), 1817 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1818 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1819 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1820 BPF_STMT(BPF_STX, 14), 1821 BPF_STMT(BPF_LDX | BPF_MEM, 14), 1822 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1823 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1824 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1825 BPF_STMT(BPF_STX, 15), 1826 BPF_STMT(BPF_LDX | BPF_MEM, 15), 1827 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1828 BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1), 1829 BPF_STMT(BPF_MISC | BPF_TAX, 0), 1830 BPF_STMT(BPF_RET | BPF_A, 0), 1831 }, 1832 CLASSIC | FLAG_NO_DATA, 1833 { }, 1834 { { 0, 116 } }, 1835 }, 1836 { /* Mainly checking JIT here. */ 1837 "M[]: full STX + full LDX", 1838 .u.insns = { 1839 BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb), 1840 BPF_STMT(BPF_STX, 0), 1841 BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae), 1842 BPF_STMT(BPF_STX, 1), 1843 BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf), 1844 BPF_STMT(BPF_STX, 2), 1845 BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc), 1846 BPF_STMT(BPF_STX, 3), 1847 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb), 1848 BPF_STMT(BPF_STX, 4), 1849 BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda), 1850 BPF_STMT(BPF_STX, 5), 1851 BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb), 1852 BPF_STMT(BPF_STX, 6), 1853 BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade), 1854 BPF_STMT(BPF_STX, 7), 1855 BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec), 1856 BPF_STMT(BPF_STX, 8), 1857 BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc), 1858 BPF_STMT(BPF_STX, 9), 1859 BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac), 1860 BPF_STMT(BPF_STX, 10), 1861 BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea), 1862 BPF_STMT(BPF_STX, 11), 1863 BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb), 1864 BPF_STMT(BPF_STX, 12), 1865 BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf), 1866 BPF_STMT(BPF_STX, 13), 1867 BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde), 1868 BPF_STMT(BPF_STX, 14), 1869 BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad), 1870 BPF_STMT(BPF_STX, 15), 1871 BPF_STMT(BPF_LDX | BPF_MEM, 0), 1872 BPF_STMT(BPF_MISC | BPF_TXA, 0), 1873 BPF_STMT(BPF_LDX | BPF_MEM, 1), 1874 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1875 BPF_STMT(BPF_LDX | BPF_MEM, 2), 1876 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1877 BPF_STMT(BPF_LDX | BPF_MEM, 3), 1878 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1879 BPF_STMT(BPF_LDX | BPF_MEM, 4), 1880 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1881 BPF_STMT(BPF_LDX | BPF_MEM, 5), 1882 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1883 BPF_STMT(BPF_LDX | BPF_MEM, 6), 1884 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1885 BPF_STMT(BPF_LDX | BPF_MEM, 7), 1886 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1887 BPF_STMT(BPF_LDX | BPF_MEM, 8), 1888 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1889 BPF_STMT(BPF_LDX | BPF_MEM, 9), 1890 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1891 BPF_STMT(BPF_LDX | BPF_MEM, 10), 1892 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1893 BPF_STMT(BPF_LDX | BPF_MEM, 11), 1894 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1895 BPF_STMT(BPF_LDX | BPF_MEM, 12), 1896 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1897 BPF_STMT(BPF_LDX | BPF_MEM, 13), 1898 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1899 BPF_STMT(BPF_LDX | BPF_MEM, 14), 1900 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1901 BPF_STMT(BPF_LDX | BPF_MEM, 15), 1902 BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), 1903 BPF_STMT(BPF_RET | BPF_A, 0), 1904 }, 1905 CLASSIC | FLAG_NO_DATA, 1906 { }, 1907 { { 0, 0x2a5a5e5 } }, 1908 }, 1909 { 1910 "check: SKF_AD_MAX", 1911 .u.insns = { 1912 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1913 SKF_AD_OFF + SKF_AD_MAX), 1914 BPF_STMT(BPF_RET | BPF_A, 0), 1915 }, 1916 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 1917 { }, 1918 { }, 1919 }, 1920 { /* Passes checker but fails during runtime. */ 1921 "LD [SKF_AD_OFF-1]", 1922 .u.insns = { 1923 BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1924 SKF_AD_OFF - 1), 1925 BPF_STMT(BPF_RET | BPF_K, 1), 1926 }, 1927 CLASSIC, 1928 { }, 1929 { { 1, 0 } }, 1930 }, 1931 { 1932 "load 64-bit immediate", 1933 .u.insns_int = { 1934 BPF_LD_IMM64(R1, 0x567800001234LL), 1935 BPF_MOV64_REG(R2, R1), 1936 BPF_MOV64_REG(R3, R2), 1937 BPF_ALU64_IMM(BPF_RSH, R2, 32), 1938 BPF_ALU64_IMM(BPF_LSH, R3, 32), 1939 BPF_ALU64_IMM(BPF_RSH, R3, 32), 1940 BPF_ALU64_IMM(BPF_MOV, R0, 0), 1941 BPF_JMP_IMM(BPF_JEQ, R2, 0x5678, 1), 1942 BPF_EXIT_INSN(), 1943 BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1), 1944 BPF_EXIT_INSN(), 1945 BPF_LD_IMM64(R0, 0x1ffffffffLL), 1946 BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */ 1947 BPF_EXIT_INSN(), 1948 }, 1949 INTERNAL, 1950 { }, 1951 { { 0, 1 } } 1952 }, 1953 { 1954 "nmap reduced", 1955 .u.insns_int = { 1956 BPF_MOV64_REG(R6, R1), 1957 BPF_LD_ABS(BPF_H, 12), 1958 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 28), 1959 BPF_LD_ABS(BPF_H, 12), 1960 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 26), 1961 BPF_MOV32_IMM(R0, 18), 1962 BPF_STX_MEM(BPF_W, R10, R0, -64), 1963 BPF_LDX_MEM(BPF_W, R7, R10, -64), 1964 BPF_LD_IND(BPF_W, R7, 14), 1965 BPF_STX_MEM(BPF_W, R10, R0, -60), 1966 BPF_MOV32_IMM(R0, 280971478), 1967 BPF_STX_MEM(BPF_W, R10, R0, -56), 1968 BPF_LDX_MEM(BPF_W, R7, R10, -56), 1969 BPF_LDX_MEM(BPF_W, R0, R10, -60), 1970 BPF_ALU32_REG(BPF_SUB, R0, R7), 1971 BPF_JMP_IMM(BPF_JNE, R0, 0, 15), 1972 BPF_LD_ABS(BPF_H, 12), 1973 BPF_JMP_IMM(BPF_JNE, R0, 0x806, 13), 1974 BPF_MOV32_IMM(R0, 22), 1975 BPF_STX_MEM(BPF_W, R10, R0, -56), 1976 BPF_LDX_MEM(BPF_W, R7, R10, -56), 1977 BPF_LD_IND(BPF_H, R7, 14), 1978 BPF_STX_MEM(BPF_W, R10, R0, -52), 1979 BPF_MOV32_IMM(R0, 17366), 1980 BPF_STX_MEM(BPF_W, R10, R0, -48), 1981 BPF_LDX_MEM(BPF_W, R7, R10, -48), 1982 BPF_LDX_MEM(BPF_W, R0, R10, -52), 1983 BPF_ALU32_REG(BPF_SUB, R0, R7), 1984 BPF_JMP_IMM(BPF_JNE, R0, 0, 2), 1985 BPF_MOV32_IMM(R0, 256), 1986 BPF_EXIT_INSN(), 1987 BPF_MOV32_IMM(R0, 0), 1988 BPF_EXIT_INSN(), 1989 }, 1990 INTERNAL, 1991 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x06, 0, 0, 1992 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1993 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6}, 1994 { { 38, 256 } } 1995 }, 1996 /* BPF_ALU | BPF_MOV | BPF_X */ 1997 { 1998 "ALU_MOV_X: dst = 2", 1999 .u.insns_int = { 2000 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2001 BPF_ALU32_REG(BPF_MOV, R0, R1), 2002 BPF_EXIT_INSN(), 2003 }, 2004 INTERNAL, 2005 { }, 2006 { { 0, 2 } }, 2007 }, 2008 { 2009 "ALU_MOV_X: dst = 4294967295", 2010 .u.insns_int = { 2011 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), 2012 BPF_ALU32_REG(BPF_MOV, R0, R1), 2013 BPF_EXIT_INSN(), 2014 }, 2015 INTERNAL, 2016 { }, 2017 { { 0, 4294967295U } }, 2018 }, 2019 { 2020 "ALU64_MOV_X: dst = 2", 2021 .u.insns_int = { 2022 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2023 BPF_ALU64_REG(BPF_MOV, R0, R1), 2024 BPF_EXIT_INSN(), 2025 }, 2026 INTERNAL, 2027 { }, 2028 { { 0, 2 } }, 2029 }, 2030 { 2031 "ALU64_MOV_X: dst = 4294967295", 2032 .u.insns_int = { 2033 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), 2034 BPF_ALU64_REG(BPF_MOV, R0, R1), 2035 BPF_EXIT_INSN(), 2036 }, 2037 INTERNAL, 2038 { }, 2039 { { 0, 4294967295U } }, 2040 }, 2041 /* BPF_ALU | BPF_MOV | BPF_K */ 2042 { 2043 "ALU_MOV_K: dst = 2", 2044 .u.insns_int = { 2045 BPF_ALU32_IMM(BPF_MOV, R0, 2), 2046 BPF_EXIT_INSN(), 2047 }, 2048 INTERNAL, 2049 { }, 2050 { { 0, 2 } }, 2051 }, 2052 { 2053 "ALU_MOV_K: dst = 4294967295", 2054 .u.insns_int = { 2055 BPF_ALU32_IMM(BPF_MOV, R0, 4294967295U), 2056 BPF_EXIT_INSN(), 2057 }, 2058 INTERNAL, 2059 { }, 2060 { { 0, 4294967295U } }, 2061 }, 2062 { 2063 "ALU_MOV_K: 0x0000ffffffff0000 = 0x00000000ffffffff", 2064 .u.insns_int = { 2065 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 2066 BPF_LD_IMM64(R3, 0x00000000ffffffffLL), 2067 BPF_ALU32_IMM(BPF_MOV, R2, 0xffffffff), 2068 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2069 BPF_MOV32_IMM(R0, 2), 2070 BPF_EXIT_INSN(), 2071 BPF_MOV32_IMM(R0, 1), 2072 BPF_EXIT_INSN(), 2073 }, 2074 INTERNAL, 2075 { }, 2076 { { 0, 0x1 } }, 2077 }, 2078 { 2079 "ALU64_MOV_K: dst = 2", 2080 .u.insns_int = { 2081 BPF_ALU64_IMM(BPF_MOV, R0, 2), 2082 BPF_EXIT_INSN(), 2083 }, 2084 INTERNAL, 2085 { }, 2086 { { 0, 2 } }, 2087 }, 2088 { 2089 "ALU64_MOV_K: dst = 2147483647", 2090 .u.insns_int = { 2091 BPF_ALU64_IMM(BPF_MOV, R0, 2147483647), 2092 BPF_EXIT_INSN(), 2093 }, 2094 INTERNAL, 2095 { }, 2096 { { 0, 2147483647 } }, 2097 }, 2098 { 2099 "ALU64_OR_K: dst = 0x0", 2100 .u.insns_int = { 2101 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 2102 BPF_LD_IMM64(R3, 0x0), 2103 BPF_ALU64_IMM(BPF_MOV, R2, 0x0), 2104 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2105 BPF_MOV32_IMM(R0, 2), 2106 BPF_EXIT_INSN(), 2107 BPF_MOV32_IMM(R0, 1), 2108 BPF_EXIT_INSN(), 2109 }, 2110 INTERNAL, 2111 { }, 2112 { { 0, 0x1 } }, 2113 }, 2114 { 2115 "ALU64_MOV_K: dst = -1", 2116 .u.insns_int = { 2117 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 2118 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 2119 BPF_ALU64_IMM(BPF_MOV, R2, 0xffffffff), 2120 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2121 BPF_MOV32_IMM(R0, 2), 2122 BPF_EXIT_INSN(), 2123 BPF_MOV32_IMM(R0, 1), 2124 BPF_EXIT_INSN(), 2125 }, 2126 INTERNAL, 2127 { }, 2128 { { 0, 0x1 } }, 2129 }, 2130 /* BPF_ALU | BPF_ADD | BPF_X */ 2131 { 2132 "ALU_ADD_X: 1 + 2 = 3", 2133 .u.insns_int = { 2134 BPF_LD_IMM64(R0, 1), 2135 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2136 BPF_ALU32_REG(BPF_ADD, R0, R1), 2137 BPF_EXIT_INSN(), 2138 }, 2139 INTERNAL, 2140 { }, 2141 { { 0, 3 } }, 2142 }, 2143 { 2144 "ALU_ADD_X: 1 + 4294967294 = 4294967295", 2145 .u.insns_int = { 2146 BPF_LD_IMM64(R0, 1), 2147 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), 2148 BPF_ALU32_REG(BPF_ADD, R0, R1), 2149 BPF_EXIT_INSN(), 2150 }, 2151 INTERNAL, 2152 { }, 2153 { { 0, 4294967295U } }, 2154 }, 2155 { 2156 "ALU64_ADD_X: 1 + 2 = 3", 2157 .u.insns_int = { 2158 BPF_LD_IMM64(R0, 1), 2159 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2160 BPF_ALU64_REG(BPF_ADD, R0, R1), 2161 BPF_EXIT_INSN(), 2162 }, 2163 INTERNAL, 2164 { }, 2165 { { 0, 3 } }, 2166 }, 2167 { 2168 "ALU64_ADD_X: 1 + 4294967294 = 4294967295", 2169 .u.insns_int = { 2170 BPF_LD_IMM64(R0, 1), 2171 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), 2172 BPF_ALU64_REG(BPF_ADD, R0, R1), 2173 BPF_EXIT_INSN(), 2174 }, 2175 INTERNAL, 2176 { }, 2177 { { 0, 4294967295U } }, 2178 }, 2179 /* BPF_ALU | BPF_ADD | BPF_K */ 2180 { 2181 "ALU_ADD_K: 1 + 2 = 3", 2182 .u.insns_int = { 2183 BPF_LD_IMM64(R0, 1), 2184 BPF_ALU32_IMM(BPF_ADD, R0, 2), 2185 BPF_EXIT_INSN(), 2186 }, 2187 INTERNAL, 2188 { }, 2189 { { 0, 3 } }, 2190 }, 2191 { 2192 "ALU_ADD_K: 3 + 0 = 3", 2193 .u.insns_int = { 2194 BPF_LD_IMM64(R0, 3), 2195 BPF_ALU32_IMM(BPF_ADD, R0, 0), 2196 BPF_EXIT_INSN(), 2197 }, 2198 INTERNAL, 2199 { }, 2200 { { 0, 3 } }, 2201 }, 2202 { 2203 "ALU_ADD_K: 1 + 4294967294 = 4294967295", 2204 .u.insns_int = { 2205 BPF_LD_IMM64(R0, 1), 2206 BPF_ALU32_IMM(BPF_ADD, R0, 4294967294U), 2207 BPF_EXIT_INSN(), 2208 }, 2209 INTERNAL, 2210 { }, 2211 { { 0, 4294967295U } }, 2212 }, 2213 { 2214 "ALU_ADD_K: 0 + (-1) = 0x00000000ffffffff", 2215 .u.insns_int = { 2216 BPF_LD_IMM64(R2, 0x0), 2217 BPF_LD_IMM64(R3, 0x00000000ffffffff), 2218 BPF_ALU32_IMM(BPF_ADD, R2, 0xffffffff), 2219 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2220 BPF_MOV32_IMM(R0, 2), 2221 BPF_EXIT_INSN(), 2222 BPF_MOV32_IMM(R0, 1), 2223 BPF_EXIT_INSN(), 2224 }, 2225 INTERNAL, 2226 { }, 2227 { { 0, 0x1 } }, 2228 }, 2229 { 2230 "ALU64_ADD_K: 1 + 2 = 3", 2231 .u.insns_int = { 2232 BPF_LD_IMM64(R0, 1), 2233 BPF_ALU64_IMM(BPF_ADD, R0, 2), 2234 BPF_EXIT_INSN(), 2235 }, 2236 INTERNAL, 2237 { }, 2238 { { 0, 3 } }, 2239 }, 2240 { 2241 "ALU64_ADD_K: 3 + 0 = 3", 2242 .u.insns_int = { 2243 BPF_LD_IMM64(R0, 3), 2244 BPF_ALU64_IMM(BPF_ADD, R0, 0), 2245 BPF_EXIT_INSN(), 2246 }, 2247 INTERNAL, 2248 { }, 2249 { { 0, 3 } }, 2250 }, 2251 { 2252 "ALU64_ADD_K: 1 + 2147483646 = 2147483647", 2253 .u.insns_int = { 2254 BPF_LD_IMM64(R0, 1), 2255 BPF_ALU64_IMM(BPF_ADD, R0, 2147483646), 2256 BPF_EXIT_INSN(), 2257 }, 2258 INTERNAL, 2259 { }, 2260 { { 0, 2147483647 } }, 2261 }, 2262 { 2263 "ALU64_ADD_K: 2147483646 + -2147483647 = -1", 2264 .u.insns_int = { 2265 BPF_LD_IMM64(R0, 2147483646), 2266 BPF_ALU64_IMM(BPF_ADD, R0, -2147483647), 2267 BPF_EXIT_INSN(), 2268 }, 2269 INTERNAL, 2270 { }, 2271 { { 0, -1 } }, 2272 }, 2273 { 2274 "ALU64_ADD_K: 1 + 0 = 1", 2275 .u.insns_int = { 2276 BPF_LD_IMM64(R2, 0x1), 2277 BPF_LD_IMM64(R3, 0x1), 2278 BPF_ALU64_IMM(BPF_ADD, R2, 0x0), 2279 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2280 BPF_MOV32_IMM(R0, 2), 2281 BPF_EXIT_INSN(), 2282 BPF_MOV32_IMM(R0, 1), 2283 BPF_EXIT_INSN(), 2284 }, 2285 INTERNAL, 2286 { }, 2287 { { 0, 0x1 } }, 2288 }, 2289 { 2290 "ALU64_ADD_K: 0 + (-1) = 0xffffffffffffffff", 2291 .u.insns_int = { 2292 BPF_LD_IMM64(R2, 0x0), 2293 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 2294 BPF_ALU64_IMM(BPF_ADD, R2, 0xffffffff), 2295 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2296 BPF_MOV32_IMM(R0, 2), 2297 BPF_EXIT_INSN(), 2298 BPF_MOV32_IMM(R0, 1), 2299 BPF_EXIT_INSN(), 2300 }, 2301 INTERNAL, 2302 { }, 2303 { { 0, 0x1 } }, 2304 }, 2305 /* BPF_ALU | BPF_SUB | BPF_X */ 2306 { 2307 "ALU_SUB_X: 3 - 1 = 2", 2308 .u.insns_int = { 2309 BPF_LD_IMM64(R0, 3), 2310 BPF_ALU32_IMM(BPF_MOV, R1, 1), 2311 BPF_ALU32_REG(BPF_SUB, R0, R1), 2312 BPF_EXIT_INSN(), 2313 }, 2314 INTERNAL, 2315 { }, 2316 { { 0, 2 } }, 2317 }, 2318 { 2319 "ALU_SUB_X: 4294967295 - 4294967294 = 1", 2320 .u.insns_int = { 2321 BPF_LD_IMM64(R0, 4294967295U), 2322 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), 2323 BPF_ALU32_REG(BPF_SUB, R0, R1), 2324 BPF_EXIT_INSN(), 2325 }, 2326 INTERNAL, 2327 { }, 2328 { { 0, 1 } }, 2329 }, 2330 { 2331 "ALU64_SUB_X: 3 - 1 = 2", 2332 .u.insns_int = { 2333 BPF_LD_IMM64(R0, 3), 2334 BPF_ALU32_IMM(BPF_MOV, R1, 1), 2335 BPF_ALU64_REG(BPF_SUB, R0, R1), 2336 BPF_EXIT_INSN(), 2337 }, 2338 INTERNAL, 2339 { }, 2340 { { 0, 2 } }, 2341 }, 2342 { 2343 "ALU64_SUB_X: 4294967295 - 4294967294 = 1", 2344 .u.insns_int = { 2345 BPF_LD_IMM64(R0, 4294967295U), 2346 BPF_ALU32_IMM(BPF_MOV, R1, 4294967294U), 2347 BPF_ALU64_REG(BPF_SUB, R0, R1), 2348 BPF_EXIT_INSN(), 2349 }, 2350 INTERNAL, 2351 { }, 2352 { { 0, 1 } }, 2353 }, 2354 /* BPF_ALU | BPF_SUB | BPF_K */ 2355 { 2356 "ALU_SUB_K: 3 - 1 = 2", 2357 .u.insns_int = { 2358 BPF_LD_IMM64(R0, 3), 2359 BPF_ALU32_IMM(BPF_SUB, R0, 1), 2360 BPF_EXIT_INSN(), 2361 }, 2362 INTERNAL, 2363 { }, 2364 { { 0, 2 } }, 2365 }, 2366 { 2367 "ALU_SUB_K: 3 - 0 = 3", 2368 .u.insns_int = { 2369 BPF_LD_IMM64(R0, 3), 2370 BPF_ALU32_IMM(BPF_SUB, R0, 0), 2371 BPF_EXIT_INSN(), 2372 }, 2373 INTERNAL, 2374 { }, 2375 { { 0, 3 } }, 2376 }, 2377 { 2378 "ALU_SUB_K: 4294967295 - 4294967294 = 1", 2379 .u.insns_int = { 2380 BPF_LD_IMM64(R0, 4294967295U), 2381 BPF_ALU32_IMM(BPF_SUB, R0, 4294967294U), 2382 BPF_EXIT_INSN(), 2383 }, 2384 INTERNAL, 2385 { }, 2386 { { 0, 1 } }, 2387 }, 2388 { 2389 "ALU64_SUB_K: 3 - 1 = 2", 2390 .u.insns_int = { 2391 BPF_LD_IMM64(R0, 3), 2392 BPF_ALU64_IMM(BPF_SUB, R0, 1), 2393 BPF_EXIT_INSN(), 2394 }, 2395 INTERNAL, 2396 { }, 2397 { { 0, 2 } }, 2398 }, 2399 { 2400 "ALU64_SUB_K: 3 - 0 = 3", 2401 .u.insns_int = { 2402 BPF_LD_IMM64(R0, 3), 2403 BPF_ALU64_IMM(BPF_SUB, R0, 0), 2404 BPF_EXIT_INSN(), 2405 }, 2406 INTERNAL, 2407 { }, 2408 { { 0, 3 } }, 2409 }, 2410 { 2411 "ALU64_SUB_K: 4294967294 - 4294967295 = -1", 2412 .u.insns_int = { 2413 BPF_LD_IMM64(R0, 4294967294U), 2414 BPF_ALU64_IMM(BPF_SUB, R0, 4294967295U), 2415 BPF_EXIT_INSN(), 2416 }, 2417 INTERNAL, 2418 { }, 2419 { { 0, -1 } }, 2420 }, 2421 { 2422 "ALU64_ADD_K: 2147483646 - 2147483647 = -1", 2423 .u.insns_int = { 2424 BPF_LD_IMM64(R0, 2147483646), 2425 BPF_ALU64_IMM(BPF_SUB, R0, 2147483647), 2426 BPF_EXIT_INSN(), 2427 }, 2428 INTERNAL, 2429 { }, 2430 { { 0, -1 } }, 2431 }, 2432 /* BPF_ALU | BPF_MUL | BPF_X */ 2433 { 2434 "ALU_MUL_X: 2 * 3 = 6", 2435 .u.insns_int = { 2436 BPF_LD_IMM64(R0, 2), 2437 BPF_ALU32_IMM(BPF_MOV, R1, 3), 2438 BPF_ALU32_REG(BPF_MUL, R0, R1), 2439 BPF_EXIT_INSN(), 2440 }, 2441 INTERNAL, 2442 { }, 2443 { { 0, 6 } }, 2444 }, 2445 { 2446 "ALU_MUL_X: 2 * 0x7FFFFFF8 = 0xFFFFFFF0", 2447 .u.insns_int = { 2448 BPF_LD_IMM64(R0, 2), 2449 BPF_ALU32_IMM(BPF_MOV, R1, 0x7FFFFFF8), 2450 BPF_ALU32_REG(BPF_MUL, R0, R1), 2451 BPF_EXIT_INSN(), 2452 }, 2453 INTERNAL, 2454 { }, 2455 { { 0, 0xFFFFFFF0 } }, 2456 }, 2457 { 2458 "ALU_MUL_X: -1 * -1 = 1", 2459 .u.insns_int = { 2460 BPF_LD_IMM64(R0, -1), 2461 BPF_ALU32_IMM(BPF_MOV, R1, -1), 2462 BPF_ALU32_REG(BPF_MUL, R0, R1), 2463 BPF_EXIT_INSN(), 2464 }, 2465 INTERNAL, 2466 { }, 2467 { { 0, 1 } }, 2468 }, 2469 { 2470 "ALU64_MUL_X: 2 * 3 = 6", 2471 .u.insns_int = { 2472 BPF_LD_IMM64(R0, 2), 2473 BPF_ALU32_IMM(BPF_MOV, R1, 3), 2474 BPF_ALU64_REG(BPF_MUL, R0, R1), 2475 BPF_EXIT_INSN(), 2476 }, 2477 INTERNAL, 2478 { }, 2479 { { 0, 6 } }, 2480 }, 2481 { 2482 "ALU64_MUL_X: 1 * 2147483647 = 2147483647", 2483 .u.insns_int = { 2484 BPF_LD_IMM64(R0, 1), 2485 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647), 2486 BPF_ALU64_REG(BPF_MUL, R0, R1), 2487 BPF_EXIT_INSN(), 2488 }, 2489 INTERNAL, 2490 { }, 2491 { { 0, 2147483647 } }, 2492 }, 2493 /* BPF_ALU | BPF_MUL | BPF_K */ 2494 { 2495 "ALU_MUL_K: 2 * 3 = 6", 2496 .u.insns_int = { 2497 BPF_LD_IMM64(R0, 2), 2498 BPF_ALU32_IMM(BPF_MUL, R0, 3), 2499 BPF_EXIT_INSN(), 2500 }, 2501 INTERNAL, 2502 { }, 2503 { { 0, 6 } }, 2504 }, 2505 { 2506 "ALU_MUL_K: 3 * 1 = 3", 2507 .u.insns_int = { 2508 BPF_LD_IMM64(R0, 3), 2509 BPF_ALU32_IMM(BPF_MUL, R0, 1), 2510 BPF_EXIT_INSN(), 2511 }, 2512 INTERNAL, 2513 { }, 2514 { { 0, 3 } }, 2515 }, 2516 { 2517 "ALU_MUL_K: 2 * 0x7FFFFFF8 = 0xFFFFFFF0", 2518 .u.insns_int = { 2519 BPF_LD_IMM64(R0, 2), 2520 BPF_ALU32_IMM(BPF_MUL, R0, 0x7FFFFFF8), 2521 BPF_EXIT_INSN(), 2522 }, 2523 INTERNAL, 2524 { }, 2525 { { 0, 0xFFFFFFF0 } }, 2526 }, 2527 { 2528 "ALU_MUL_K: 1 * (-1) = 0x00000000ffffffff", 2529 .u.insns_int = { 2530 BPF_LD_IMM64(R2, 0x1), 2531 BPF_LD_IMM64(R3, 0x00000000ffffffff), 2532 BPF_ALU32_IMM(BPF_MUL, R2, 0xffffffff), 2533 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2534 BPF_MOV32_IMM(R0, 2), 2535 BPF_EXIT_INSN(), 2536 BPF_MOV32_IMM(R0, 1), 2537 BPF_EXIT_INSN(), 2538 }, 2539 INTERNAL, 2540 { }, 2541 { { 0, 0x1 } }, 2542 }, 2543 { 2544 "ALU64_MUL_K: 2 * 3 = 6", 2545 .u.insns_int = { 2546 BPF_LD_IMM64(R0, 2), 2547 BPF_ALU64_IMM(BPF_MUL, R0, 3), 2548 BPF_EXIT_INSN(), 2549 }, 2550 INTERNAL, 2551 { }, 2552 { { 0, 6 } }, 2553 }, 2554 { 2555 "ALU64_MUL_K: 3 * 1 = 3", 2556 .u.insns_int = { 2557 BPF_LD_IMM64(R0, 3), 2558 BPF_ALU64_IMM(BPF_MUL, R0, 1), 2559 BPF_EXIT_INSN(), 2560 }, 2561 INTERNAL, 2562 { }, 2563 { { 0, 3 } }, 2564 }, 2565 { 2566 "ALU64_MUL_K: 1 * 2147483647 = 2147483647", 2567 .u.insns_int = { 2568 BPF_LD_IMM64(R0, 1), 2569 BPF_ALU64_IMM(BPF_MUL, R0, 2147483647), 2570 BPF_EXIT_INSN(), 2571 }, 2572 INTERNAL, 2573 { }, 2574 { { 0, 2147483647 } }, 2575 }, 2576 { 2577 "ALU64_MUL_K: 1 * -2147483647 = -2147483647", 2578 .u.insns_int = { 2579 BPF_LD_IMM64(R0, 1), 2580 BPF_ALU64_IMM(BPF_MUL, R0, -2147483647), 2581 BPF_EXIT_INSN(), 2582 }, 2583 INTERNAL, 2584 { }, 2585 { { 0, -2147483647 } }, 2586 }, 2587 { 2588 "ALU64_MUL_K: 1 * (-1) = 0xffffffffffffffff", 2589 .u.insns_int = { 2590 BPF_LD_IMM64(R2, 0x1), 2591 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 2592 BPF_ALU64_IMM(BPF_MUL, R2, 0xffffffff), 2593 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2594 BPF_MOV32_IMM(R0, 2), 2595 BPF_EXIT_INSN(), 2596 BPF_MOV32_IMM(R0, 1), 2597 BPF_EXIT_INSN(), 2598 }, 2599 INTERNAL, 2600 { }, 2601 { { 0, 0x1 } }, 2602 }, 2603 /* BPF_ALU | BPF_DIV | BPF_X */ 2604 { 2605 "ALU_DIV_X: 6 / 2 = 3", 2606 .u.insns_int = { 2607 BPF_LD_IMM64(R0, 6), 2608 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2609 BPF_ALU32_REG(BPF_DIV, R0, R1), 2610 BPF_EXIT_INSN(), 2611 }, 2612 INTERNAL, 2613 { }, 2614 { { 0, 3 } }, 2615 }, 2616 { 2617 "ALU_DIV_X: 4294967295 / 4294967295 = 1", 2618 .u.insns_int = { 2619 BPF_LD_IMM64(R0, 4294967295U), 2620 BPF_ALU32_IMM(BPF_MOV, R1, 4294967295U), 2621 BPF_ALU32_REG(BPF_DIV, R0, R1), 2622 BPF_EXIT_INSN(), 2623 }, 2624 INTERNAL, 2625 { }, 2626 { { 0, 1 } }, 2627 }, 2628 { 2629 "ALU64_DIV_X: 6 / 2 = 3", 2630 .u.insns_int = { 2631 BPF_LD_IMM64(R0, 6), 2632 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2633 BPF_ALU64_REG(BPF_DIV, R0, R1), 2634 BPF_EXIT_INSN(), 2635 }, 2636 INTERNAL, 2637 { }, 2638 { { 0, 3 } }, 2639 }, 2640 { 2641 "ALU64_DIV_X: 2147483647 / 2147483647 = 1", 2642 .u.insns_int = { 2643 BPF_LD_IMM64(R0, 2147483647), 2644 BPF_ALU32_IMM(BPF_MOV, R1, 2147483647), 2645 BPF_ALU64_REG(BPF_DIV, R0, R1), 2646 BPF_EXIT_INSN(), 2647 }, 2648 INTERNAL, 2649 { }, 2650 { { 0, 1 } }, 2651 }, 2652 { 2653 "ALU64_DIV_X: 0xffffffffffffffff / (-1) = 0x0000000000000001", 2654 .u.insns_int = { 2655 BPF_LD_IMM64(R2, 0xffffffffffffffffLL), 2656 BPF_LD_IMM64(R4, 0xffffffffffffffffLL), 2657 BPF_LD_IMM64(R3, 0x0000000000000001LL), 2658 BPF_ALU64_REG(BPF_DIV, R2, R4), 2659 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2660 BPF_MOV32_IMM(R0, 2), 2661 BPF_EXIT_INSN(), 2662 BPF_MOV32_IMM(R0, 1), 2663 BPF_EXIT_INSN(), 2664 }, 2665 INTERNAL, 2666 { }, 2667 { { 0, 0x1 } }, 2668 }, 2669 /* BPF_ALU | BPF_DIV | BPF_K */ 2670 { 2671 "ALU_DIV_K: 6 / 2 = 3", 2672 .u.insns_int = { 2673 BPF_LD_IMM64(R0, 6), 2674 BPF_ALU32_IMM(BPF_DIV, R0, 2), 2675 BPF_EXIT_INSN(), 2676 }, 2677 INTERNAL, 2678 { }, 2679 { { 0, 3 } }, 2680 }, 2681 { 2682 "ALU_DIV_K: 3 / 1 = 3", 2683 .u.insns_int = { 2684 BPF_LD_IMM64(R0, 3), 2685 BPF_ALU32_IMM(BPF_DIV, R0, 1), 2686 BPF_EXIT_INSN(), 2687 }, 2688 INTERNAL, 2689 { }, 2690 { { 0, 3 } }, 2691 }, 2692 { 2693 "ALU_DIV_K: 4294967295 / 4294967295 = 1", 2694 .u.insns_int = { 2695 BPF_LD_IMM64(R0, 4294967295U), 2696 BPF_ALU32_IMM(BPF_DIV, R0, 4294967295U), 2697 BPF_EXIT_INSN(), 2698 }, 2699 INTERNAL, 2700 { }, 2701 { { 0, 1 } }, 2702 }, 2703 { 2704 "ALU_DIV_K: 0xffffffffffffffff / (-1) = 0x1", 2705 .u.insns_int = { 2706 BPF_LD_IMM64(R2, 0xffffffffffffffffLL), 2707 BPF_LD_IMM64(R3, 0x1UL), 2708 BPF_ALU32_IMM(BPF_DIV, R2, 0xffffffff), 2709 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2710 BPF_MOV32_IMM(R0, 2), 2711 BPF_EXIT_INSN(), 2712 BPF_MOV32_IMM(R0, 1), 2713 BPF_EXIT_INSN(), 2714 }, 2715 INTERNAL, 2716 { }, 2717 { { 0, 0x1 } }, 2718 }, 2719 { 2720 "ALU64_DIV_K: 6 / 2 = 3", 2721 .u.insns_int = { 2722 BPF_LD_IMM64(R0, 6), 2723 BPF_ALU64_IMM(BPF_DIV, R0, 2), 2724 BPF_EXIT_INSN(), 2725 }, 2726 INTERNAL, 2727 { }, 2728 { { 0, 3 } }, 2729 }, 2730 { 2731 "ALU64_DIV_K: 3 / 1 = 3", 2732 .u.insns_int = { 2733 BPF_LD_IMM64(R0, 3), 2734 BPF_ALU64_IMM(BPF_DIV, R0, 1), 2735 BPF_EXIT_INSN(), 2736 }, 2737 INTERNAL, 2738 { }, 2739 { { 0, 3 } }, 2740 }, 2741 { 2742 "ALU64_DIV_K: 2147483647 / 2147483647 = 1", 2743 .u.insns_int = { 2744 BPF_LD_IMM64(R0, 2147483647), 2745 BPF_ALU64_IMM(BPF_DIV, R0, 2147483647), 2746 BPF_EXIT_INSN(), 2747 }, 2748 INTERNAL, 2749 { }, 2750 { { 0, 1 } }, 2751 }, 2752 { 2753 "ALU64_DIV_K: 0xffffffffffffffff / (-1) = 0x0000000000000001", 2754 .u.insns_int = { 2755 BPF_LD_IMM64(R2, 0xffffffffffffffffLL), 2756 BPF_LD_IMM64(R3, 0x0000000000000001LL), 2757 BPF_ALU64_IMM(BPF_DIV, R2, 0xffffffff), 2758 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2759 BPF_MOV32_IMM(R0, 2), 2760 BPF_EXIT_INSN(), 2761 BPF_MOV32_IMM(R0, 1), 2762 BPF_EXIT_INSN(), 2763 }, 2764 INTERNAL, 2765 { }, 2766 { { 0, 0x1 } }, 2767 }, 2768 /* BPF_ALU | BPF_MOD | BPF_X */ 2769 { 2770 "ALU_MOD_X: 3 % 2 = 1", 2771 .u.insns_int = { 2772 BPF_LD_IMM64(R0, 3), 2773 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2774 BPF_ALU32_REG(BPF_MOD, R0, R1), 2775 BPF_EXIT_INSN(), 2776 }, 2777 INTERNAL, 2778 { }, 2779 { { 0, 1 } }, 2780 }, 2781 { 2782 "ALU_MOD_X: 4294967295 % 4294967293 = 2", 2783 .u.insns_int = { 2784 BPF_LD_IMM64(R0, 4294967295U), 2785 BPF_ALU32_IMM(BPF_MOV, R1, 4294967293U), 2786 BPF_ALU32_REG(BPF_MOD, R0, R1), 2787 BPF_EXIT_INSN(), 2788 }, 2789 INTERNAL, 2790 { }, 2791 { { 0, 2 } }, 2792 }, 2793 { 2794 "ALU64_MOD_X: 3 % 2 = 1", 2795 .u.insns_int = { 2796 BPF_LD_IMM64(R0, 3), 2797 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2798 BPF_ALU64_REG(BPF_MOD, R0, R1), 2799 BPF_EXIT_INSN(), 2800 }, 2801 INTERNAL, 2802 { }, 2803 { { 0, 1 } }, 2804 }, 2805 { 2806 "ALU64_MOD_X: 2147483647 % 2147483645 = 2", 2807 .u.insns_int = { 2808 BPF_LD_IMM64(R0, 2147483647), 2809 BPF_ALU32_IMM(BPF_MOV, R1, 2147483645), 2810 BPF_ALU64_REG(BPF_MOD, R0, R1), 2811 BPF_EXIT_INSN(), 2812 }, 2813 INTERNAL, 2814 { }, 2815 { { 0, 2 } }, 2816 }, 2817 /* BPF_ALU | BPF_MOD | BPF_K */ 2818 { 2819 "ALU_MOD_K: 3 % 2 = 1", 2820 .u.insns_int = { 2821 BPF_LD_IMM64(R0, 3), 2822 BPF_ALU32_IMM(BPF_MOD, R0, 2), 2823 BPF_EXIT_INSN(), 2824 }, 2825 INTERNAL, 2826 { }, 2827 { { 0, 1 } }, 2828 }, 2829 { 2830 "ALU_MOD_K: 3 % 1 = 0", 2831 .u.insns_int = { 2832 BPF_LD_IMM64(R0, 3), 2833 BPF_ALU32_IMM(BPF_MOD, R0, 1), 2834 BPF_EXIT_INSN(), 2835 }, 2836 INTERNAL, 2837 { }, 2838 { { 0, 0 } }, 2839 }, 2840 { 2841 "ALU_MOD_K: 4294967295 % 4294967293 = 2", 2842 .u.insns_int = { 2843 BPF_LD_IMM64(R0, 4294967295U), 2844 BPF_ALU32_IMM(BPF_MOD, R0, 4294967293U), 2845 BPF_EXIT_INSN(), 2846 }, 2847 INTERNAL, 2848 { }, 2849 { { 0, 2 } }, 2850 }, 2851 { 2852 "ALU64_MOD_K: 3 % 2 = 1", 2853 .u.insns_int = { 2854 BPF_LD_IMM64(R0, 3), 2855 BPF_ALU64_IMM(BPF_MOD, R0, 2), 2856 BPF_EXIT_INSN(), 2857 }, 2858 INTERNAL, 2859 { }, 2860 { { 0, 1 } }, 2861 }, 2862 { 2863 "ALU64_MOD_K: 3 % 1 = 0", 2864 .u.insns_int = { 2865 BPF_LD_IMM64(R0, 3), 2866 BPF_ALU64_IMM(BPF_MOD, R0, 1), 2867 BPF_EXIT_INSN(), 2868 }, 2869 INTERNAL, 2870 { }, 2871 { { 0, 0 } }, 2872 }, 2873 { 2874 "ALU64_MOD_K: 2147483647 % 2147483645 = 2", 2875 .u.insns_int = { 2876 BPF_LD_IMM64(R0, 2147483647), 2877 BPF_ALU64_IMM(BPF_MOD, R0, 2147483645), 2878 BPF_EXIT_INSN(), 2879 }, 2880 INTERNAL, 2881 { }, 2882 { { 0, 2 } }, 2883 }, 2884 /* BPF_ALU | BPF_AND | BPF_X */ 2885 { 2886 "ALU_AND_X: 3 & 2 = 2", 2887 .u.insns_int = { 2888 BPF_LD_IMM64(R0, 3), 2889 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2890 BPF_ALU32_REG(BPF_AND, R0, R1), 2891 BPF_EXIT_INSN(), 2892 }, 2893 INTERNAL, 2894 { }, 2895 { { 0, 2 } }, 2896 }, 2897 { 2898 "ALU_AND_X: 0xffffffff & 0xffffffff = 0xffffffff", 2899 .u.insns_int = { 2900 BPF_LD_IMM64(R0, 0xffffffff), 2901 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 2902 BPF_ALU32_REG(BPF_AND, R0, R1), 2903 BPF_EXIT_INSN(), 2904 }, 2905 INTERNAL, 2906 { }, 2907 { { 0, 0xffffffff } }, 2908 }, 2909 { 2910 "ALU64_AND_X: 3 & 2 = 2", 2911 .u.insns_int = { 2912 BPF_LD_IMM64(R0, 3), 2913 BPF_ALU32_IMM(BPF_MOV, R1, 2), 2914 BPF_ALU64_REG(BPF_AND, R0, R1), 2915 BPF_EXIT_INSN(), 2916 }, 2917 INTERNAL, 2918 { }, 2919 { { 0, 2 } }, 2920 }, 2921 { 2922 "ALU64_AND_X: 0xffffffff & 0xffffffff = 0xffffffff", 2923 .u.insns_int = { 2924 BPF_LD_IMM64(R0, 0xffffffff), 2925 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 2926 BPF_ALU64_REG(BPF_AND, R0, R1), 2927 BPF_EXIT_INSN(), 2928 }, 2929 INTERNAL, 2930 { }, 2931 { { 0, 0xffffffff } }, 2932 }, 2933 /* BPF_ALU | BPF_AND | BPF_K */ 2934 { 2935 "ALU_AND_K: 3 & 2 = 2", 2936 .u.insns_int = { 2937 BPF_LD_IMM64(R0, 3), 2938 BPF_ALU32_IMM(BPF_AND, R0, 2), 2939 BPF_EXIT_INSN(), 2940 }, 2941 INTERNAL, 2942 { }, 2943 { { 0, 2 } }, 2944 }, 2945 { 2946 "ALU_AND_K: 0xffffffff & 0xffffffff = 0xffffffff", 2947 .u.insns_int = { 2948 BPF_LD_IMM64(R0, 0xffffffff), 2949 BPF_ALU32_IMM(BPF_AND, R0, 0xffffffff), 2950 BPF_EXIT_INSN(), 2951 }, 2952 INTERNAL, 2953 { }, 2954 { { 0, 0xffffffff } }, 2955 }, 2956 { 2957 "ALU64_AND_K: 3 & 2 = 2", 2958 .u.insns_int = { 2959 BPF_LD_IMM64(R0, 3), 2960 BPF_ALU64_IMM(BPF_AND, R0, 2), 2961 BPF_EXIT_INSN(), 2962 }, 2963 INTERNAL, 2964 { }, 2965 { { 0, 2 } }, 2966 }, 2967 { 2968 "ALU64_AND_K: 0xffffffff & 0xffffffff = 0xffffffff", 2969 .u.insns_int = { 2970 BPF_LD_IMM64(R0, 0xffffffff), 2971 BPF_ALU64_IMM(BPF_AND, R0, 0xffffffff), 2972 BPF_EXIT_INSN(), 2973 }, 2974 INTERNAL, 2975 { }, 2976 { { 0, 0xffffffff } }, 2977 }, 2978 { 2979 "ALU64_AND_K: 0x0000ffffffff0000 & 0x0 = 0x0000ffff00000000", 2980 .u.insns_int = { 2981 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 2982 BPF_LD_IMM64(R3, 0x0000000000000000LL), 2983 BPF_ALU64_IMM(BPF_AND, R2, 0x0), 2984 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 2985 BPF_MOV32_IMM(R0, 2), 2986 BPF_EXIT_INSN(), 2987 BPF_MOV32_IMM(R0, 1), 2988 BPF_EXIT_INSN(), 2989 }, 2990 INTERNAL, 2991 { }, 2992 { { 0, 0x1 } }, 2993 }, 2994 { 2995 "ALU64_AND_K: 0x0000ffffffff0000 & -1 = 0x0000ffffffffffff", 2996 .u.insns_int = { 2997 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 2998 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), 2999 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff), 3000 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3001 BPF_MOV32_IMM(R0, 2), 3002 BPF_EXIT_INSN(), 3003 BPF_MOV32_IMM(R0, 1), 3004 BPF_EXIT_INSN(), 3005 }, 3006 INTERNAL, 3007 { }, 3008 { { 0, 0x1 } }, 3009 }, 3010 { 3011 "ALU64_AND_K: 0xffffffffffffffff & -1 = 0xffffffffffffffff", 3012 .u.insns_int = { 3013 BPF_LD_IMM64(R2, 0xffffffffffffffffLL), 3014 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3015 BPF_ALU64_IMM(BPF_AND, R2, 0xffffffff), 3016 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3017 BPF_MOV32_IMM(R0, 2), 3018 BPF_EXIT_INSN(), 3019 BPF_MOV32_IMM(R0, 1), 3020 BPF_EXIT_INSN(), 3021 }, 3022 INTERNAL, 3023 { }, 3024 { { 0, 0x1 } }, 3025 }, 3026 /* BPF_ALU | BPF_OR | BPF_X */ 3027 { 3028 "ALU_OR_X: 1 | 2 = 3", 3029 .u.insns_int = { 3030 BPF_LD_IMM64(R0, 1), 3031 BPF_ALU32_IMM(BPF_MOV, R1, 2), 3032 BPF_ALU32_REG(BPF_OR, R0, R1), 3033 BPF_EXIT_INSN(), 3034 }, 3035 INTERNAL, 3036 { }, 3037 { { 0, 3 } }, 3038 }, 3039 { 3040 "ALU_OR_X: 0x0 | 0xffffffff = 0xffffffff", 3041 .u.insns_int = { 3042 BPF_LD_IMM64(R0, 0), 3043 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3044 BPF_ALU32_REG(BPF_OR, R0, R1), 3045 BPF_EXIT_INSN(), 3046 }, 3047 INTERNAL, 3048 { }, 3049 { { 0, 0xffffffff } }, 3050 }, 3051 { 3052 "ALU64_OR_X: 1 | 2 = 3", 3053 .u.insns_int = { 3054 BPF_LD_IMM64(R0, 1), 3055 BPF_ALU32_IMM(BPF_MOV, R1, 2), 3056 BPF_ALU64_REG(BPF_OR, R0, R1), 3057 BPF_EXIT_INSN(), 3058 }, 3059 INTERNAL, 3060 { }, 3061 { { 0, 3 } }, 3062 }, 3063 { 3064 "ALU64_OR_X: 0 | 0xffffffff = 0xffffffff", 3065 .u.insns_int = { 3066 BPF_LD_IMM64(R0, 0), 3067 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3068 BPF_ALU64_REG(BPF_OR, R0, R1), 3069 BPF_EXIT_INSN(), 3070 }, 3071 INTERNAL, 3072 { }, 3073 { { 0, 0xffffffff } }, 3074 }, 3075 /* BPF_ALU | BPF_OR | BPF_K */ 3076 { 3077 "ALU_OR_K: 1 | 2 = 3", 3078 .u.insns_int = { 3079 BPF_LD_IMM64(R0, 1), 3080 BPF_ALU32_IMM(BPF_OR, R0, 2), 3081 BPF_EXIT_INSN(), 3082 }, 3083 INTERNAL, 3084 { }, 3085 { { 0, 3 } }, 3086 }, 3087 { 3088 "ALU_OR_K: 0 & 0xffffffff = 0xffffffff", 3089 .u.insns_int = { 3090 BPF_LD_IMM64(R0, 0), 3091 BPF_ALU32_IMM(BPF_OR, R0, 0xffffffff), 3092 BPF_EXIT_INSN(), 3093 }, 3094 INTERNAL, 3095 { }, 3096 { { 0, 0xffffffff } }, 3097 }, 3098 { 3099 "ALU64_OR_K: 1 | 2 = 3", 3100 .u.insns_int = { 3101 BPF_LD_IMM64(R0, 1), 3102 BPF_ALU64_IMM(BPF_OR, R0, 2), 3103 BPF_EXIT_INSN(), 3104 }, 3105 INTERNAL, 3106 { }, 3107 { { 0, 3 } }, 3108 }, 3109 { 3110 "ALU64_OR_K: 0 & 0xffffffff = 0xffffffff", 3111 .u.insns_int = { 3112 BPF_LD_IMM64(R0, 0), 3113 BPF_ALU64_IMM(BPF_OR, R0, 0xffffffff), 3114 BPF_EXIT_INSN(), 3115 }, 3116 INTERNAL, 3117 { }, 3118 { { 0, 0xffffffff } }, 3119 }, 3120 { 3121 "ALU64_OR_K: 0x0000ffffffff0000 | 0x0 = 0x0000ffff00000000", 3122 .u.insns_int = { 3123 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3124 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), 3125 BPF_ALU64_IMM(BPF_OR, R2, 0x0), 3126 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3127 BPF_MOV32_IMM(R0, 2), 3128 BPF_EXIT_INSN(), 3129 BPF_MOV32_IMM(R0, 1), 3130 BPF_EXIT_INSN(), 3131 }, 3132 INTERNAL, 3133 { }, 3134 { { 0, 0x1 } }, 3135 }, 3136 { 3137 "ALU64_OR_K: 0x0000ffffffff0000 | -1 = 0xffffffffffffffff", 3138 .u.insns_int = { 3139 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3140 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3141 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff), 3142 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3143 BPF_MOV32_IMM(R0, 2), 3144 BPF_EXIT_INSN(), 3145 BPF_MOV32_IMM(R0, 1), 3146 BPF_EXIT_INSN(), 3147 }, 3148 INTERNAL, 3149 { }, 3150 { { 0, 0x1 } }, 3151 }, 3152 { 3153 "ALU64_OR_K: 0x000000000000000 | -1 = 0xffffffffffffffff", 3154 .u.insns_int = { 3155 BPF_LD_IMM64(R2, 0x0000000000000000LL), 3156 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3157 BPF_ALU64_IMM(BPF_OR, R2, 0xffffffff), 3158 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3159 BPF_MOV32_IMM(R0, 2), 3160 BPF_EXIT_INSN(), 3161 BPF_MOV32_IMM(R0, 1), 3162 BPF_EXIT_INSN(), 3163 }, 3164 INTERNAL, 3165 { }, 3166 { { 0, 0x1 } }, 3167 }, 3168 /* BPF_ALU | BPF_XOR | BPF_X */ 3169 { 3170 "ALU_XOR_X: 5 ^ 6 = 3", 3171 .u.insns_int = { 3172 BPF_LD_IMM64(R0, 5), 3173 BPF_ALU32_IMM(BPF_MOV, R1, 6), 3174 BPF_ALU32_REG(BPF_XOR, R0, R1), 3175 BPF_EXIT_INSN(), 3176 }, 3177 INTERNAL, 3178 { }, 3179 { { 0, 3 } }, 3180 }, 3181 { 3182 "ALU_XOR_X: 0x1 ^ 0xffffffff = 0xfffffffe", 3183 .u.insns_int = { 3184 BPF_LD_IMM64(R0, 1), 3185 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3186 BPF_ALU32_REG(BPF_XOR, R0, R1), 3187 BPF_EXIT_INSN(), 3188 }, 3189 INTERNAL, 3190 { }, 3191 { { 0, 0xfffffffe } }, 3192 }, 3193 { 3194 "ALU64_XOR_X: 5 ^ 6 = 3", 3195 .u.insns_int = { 3196 BPF_LD_IMM64(R0, 5), 3197 BPF_ALU32_IMM(BPF_MOV, R1, 6), 3198 BPF_ALU64_REG(BPF_XOR, R0, R1), 3199 BPF_EXIT_INSN(), 3200 }, 3201 INTERNAL, 3202 { }, 3203 { { 0, 3 } }, 3204 }, 3205 { 3206 "ALU64_XOR_X: 1 ^ 0xffffffff = 0xfffffffe", 3207 .u.insns_int = { 3208 BPF_LD_IMM64(R0, 1), 3209 BPF_ALU32_IMM(BPF_MOV, R1, 0xffffffff), 3210 BPF_ALU64_REG(BPF_XOR, R0, R1), 3211 BPF_EXIT_INSN(), 3212 }, 3213 INTERNAL, 3214 { }, 3215 { { 0, 0xfffffffe } }, 3216 }, 3217 /* BPF_ALU | BPF_XOR | BPF_K */ 3218 { 3219 "ALU_XOR_K: 5 ^ 6 = 3", 3220 .u.insns_int = { 3221 BPF_LD_IMM64(R0, 5), 3222 BPF_ALU32_IMM(BPF_XOR, R0, 6), 3223 BPF_EXIT_INSN(), 3224 }, 3225 INTERNAL, 3226 { }, 3227 { { 0, 3 } }, 3228 }, 3229 { 3230 "ALU_XOR_K: 1 ^ 0xffffffff = 0xfffffffe", 3231 .u.insns_int = { 3232 BPF_LD_IMM64(R0, 1), 3233 BPF_ALU32_IMM(BPF_XOR, R0, 0xffffffff), 3234 BPF_EXIT_INSN(), 3235 }, 3236 INTERNAL, 3237 { }, 3238 { { 0, 0xfffffffe } }, 3239 }, 3240 { 3241 "ALU64_XOR_K: 5 ^ 6 = 3", 3242 .u.insns_int = { 3243 BPF_LD_IMM64(R0, 5), 3244 BPF_ALU64_IMM(BPF_XOR, R0, 6), 3245 BPF_EXIT_INSN(), 3246 }, 3247 INTERNAL, 3248 { }, 3249 { { 0, 3 } }, 3250 }, 3251 { 3252 "ALU64_XOR_K: 1 & 0xffffffff = 0xfffffffe", 3253 .u.insns_int = { 3254 BPF_LD_IMM64(R0, 1), 3255 BPF_ALU64_IMM(BPF_XOR, R0, 0xffffffff), 3256 BPF_EXIT_INSN(), 3257 }, 3258 INTERNAL, 3259 { }, 3260 { { 0, 0xfffffffe } }, 3261 }, 3262 { 3263 "ALU64_XOR_K: 0x0000ffffffff0000 ^ 0x0 = 0x0000ffffffff0000", 3264 .u.insns_int = { 3265 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3266 BPF_LD_IMM64(R3, 0x0000ffffffff0000LL), 3267 BPF_ALU64_IMM(BPF_XOR, R2, 0x0), 3268 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3269 BPF_MOV32_IMM(R0, 2), 3270 BPF_EXIT_INSN(), 3271 BPF_MOV32_IMM(R0, 1), 3272 BPF_EXIT_INSN(), 3273 }, 3274 INTERNAL, 3275 { }, 3276 { { 0, 0x1 } }, 3277 }, 3278 { 3279 "ALU64_XOR_K: 0x0000ffffffff0000 ^ -1 = 0xffff00000000ffff", 3280 .u.insns_int = { 3281 BPF_LD_IMM64(R2, 0x0000ffffffff0000LL), 3282 BPF_LD_IMM64(R3, 0xffff00000000ffffLL), 3283 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff), 3284 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3285 BPF_MOV32_IMM(R0, 2), 3286 BPF_EXIT_INSN(), 3287 BPF_MOV32_IMM(R0, 1), 3288 BPF_EXIT_INSN(), 3289 }, 3290 INTERNAL, 3291 { }, 3292 { { 0, 0x1 } }, 3293 }, 3294 { 3295 "ALU64_XOR_K: 0x000000000000000 ^ -1 = 0xffffffffffffffff", 3296 .u.insns_int = { 3297 BPF_LD_IMM64(R2, 0x0000000000000000LL), 3298 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3299 BPF_ALU64_IMM(BPF_XOR, R2, 0xffffffff), 3300 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3301 BPF_MOV32_IMM(R0, 2), 3302 BPF_EXIT_INSN(), 3303 BPF_MOV32_IMM(R0, 1), 3304 BPF_EXIT_INSN(), 3305 }, 3306 INTERNAL, 3307 { }, 3308 { { 0, 0x1 } }, 3309 }, 3310 /* BPF_ALU | BPF_LSH | BPF_X */ 3311 { 3312 "ALU_LSH_X: 1 << 1 = 2", 3313 .u.insns_int = { 3314 BPF_LD_IMM64(R0, 1), 3315 BPF_ALU32_IMM(BPF_MOV, R1, 1), 3316 BPF_ALU32_REG(BPF_LSH, R0, R1), 3317 BPF_EXIT_INSN(), 3318 }, 3319 INTERNAL, 3320 { }, 3321 { { 0, 2 } }, 3322 }, 3323 { 3324 "ALU_LSH_X: 1 << 31 = 0x80000000", 3325 .u.insns_int = { 3326 BPF_LD_IMM64(R0, 1), 3327 BPF_ALU32_IMM(BPF_MOV, R1, 31), 3328 BPF_ALU32_REG(BPF_LSH, R0, R1), 3329 BPF_EXIT_INSN(), 3330 }, 3331 INTERNAL, 3332 { }, 3333 { { 0, 0x80000000 } }, 3334 }, 3335 { 3336 "ALU64_LSH_X: 1 << 1 = 2", 3337 .u.insns_int = { 3338 BPF_LD_IMM64(R0, 1), 3339 BPF_ALU32_IMM(BPF_MOV, R1, 1), 3340 BPF_ALU64_REG(BPF_LSH, R0, R1), 3341 BPF_EXIT_INSN(), 3342 }, 3343 INTERNAL, 3344 { }, 3345 { { 0, 2 } }, 3346 }, 3347 { 3348 "ALU64_LSH_X: 1 << 31 = 0x80000000", 3349 .u.insns_int = { 3350 BPF_LD_IMM64(R0, 1), 3351 BPF_ALU32_IMM(BPF_MOV, R1, 31), 3352 BPF_ALU64_REG(BPF_LSH, R0, R1), 3353 BPF_EXIT_INSN(), 3354 }, 3355 INTERNAL, 3356 { }, 3357 { { 0, 0x80000000 } }, 3358 }, 3359 /* BPF_ALU | BPF_LSH | BPF_K */ 3360 { 3361 "ALU_LSH_K: 1 << 1 = 2", 3362 .u.insns_int = { 3363 BPF_LD_IMM64(R0, 1), 3364 BPF_ALU32_IMM(BPF_LSH, R0, 1), 3365 BPF_EXIT_INSN(), 3366 }, 3367 INTERNAL, 3368 { }, 3369 { { 0, 2 } }, 3370 }, 3371 { 3372 "ALU_LSH_K: 1 << 31 = 0x80000000", 3373 .u.insns_int = { 3374 BPF_LD_IMM64(R0, 1), 3375 BPF_ALU32_IMM(BPF_LSH, R0, 31), 3376 BPF_EXIT_INSN(), 3377 }, 3378 INTERNAL, 3379 { }, 3380 { { 0, 0x80000000 } }, 3381 }, 3382 { 3383 "ALU64_LSH_K: 1 << 1 = 2", 3384 .u.insns_int = { 3385 BPF_LD_IMM64(R0, 1), 3386 BPF_ALU64_IMM(BPF_LSH, R0, 1), 3387 BPF_EXIT_INSN(), 3388 }, 3389 INTERNAL, 3390 { }, 3391 { { 0, 2 } }, 3392 }, 3393 { 3394 "ALU64_LSH_K: 1 << 31 = 0x80000000", 3395 .u.insns_int = { 3396 BPF_LD_IMM64(R0, 1), 3397 BPF_ALU64_IMM(BPF_LSH, R0, 31), 3398 BPF_EXIT_INSN(), 3399 }, 3400 INTERNAL, 3401 { }, 3402 { { 0, 0x80000000 } }, 3403 }, 3404 /* BPF_ALU | BPF_RSH | BPF_X */ 3405 { 3406 "ALU_RSH_X: 2 >> 1 = 1", 3407 .u.insns_int = { 3408 BPF_LD_IMM64(R0, 2), 3409 BPF_ALU32_IMM(BPF_MOV, R1, 1), 3410 BPF_ALU32_REG(BPF_RSH, R0, R1), 3411 BPF_EXIT_INSN(), 3412 }, 3413 INTERNAL, 3414 { }, 3415 { { 0, 1 } }, 3416 }, 3417 { 3418 "ALU_RSH_X: 0x80000000 >> 31 = 1", 3419 .u.insns_int = { 3420 BPF_LD_IMM64(R0, 0x80000000), 3421 BPF_ALU32_IMM(BPF_MOV, R1, 31), 3422 BPF_ALU32_REG(BPF_RSH, R0, R1), 3423 BPF_EXIT_INSN(), 3424 }, 3425 INTERNAL, 3426 { }, 3427 { { 0, 1 } }, 3428 }, 3429 { 3430 "ALU64_RSH_X: 2 >> 1 = 1", 3431 .u.insns_int = { 3432 BPF_LD_IMM64(R0, 2), 3433 BPF_ALU32_IMM(BPF_MOV, R1, 1), 3434 BPF_ALU64_REG(BPF_RSH, R0, R1), 3435 BPF_EXIT_INSN(), 3436 }, 3437 INTERNAL, 3438 { }, 3439 { { 0, 1 } }, 3440 }, 3441 { 3442 "ALU64_RSH_X: 0x80000000 >> 31 = 1", 3443 .u.insns_int = { 3444 BPF_LD_IMM64(R0, 0x80000000), 3445 BPF_ALU32_IMM(BPF_MOV, R1, 31), 3446 BPF_ALU64_REG(BPF_RSH, R0, R1), 3447 BPF_EXIT_INSN(), 3448 }, 3449 INTERNAL, 3450 { }, 3451 { { 0, 1 } }, 3452 }, 3453 /* BPF_ALU | BPF_RSH | BPF_K */ 3454 { 3455 "ALU_RSH_K: 2 >> 1 = 1", 3456 .u.insns_int = { 3457 BPF_LD_IMM64(R0, 2), 3458 BPF_ALU32_IMM(BPF_RSH, R0, 1), 3459 BPF_EXIT_INSN(), 3460 }, 3461 INTERNAL, 3462 { }, 3463 { { 0, 1 } }, 3464 }, 3465 { 3466 "ALU_RSH_K: 0x80000000 >> 31 = 1", 3467 .u.insns_int = { 3468 BPF_LD_IMM64(R0, 0x80000000), 3469 BPF_ALU32_IMM(BPF_RSH, R0, 31), 3470 BPF_EXIT_INSN(), 3471 }, 3472 INTERNAL, 3473 { }, 3474 { { 0, 1 } }, 3475 }, 3476 { 3477 "ALU64_RSH_K: 2 >> 1 = 1", 3478 .u.insns_int = { 3479 BPF_LD_IMM64(R0, 2), 3480 BPF_ALU64_IMM(BPF_RSH, R0, 1), 3481 BPF_EXIT_INSN(), 3482 }, 3483 INTERNAL, 3484 { }, 3485 { { 0, 1 } }, 3486 }, 3487 { 3488 "ALU64_RSH_K: 0x80000000 >> 31 = 1", 3489 .u.insns_int = { 3490 BPF_LD_IMM64(R0, 0x80000000), 3491 BPF_ALU64_IMM(BPF_RSH, R0, 31), 3492 BPF_EXIT_INSN(), 3493 }, 3494 INTERNAL, 3495 { }, 3496 { { 0, 1 } }, 3497 }, 3498 /* BPF_ALU | BPF_ARSH | BPF_X */ 3499 { 3500 "ALU_ARSH_X: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff", 3501 .u.insns_int = { 3502 BPF_LD_IMM64(R0, 0xff00ff0000000000LL), 3503 BPF_ALU32_IMM(BPF_MOV, R1, 40), 3504 BPF_ALU64_REG(BPF_ARSH, R0, R1), 3505 BPF_EXIT_INSN(), 3506 }, 3507 INTERNAL, 3508 { }, 3509 { { 0, 0xffff00ff } }, 3510 }, 3511 /* BPF_ALU | BPF_ARSH | BPF_K */ 3512 { 3513 "ALU_ARSH_K: 0xff00ff0000000000 >> 40 = 0xffffffffffff00ff", 3514 .u.insns_int = { 3515 BPF_LD_IMM64(R0, 0xff00ff0000000000LL), 3516 BPF_ALU64_IMM(BPF_ARSH, R0, 40), 3517 BPF_EXIT_INSN(), 3518 }, 3519 INTERNAL, 3520 { }, 3521 { { 0, 0xffff00ff } }, 3522 }, 3523 /* BPF_ALU | BPF_NEG */ 3524 { 3525 "ALU_NEG: -(3) = -3", 3526 .u.insns_int = { 3527 BPF_ALU32_IMM(BPF_MOV, R0, 3), 3528 BPF_ALU32_IMM(BPF_NEG, R0, 0), 3529 BPF_EXIT_INSN(), 3530 }, 3531 INTERNAL, 3532 { }, 3533 { { 0, -3 } }, 3534 }, 3535 { 3536 "ALU_NEG: -(-3) = 3", 3537 .u.insns_int = { 3538 BPF_ALU32_IMM(BPF_MOV, R0, -3), 3539 BPF_ALU32_IMM(BPF_NEG, R0, 0), 3540 BPF_EXIT_INSN(), 3541 }, 3542 INTERNAL, 3543 { }, 3544 { { 0, 3 } }, 3545 }, 3546 { 3547 "ALU64_NEG: -(3) = -3", 3548 .u.insns_int = { 3549 BPF_LD_IMM64(R0, 3), 3550 BPF_ALU64_IMM(BPF_NEG, R0, 0), 3551 BPF_EXIT_INSN(), 3552 }, 3553 INTERNAL, 3554 { }, 3555 { { 0, -3 } }, 3556 }, 3557 { 3558 "ALU64_NEG: -(-3) = 3", 3559 .u.insns_int = { 3560 BPF_LD_IMM64(R0, -3), 3561 BPF_ALU64_IMM(BPF_NEG, R0, 0), 3562 BPF_EXIT_INSN(), 3563 }, 3564 INTERNAL, 3565 { }, 3566 { { 0, 3 } }, 3567 }, 3568 /* BPF_ALU | BPF_END | BPF_FROM_BE */ 3569 { 3570 "ALU_END_FROM_BE 16: 0x0123456789abcdef -> 0xcdef", 3571 .u.insns_int = { 3572 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3573 BPF_ENDIAN(BPF_FROM_BE, R0, 16), 3574 BPF_EXIT_INSN(), 3575 }, 3576 INTERNAL, 3577 { }, 3578 { { 0, cpu_to_be16(0xcdef) } }, 3579 }, 3580 { 3581 "ALU_END_FROM_BE 32: 0x0123456789abcdef -> 0x89abcdef", 3582 .u.insns_int = { 3583 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3584 BPF_ENDIAN(BPF_FROM_BE, R0, 32), 3585 BPF_EXIT_INSN(), 3586 }, 3587 INTERNAL, 3588 { }, 3589 { { 0, cpu_to_be32(0x89abcdef) } }, 3590 }, 3591 { 3592 "ALU_END_FROM_BE 64: 0x0123456789abcdef -> 0x89abcdef", 3593 .u.insns_int = { 3594 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3595 BPF_ENDIAN(BPF_FROM_BE, R0, 64), 3596 BPF_EXIT_INSN(), 3597 }, 3598 INTERNAL, 3599 { }, 3600 { { 0, (u32) cpu_to_be64(0x0123456789abcdefLL) } }, 3601 }, 3602 /* BPF_ALU | BPF_END | BPF_FROM_LE */ 3603 { 3604 "ALU_END_FROM_LE 16: 0x0123456789abcdef -> 0xefcd", 3605 .u.insns_int = { 3606 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3607 BPF_ENDIAN(BPF_FROM_LE, R0, 16), 3608 BPF_EXIT_INSN(), 3609 }, 3610 INTERNAL, 3611 { }, 3612 { { 0, cpu_to_le16(0xcdef) } }, 3613 }, 3614 { 3615 "ALU_END_FROM_LE 32: 0x0123456789abcdef -> 0xefcdab89", 3616 .u.insns_int = { 3617 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3618 BPF_ENDIAN(BPF_FROM_LE, R0, 32), 3619 BPF_EXIT_INSN(), 3620 }, 3621 INTERNAL, 3622 { }, 3623 { { 0, cpu_to_le32(0x89abcdef) } }, 3624 }, 3625 { 3626 "ALU_END_FROM_LE 64: 0x0123456789abcdef -> 0x67452301", 3627 .u.insns_int = { 3628 BPF_LD_IMM64(R0, 0x0123456789abcdefLL), 3629 BPF_ENDIAN(BPF_FROM_LE, R0, 64), 3630 BPF_EXIT_INSN(), 3631 }, 3632 INTERNAL, 3633 { }, 3634 { { 0, (u32) cpu_to_le64(0x0123456789abcdefLL) } }, 3635 }, 3636 /* BPF_ST(X) | BPF_MEM | BPF_B/H/W/DW */ 3637 { 3638 "ST_MEM_B: Store/Load byte: max negative", 3639 .u.insns_int = { 3640 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3641 BPF_ST_MEM(BPF_B, R10, -40, 0xff), 3642 BPF_LDX_MEM(BPF_B, R0, R10, -40), 3643 BPF_EXIT_INSN(), 3644 }, 3645 INTERNAL, 3646 { }, 3647 { { 0, 0xff } }, 3648 }, 3649 { 3650 "ST_MEM_B: Store/Load byte: max positive", 3651 .u.insns_int = { 3652 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3653 BPF_ST_MEM(BPF_H, R10, -40, 0x7f), 3654 BPF_LDX_MEM(BPF_H, R0, R10, -40), 3655 BPF_EXIT_INSN(), 3656 }, 3657 INTERNAL, 3658 { }, 3659 { { 0, 0x7f } }, 3660 }, 3661 { 3662 "STX_MEM_B: Store/Load byte: max negative", 3663 .u.insns_int = { 3664 BPF_LD_IMM64(R0, 0), 3665 BPF_LD_IMM64(R1, 0xffLL), 3666 BPF_STX_MEM(BPF_B, R10, R1, -40), 3667 BPF_LDX_MEM(BPF_B, R0, R10, -40), 3668 BPF_EXIT_INSN(), 3669 }, 3670 INTERNAL, 3671 { }, 3672 { { 0, 0xff } }, 3673 }, 3674 { 3675 "ST_MEM_H: Store/Load half word: max negative", 3676 .u.insns_int = { 3677 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3678 BPF_ST_MEM(BPF_H, R10, -40, 0xffff), 3679 BPF_LDX_MEM(BPF_H, R0, R10, -40), 3680 BPF_EXIT_INSN(), 3681 }, 3682 INTERNAL, 3683 { }, 3684 { { 0, 0xffff } }, 3685 }, 3686 { 3687 "ST_MEM_H: Store/Load half word: max positive", 3688 .u.insns_int = { 3689 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3690 BPF_ST_MEM(BPF_H, R10, -40, 0x7fff), 3691 BPF_LDX_MEM(BPF_H, R0, R10, -40), 3692 BPF_EXIT_INSN(), 3693 }, 3694 INTERNAL, 3695 { }, 3696 { { 0, 0x7fff } }, 3697 }, 3698 { 3699 "STX_MEM_H: Store/Load half word: max negative", 3700 .u.insns_int = { 3701 BPF_LD_IMM64(R0, 0), 3702 BPF_LD_IMM64(R1, 0xffffLL), 3703 BPF_STX_MEM(BPF_H, R10, R1, -40), 3704 BPF_LDX_MEM(BPF_H, R0, R10, -40), 3705 BPF_EXIT_INSN(), 3706 }, 3707 INTERNAL, 3708 { }, 3709 { { 0, 0xffff } }, 3710 }, 3711 { 3712 "ST_MEM_W: Store/Load word: max negative", 3713 .u.insns_int = { 3714 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3715 BPF_ST_MEM(BPF_W, R10, -40, 0xffffffff), 3716 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3717 BPF_EXIT_INSN(), 3718 }, 3719 INTERNAL, 3720 { }, 3721 { { 0, 0xffffffff } }, 3722 }, 3723 { 3724 "ST_MEM_W: Store/Load word: max positive", 3725 .u.insns_int = { 3726 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3727 BPF_ST_MEM(BPF_W, R10, -40, 0x7fffffff), 3728 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3729 BPF_EXIT_INSN(), 3730 }, 3731 INTERNAL, 3732 { }, 3733 { { 0, 0x7fffffff } }, 3734 }, 3735 { 3736 "STX_MEM_W: Store/Load word: max negative", 3737 .u.insns_int = { 3738 BPF_LD_IMM64(R0, 0), 3739 BPF_LD_IMM64(R1, 0xffffffffLL), 3740 BPF_STX_MEM(BPF_W, R10, R1, -40), 3741 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3742 BPF_EXIT_INSN(), 3743 }, 3744 INTERNAL, 3745 { }, 3746 { { 0, 0xffffffff } }, 3747 }, 3748 { 3749 "ST_MEM_DW: Store/Load double word: max negative", 3750 .u.insns_int = { 3751 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3752 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff), 3753 BPF_LDX_MEM(BPF_DW, R0, R10, -40), 3754 BPF_EXIT_INSN(), 3755 }, 3756 INTERNAL, 3757 { }, 3758 { { 0, 0xffffffff } }, 3759 }, 3760 { 3761 "ST_MEM_DW: Store/Load double word: max negative 2", 3762 .u.insns_int = { 3763 BPF_LD_IMM64(R2, 0xffff00000000ffffLL), 3764 BPF_LD_IMM64(R3, 0xffffffffffffffffLL), 3765 BPF_ST_MEM(BPF_DW, R10, -40, 0xffffffff), 3766 BPF_LDX_MEM(BPF_DW, R2, R10, -40), 3767 BPF_JMP_REG(BPF_JEQ, R2, R3, 2), 3768 BPF_MOV32_IMM(R0, 2), 3769 BPF_EXIT_INSN(), 3770 BPF_MOV32_IMM(R0, 1), 3771 BPF_EXIT_INSN(), 3772 }, 3773 INTERNAL, 3774 { }, 3775 { { 0, 0x1 } }, 3776 }, 3777 { 3778 "ST_MEM_DW: Store/Load double word: max positive", 3779 .u.insns_int = { 3780 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3781 BPF_ST_MEM(BPF_DW, R10, -40, 0x7fffffff), 3782 BPF_LDX_MEM(BPF_DW, R0, R10, -40), 3783 BPF_EXIT_INSN(), 3784 }, 3785 INTERNAL, 3786 { }, 3787 { { 0, 0x7fffffff } }, 3788 }, 3789 { 3790 "STX_MEM_DW: Store/Load double word: max negative", 3791 .u.insns_int = { 3792 BPF_LD_IMM64(R0, 0), 3793 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3794 BPF_STX_MEM(BPF_W, R10, R1, -40), 3795 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3796 BPF_EXIT_INSN(), 3797 }, 3798 INTERNAL, 3799 { }, 3800 { { 0, 0xffffffff } }, 3801 }, 3802 /* BPF_STX | BPF_XADD | BPF_W/DW */ 3803 { 3804 "STX_XADD_W: Test: 0x12 + 0x10 = 0x22", 3805 .u.insns_int = { 3806 BPF_ALU32_IMM(BPF_MOV, R0, 0x12), 3807 BPF_ST_MEM(BPF_W, R10, -40, 0x10), 3808 BPF_STX_XADD(BPF_W, R10, R0, -40), 3809 BPF_LDX_MEM(BPF_W, R0, R10, -40), 3810 BPF_EXIT_INSN(), 3811 }, 3812 INTERNAL, 3813 { }, 3814 { { 0, 0x22 } }, 3815 }, 3816 { 3817 "STX_XADD_DW: Test: 0x12 + 0x10 = 0x22", 3818 .u.insns_int = { 3819 BPF_ALU32_IMM(BPF_MOV, R0, 0x12), 3820 BPF_ST_MEM(BPF_DW, R10, -40, 0x10), 3821 BPF_STX_XADD(BPF_DW, R10, R0, -40), 3822 BPF_LDX_MEM(BPF_DW, R0, R10, -40), 3823 BPF_EXIT_INSN(), 3824 }, 3825 INTERNAL, 3826 { }, 3827 { { 0, 0x22 } }, 3828 }, 3829 /* BPF_JMP | BPF_EXIT */ 3830 { 3831 "JMP_EXIT", 3832 .u.insns_int = { 3833 BPF_ALU32_IMM(BPF_MOV, R0, 0x4711), 3834 BPF_EXIT_INSN(), 3835 BPF_ALU32_IMM(BPF_MOV, R0, 0x4712), 3836 }, 3837 INTERNAL, 3838 { }, 3839 { { 0, 0x4711 } }, 3840 }, 3841 /* BPF_JMP | BPF_JA */ 3842 { 3843 "JMP_JA: Unconditional jump: if (true) return 1", 3844 .u.insns_int = { 3845 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3846 BPF_JMP_IMM(BPF_JA, 0, 0, 1), 3847 BPF_EXIT_INSN(), 3848 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3849 BPF_EXIT_INSN(), 3850 }, 3851 INTERNAL, 3852 { }, 3853 { { 0, 1 } }, 3854 }, 3855 /* BPF_JMP | BPF_JSGT | BPF_K */ 3856 { 3857 "JMP_JSGT_K: Signed jump: if (-1 > -2) return 1", 3858 .u.insns_int = { 3859 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3860 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3861 BPF_JMP_IMM(BPF_JSGT, R1, -2, 1), 3862 BPF_EXIT_INSN(), 3863 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3864 BPF_EXIT_INSN(), 3865 }, 3866 INTERNAL, 3867 { }, 3868 { { 0, 1 } }, 3869 }, 3870 { 3871 "JMP_JSGT_K: Signed jump: if (-1 > -1) return 0", 3872 .u.insns_int = { 3873 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3874 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3875 BPF_JMP_IMM(BPF_JSGT, R1, -1, 1), 3876 BPF_EXIT_INSN(), 3877 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3878 BPF_EXIT_INSN(), 3879 }, 3880 INTERNAL, 3881 { }, 3882 { { 0, 1 } }, 3883 }, 3884 /* BPF_JMP | BPF_JSGE | BPF_K */ 3885 { 3886 "JMP_JSGE_K: Signed jump: if (-1 >= -2) return 1", 3887 .u.insns_int = { 3888 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3889 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3890 BPF_JMP_IMM(BPF_JSGE, R1, -2, 1), 3891 BPF_EXIT_INSN(), 3892 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3893 BPF_EXIT_INSN(), 3894 }, 3895 INTERNAL, 3896 { }, 3897 { { 0, 1 } }, 3898 }, 3899 { 3900 "JMP_JSGE_K: Signed jump: if (-1 >= -1) return 1", 3901 .u.insns_int = { 3902 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3903 BPF_LD_IMM64(R1, 0xffffffffffffffffLL), 3904 BPF_JMP_IMM(BPF_JSGE, R1, -1, 1), 3905 BPF_EXIT_INSN(), 3906 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3907 BPF_EXIT_INSN(), 3908 }, 3909 INTERNAL, 3910 { }, 3911 { { 0, 1 } }, 3912 }, 3913 /* BPF_JMP | BPF_JGT | BPF_K */ 3914 { 3915 "JMP_JGT_K: if (3 > 2) return 1", 3916 .u.insns_int = { 3917 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3918 BPF_LD_IMM64(R1, 3), 3919 BPF_JMP_IMM(BPF_JGT, R1, 2, 1), 3920 BPF_EXIT_INSN(), 3921 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3922 BPF_EXIT_INSN(), 3923 }, 3924 INTERNAL, 3925 { }, 3926 { { 0, 1 } }, 3927 }, 3928 /* BPF_JMP | BPF_JGE | BPF_K */ 3929 { 3930 "JMP_JGE_K: if (3 >= 2) return 1", 3931 .u.insns_int = { 3932 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3933 BPF_LD_IMM64(R1, 3), 3934 BPF_JMP_IMM(BPF_JGE, R1, 2, 1), 3935 BPF_EXIT_INSN(), 3936 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3937 BPF_EXIT_INSN(), 3938 }, 3939 INTERNAL, 3940 { }, 3941 { { 0, 1 } }, 3942 }, 3943 /* BPF_JMP | BPF_JGT | BPF_K jump backwards */ 3944 { 3945 "JMP_JGT_K: if (3 > 2) return 1 (jump backwards)", 3946 .u.insns_int = { 3947 BPF_JMP_IMM(BPF_JA, 0, 0, 2), /* goto start */ 3948 BPF_ALU32_IMM(BPF_MOV, R0, 1), /* out: */ 3949 BPF_EXIT_INSN(), 3950 BPF_ALU32_IMM(BPF_MOV, R0, 0), /* start: */ 3951 BPF_LD_IMM64(R1, 3), /* note: this takes 2 insns */ 3952 BPF_JMP_IMM(BPF_JGT, R1, 2, -6), /* goto out */ 3953 BPF_EXIT_INSN(), 3954 }, 3955 INTERNAL, 3956 { }, 3957 { { 0, 1 } }, 3958 }, 3959 { 3960 "JMP_JGE_K: if (3 >= 3) return 1", 3961 .u.insns_int = { 3962 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3963 BPF_LD_IMM64(R1, 3), 3964 BPF_JMP_IMM(BPF_JGE, R1, 3, 1), 3965 BPF_EXIT_INSN(), 3966 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3967 BPF_EXIT_INSN(), 3968 }, 3969 INTERNAL, 3970 { }, 3971 { { 0, 1 } }, 3972 }, 3973 /* BPF_JMP | BPF_JNE | BPF_K */ 3974 { 3975 "JMP_JNE_K: if (3 != 2) return 1", 3976 .u.insns_int = { 3977 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3978 BPF_LD_IMM64(R1, 3), 3979 BPF_JMP_IMM(BPF_JNE, R1, 2, 1), 3980 BPF_EXIT_INSN(), 3981 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3982 BPF_EXIT_INSN(), 3983 }, 3984 INTERNAL, 3985 { }, 3986 { { 0, 1 } }, 3987 }, 3988 /* BPF_JMP | BPF_JEQ | BPF_K */ 3989 { 3990 "JMP_JEQ_K: if (3 == 3) return 1", 3991 .u.insns_int = { 3992 BPF_ALU32_IMM(BPF_MOV, R0, 0), 3993 BPF_LD_IMM64(R1, 3), 3994 BPF_JMP_IMM(BPF_JEQ, R1, 3, 1), 3995 BPF_EXIT_INSN(), 3996 BPF_ALU32_IMM(BPF_MOV, R0, 1), 3997 BPF_EXIT_INSN(), 3998 }, 3999 INTERNAL, 4000 { }, 4001 { { 0, 1 } }, 4002 }, 4003 /* BPF_JMP | BPF_JSET | BPF_K */ 4004 { 4005 "JMP_JSET_K: if (0x3 & 0x2) return 1", 4006 .u.insns_int = { 4007 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4008 BPF_LD_IMM64(R1, 3), 4009 BPF_JMP_IMM(BPF_JNE, R1, 2, 1), 4010 BPF_EXIT_INSN(), 4011 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4012 BPF_EXIT_INSN(), 4013 }, 4014 INTERNAL, 4015 { }, 4016 { { 0, 1 } }, 4017 }, 4018 { 4019 "JMP_JSET_K: if (0x3 & 0xffffffff) return 1", 4020 .u.insns_int = { 4021 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4022 BPF_LD_IMM64(R1, 3), 4023 BPF_JMP_IMM(BPF_JNE, R1, 0xffffffff, 1), 4024 BPF_EXIT_INSN(), 4025 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4026 BPF_EXIT_INSN(), 4027 }, 4028 INTERNAL, 4029 { }, 4030 { { 0, 1 } }, 4031 }, 4032 /* BPF_JMP | BPF_JSGT | BPF_X */ 4033 { 4034 "JMP_JSGT_X: Signed jump: if (-1 > -2) return 1", 4035 .u.insns_int = { 4036 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4037 BPF_LD_IMM64(R1, -1), 4038 BPF_LD_IMM64(R2, -2), 4039 BPF_JMP_REG(BPF_JSGT, R1, R2, 1), 4040 BPF_EXIT_INSN(), 4041 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4042 BPF_EXIT_INSN(), 4043 }, 4044 INTERNAL, 4045 { }, 4046 { { 0, 1 } }, 4047 }, 4048 { 4049 "JMP_JSGT_X: Signed jump: if (-1 > -1) return 0", 4050 .u.insns_int = { 4051 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4052 BPF_LD_IMM64(R1, -1), 4053 BPF_LD_IMM64(R2, -1), 4054 BPF_JMP_REG(BPF_JSGT, R1, R2, 1), 4055 BPF_EXIT_INSN(), 4056 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4057 BPF_EXIT_INSN(), 4058 }, 4059 INTERNAL, 4060 { }, 4061 { { 0, 1 } }, 4062 }, 4063 /* BPF_JMP | BPF_JSGE | BPF_X */ 4064 { 4065 "JMP_JSGE_X: Signed jump: if (-1 >= -2) return 1", 4066 .u.insns_int = { 4067 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4068 BPF_LD_IMM64(R1, -1), 4069 BPF_LD_IMM64(R2, -2), 4070 BPF_JMP_REG(BPF_JSGE, R1, R2, 1), 4071 BPF_EXIT_INSN(), 4072 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4073 BPF_EXIT_INSN(), 4074 }, 4075 INTERNAL, 4076 { }, 4077 { { 0, 1 } }, 4078 }, 4079 { 4080 "JMP_JSGE_X: Signed jump: if (-1 >= -1) return 1", 4081 .u.insns_int = { 4082 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4083 BPF_LD_IMM64(R1, -1), 4084 BPF_LD_IMM64(R2, -1), 4085 BPF_JMP_REG(BPF_JSGE, R1, R2, 1), 4086 BPF_EXIT_INSN(), 4087 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4088 BPF_EXIT_INSN(), 4089 }, 4090 INTERNAL, 4091 { }, 4092 { { 0, 1 } }, 4093 }, 4094 /* BPF_JMP | BPF_JGT | BPF_X */ 4095 { 4096 "JMP_JGT_X: if (3 > 2) return 1", 4097 .u.insns_int = { 4098 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4099 BPF_LD_IMM64(R1, 3), 4100 BPF_LD_IMM64(R2, 2), 4101 BPF_JMP_REG(BPF_JGT, R1, R2, 1), 4102 BPF_EXIT_INSN(), 4103 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4104 BPF_EXIT_INSN(), 4105 }, 4106 INTERNAL, 4107 { }, 4108 { { 0, 1 } }, 4109 }, 4110 /* BPF_JMP | BPF_JGE | BPF_X */ 4111 { 4112 "JMP_JGE_X: if (3 >= 2) return 1", 4113 .u.insns_int = { 4114 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4115 BPF_LD_IMM64(R1, 3), 4116 BPF_LD_IMM64(R2, 2), 4117 BPF_JMP_REG(BPF_JGE, R1, R2, 1), 4118 BPF_EXIT_INSN(), 4119 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4120 BPF_EXIT_INSN(), 4121 }, 4122 INTERNAL, 4123 { }, 4124 { { 0, 1 } }, 4125 }, 4126 { 4127 "JMP_JGE_X: if (3 >= 3) return 1", 4128 .u.insns_int = { 4129 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4130 BPF_LD_IMM64(R1, 3), 4131 BPF_LD_IMM64(R2, 3), 4132 BPF_JMP_REG(BPF_JGE, R1, R2, 1), 4133 BPF_EXIT_INSN(), 4134 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4135 BPF_EXIT_INSN(), 4136 }, 4137 INTERNAL, 4138 { }, 4139 { { 0, 1 } }, 4140 }, 4141 /* BPF_JMP | BPF_JNE | BPF_X */ 4142 { 4143 "JMP_JNE_X: if (3 != 2) return 1", 4144 .u.insns_int = { 4145 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4146 BPF_LD_IMM64(R1, 3), 4147 BPF_LD_IMM64(R2, 2), 4148 BPF_JMP_REG(BPF_JNE, R1, R2, 1), 4149 BPF_EXIT_INSN(), 4150 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4151 BPF_EXIT_INSN(), 4152 }, 4153 INTERNAL, 4154 { }, 4155 { { 0, 1 } }, 4156 }, 4157 /* BPF_JMP | BPF_JEQ | BPF_X */ 4158 { 4159 "JMP_JEQ_X: if (3 == 3) return 1", 4160 .u.insns_int = { 4161 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4162 BPF_LD_IMM64(R1, 3), 4163 BPF_LD_IMM64(R2, 3), 4164 BPF_JMP_REG(BPF_JEQ, R1, R2, 1), 4165 BPF_EXIT_INSN(), 4166 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4167 BPF_EXIT_INSN(), 4168 }, 4169 INTERNAL, 4170 { }, 4171 { { 0, 1 } }, 4172 }, 4173 /* BPF_JMP | BPF_JSET | BPF_X */ 4174 { 4175 "JMP_JSET_X: if (0x3 & 0x2) return 1", 4176 .u.insns_int = { 4177 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4178 BPF_LD_IMM64(R1, 3), 4179 BPF_LD_IMM64(R2, 2), 4180 BPF_JMP_REG(BPF_JNE, R1, R2, 1), 4181 BPF_EXIT_INSN(), 4182 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4183 BPF_EXIT_INSN(), 4184 }, 4185 INTERNAL, 4186 { }, 4187 { { 0, 1 } }, 4188 }, 4189 { 4190 "JMP_JSET_X: if (0x3 & 0xffffffff) return 1", 4191 .u.insns_int = { 4192 BPF_ALU32_IMM(BPF_MOV, R0, 0), 4193 BPF_LD_IMM64(R1, 3), 4194 BPF_LD_IMM64(R2, 0xffffffff), 4195 BPF_JMP_REG(BPF_JNE, R1, R2, 1), 4196 BPF_EXIT_INSN(), 4197 BPF_ALU32_IMM(BPF_MOV, R0, 1), 4198 BPF_EXIT_INSN(), 4199 }, 4200 INTERNAL, 4201 { }, 4202 { { 0, 1 } }, 4203 }, 4204 { /* Mainly checking JIT here. */ 4205 "BPF_MAXINSNS: Maximum possible literals", 4206 { }, 4207 CLASSIC | FLAG_NO_DATA, 4208 { }, 4209 { { 0, 0xffffffff } }, 4210 .fill_helper = bpf_fill_maxinsns1, 4211 }, 4212 { /* Mainly checking JIT here. */ 4213 "BPF_MAXINSNS: Single literal", 4214 { }, 4215 CLASSIC | FLAG_NO_DATA, 4216 { }, 4217 { { 0, 0xfefefefe } }, 4218 .fill_helper = bpf_fill_maxinsns2, 4219 }, 4220 { /* Mainly checking JIT here. */ 4221 "BPF_MAXINSNS: Run/add until end", 4222 { }, 4223 CLASSIC | FLAG_NO_DATA, 4224 { }, 4225 { { 0, 0x947bf368 } }, 4226 .fill_helper = bpf_fill_maxinsns3, 4227 }, 4228 { 4229 "BPF_MAXINSNS: Too many instructions", 4230 { }, 4231 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 4232 { }, 4233 { }, 4234 .fill_helper = bpf_fill_maxinsns4, 4235 }, 4236 { /* Mainly checking JIT here. */ 4237 "BPF_MAXINSNS: Very long jump", 4238 { }, 4239 CLASSIC | FLAG_NO_DATA, 4240 { }, 4241 { { 0, 0xabababab } }, 4242 .fill_helper = bpf_fill_maxinsns5, 4243 }, 4244 { /* Mainly checking JIT here. */ 4245 "BPF_MAXINSNS: Ctx heavy transformations", 4246 { }, 4247 CLASSIC, 4248 { }, 4249 { 4250 { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }, 4251 { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) } 4252 }, 4253 .fill_helper = bpf_fill_maxinsns6, 4254 }, 4255 { /* Mainly checking JIT here. */ 4256 "BPF_MAXINSNS: Call heavy transformations", 4257 { }, 4258 CLASSIC | FLAG_NO_DATA, 4259 { }, 4260 { { 1, 0 }, { 10, 0 } }, 4261 .fill_helper = bpf_fill_maxinsns7, 4262 }, 4263 { /* Mainly checking JIT here. */ 4264 "BPF_MAXINSNS: Jump heavy test", 4265 { }, 4266 CLASSIC | FLAG_NO_DATA, 4267 { }, 4268 { { 0, 0xffffffff } }, 4269 .fill_helper = bpf_fill_maxinsns8, 4270 }, 4271 }; 4272 4273 static struct net_device dev; 4274 4275 static struct sk_buff *populate_skb(char *buf, int size) 4276 { 4277 struct sk_buff *skb; 4278 4279 if (size >= MAX_DATA) 4280 return NULL; 4281 4282 skb = alloc_skb(MAX_DATA, GFP_KERNEL); 4283 if (!skb) 4284 return NULL; 4285 4286 memcpy(__skb_put(skb, size), buf, size); 4287 4288 /* Initialize a fake skb with test pattern. */ 4289 skb_reset_mac_header(skb); 4290 skb->protocol = htons(ETH_P_IP); 4291 skb->pkt_type = SKB_TYPE; 4292 skb->mark = SKB_MARK; 4293 skb->hash = SKB_HASH; 4294 skb->queue_mapping = SKB_QUEUE_MAP; 4295 skb->vlan_tci = SKB_VLAN_TCI; 4296 skb->dev = &dev; 4297 skb->dev->ifindex = SKB_DEV_IFINDEX; 4298 skb->dev->type = SKB_DEV_TYPE; 4299 skb_set_network_header(skb, min(size, ETH_HLEN)); 4300 4301 return skb; 4302 } 4303 4304 static void *generate_test_data(struct bpf_test *test, int sub) 4305 { 4306 if (test->aux & FLAG_NO_DATA) 4307 return NULL; 4308 4309 /* Test case expects an skb, so populate one. Various 4310 * subtests generate skbs of different sizes based on 4311 * the same data. 4312 */ 4313 return populate_skb(test->data, test->test[sub].data_size); 4314 } 4315 4316 static void release_test_data(const struct bpf_test *test, void *data) 4317 { 4318 if (test->aux & FLAG_NO_DATA) 4319 return; 4320 4321 kfree_skb(data); 4322 } 4323 4324 static int filter_length(int which) 4325 { 4326 struct sock_filter *fp; 4327 int len; 4328 4329 if (tests[which].fill_helper) 4330 return tests[which].u.ptr.len; 4331 4332 fp = tests[which].u.insns; 4333 for (len = MAX_INSNS - 1; len > 0; --len) 4334 if (fp[len].code != 0 || fp[len].k != 0) 4335 break; 4336 4337 return len + 1; 4338 } 4339 4340 static void *filter_pointer(int which) 4341 { 4342 if (tests[which].fill_helper) 4343 return tests[which].u.ptr.insns; 4344 else 4345 return tests[which].u.insns; 4346 } 4347 4348 static struct bpf_prog *generate_filter(int which, int *err) 4349 { 4350 __u8 test_type = tests[which].aux & TEST_TYPE_MASK; 4351 unsigned int flen = filter_length(which); 4352 void *fptr = filter_pointer(which); 4353 struct sock_fprog_kern fprog; 4354 struct bpf_prog *fp; 4355 4356 switch (test_type) { 4357 case CLASSIC: 4358 fprog.filter = fptr; 4359 fprog.len = flen; 4360 4361 *err = bpf_prog_create(&fp, &fprog); 4362 if (tests[which].aux & FLAG_EXPECTED_FAIL) { 4363 if (*err == -EINVAL) { 4364 pr_cont("PASS\n"); 4365 /* Verifier rejected filter as expected. */ 4366 *err = 0; 4367 return NULL; 4368 } else { 4369 pr_cont("UNEXPECTED_PASS\n"); 4370 /* Verifier didn't reject the test that's 4371 * bad enough, just return! 4372 */ 4373 *err = -EINVAL; 4374 return NULL; 4375 } 4376 } 4377 /* We don't expect to fail. */ 4378 if (*err) { 4379 pr_cont("FAIL to attach err=%d len=%d\n", 4380 *err, fprog.len); 4381 return NULL; 4382 } 4383 break; 4384 4385 case INTERNAL: 4386 fp = bpf_prog_alloc(bpf_prog_size(flen), 0); 4387 if (fp == NULL) { 4388 pr_cont("UNEXPECTED_FAIL no memory left\n"); 4389 *err = -ENOMEM; 4390 return NULL; 4391 } 4392 4393 fp->len = flen; 4394 memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn)); 4395 4396 bpf_prog_select_runtime(fp); 4397 break; 4398 } 4399 4400 *err = 0; 4401 return fp; 4402 } 4403 4404 static void release_filter(struct bpf_prog *fp, int which) 4405 { 4406 __u8 test_type = tests[which].aux & TEST_TYPE_MASK; 4407 4408 switch (test_type) { 4409 case CLASSIC: 4410 bpf_prog_destroy(fp); 4411 break; 4412 case INTERNAL: 4413 bpf_prog_free(fp); 4414 break; 4415 } 4416 } 4417 4418 static int __run_one(const struct bpf_prog *fp, const void *data, 4419 int runs, u64 *duration) 4420 { 4421 u64 start, finish; 4422 int ret = 0, i; 4423 4424 start = ktime_to_us(ktime_get()); 4425 4426 for (i = 0; i < runs; i++) 4427 ret = BPF_PROG_RUN(fp, data); 4428 4429 finish = ktime_to_us(ktime_get()); 4430 4431 *duration = (finish - start) * 1000ULL; 4432 do_div(*duration, runs); 4433 4434 return ret; 4435 } 4436 4437 static int run_one(const struct bpf_prog *fp, struct bpf_test *test) 4438 { 4439 int err_cnt = 0, i, runs = MAX_TESTRUNS; 4440 4441 for (i = 0; i < MAX_SUBTESTS; i++) { 4442 void *data; 4443 u64 duration; 4444 u32 ret; 4445 4446 if (test->test[i].data_size == 0 && 4447 test->test[i].result == 0) 4448 break; 4449 4450 data = generate_test_data(test, i); 4451 ret = __run_one(fp, data, runs, &duration); 4452 release_test_data(test, data); 4453 4454 if (ret == test->test[i].result) { 4455 pr_cont("%lld ", duration); 4456 } else { 4457 pr_cont("ret %d != %d ", ret, 4458 test->test[i].result); 4459 err_cnt++; 4460 } 4461 } 4462 4463 return err_cnt; 4464 } 4465 4466 static __init int prepare_bpf_tests(void) 4467 { 4468 int i; 4469 4470 for (i = 0; i < ARRAY_SIZE(tests); i++) { 4471 if (tests[i].fill_helper && 4472 tests[i].fill_helper(&tests[i]) < 0) 4473 return -ENOMEM; 4474 } 4475 4476 return 0; 4477 } 4478 4479 static __init void destroy_bpf_tests(void) 4480 { 4481 int i; 4482 4483 for (i = 0; i < ARRAY_SIZE(tests); i++) { 4484 if (tests[i].fill_helper) 4485 kfree(tests[i].u.ptr.insns); 4486 } 4487 } 4488 4489 static __init int test_bpf(void) 4490 { 4491 int i, err_cnt = 0, pass_cnt = 0; 4492 int jit_cnt = 0, run_cnt = 0; 4493 4494 for (i = 0; i < ARRAY_SIZE(tests); i++) { 4495 struct bpf_prog *fp; 4496 int err; 4497 4498 pr_info("#%d %s ", i, tests[i].descr); 4499 4500 fp = generate_filter(i, &err); 4501 if (fp == NULL) { 4502 if (err == 0) { 4503 pass_cnt++; 4504 continue; 4505 } 4506 4507 return err; 4508 } 4509 4510 pr_cont("jited:%u ", fp->jited); 4511 4512 run_cnt++; 4513 if (fp->jited) 4514 jit_cnt++; 4515 4516 err = run_one(fp, &tests[i]); 4517 release_filter(fp, i); 4518 4519 if (err) { 4520 pr_cont("FAIL (%d times)\n", err); 4521 err_cnt++; 4522 } else { 4523 pr_cont("PASS\n"); 4524 pass_cnt++; 4525 } 4526 } 4527 4528 pr_info("Summary: %d PASSED, %d FAILED, [%d/%d JIT'ed]\n", 4529 pass_cnt, err_cnt, jit_cnt, run_cnt); 4530 4531 return err_cnt ? -EINVAL : 0; 4532 } 4533 4534 static int __init test_bpf_init(void) 4535 { 4536 int ret; 4537 4538 ret = prepare_bpf_tests(); 4539 if (ret < 0) 4540 return ret; 4541 4542 ret = test_bpf(); 4543 4544 destroy_bpf_tests(); 4545 return ret; 4546 } 4547 4548 static void __exit test_bpf_exit(void) 4549 { 4550 } 4551 4552 module_init(test_bpf_init); 4553 module_exit(test_bpf_exit); 4554 4555 MODULE_LICENSE("GPL"); 4556