1 // SPDX-License-Identifier: GPL-2.0 2 3 #include <linux/bpf.h> 4 #include <bpf/bpf_helpers.h> 5 #include "bpf_misc.h" 6 7 #if defined(__TARGET_ARCH_x86) && __clang_major__ >= 18 8 9 SEC("socket") 10 __description("SDIV32, non-zero imm divisor, check 1") 11 __success __success_unpriv __retval(-20) 12 __naked void sdiv32_non_zero_imm_1(void) 13 { 14 asm volatile (" \ 15 w0 = -41; \ 16 w0 s/= 2; \ 17 exit; \ 18 " ::: __clobber_all); 19 } 20 21 SEC("socket") 22 __description("SDIV32, non-zero imm divisor, check 2") 23 __success __success_unpriv __retval(-20) 24 __naked void sdiv32_non_zero_imm_2(void) 25 { 26 asm volatile (" \ 27 w0 = 41; \ 28 w0 s/= -2; \ 29 exit; \ 30 " ::: __clobber_all); 31 } 32 33 SEC("socket") 34 __description("SDIV32, non-zero imm divisor, check 3") 35 __success __success_unpriv __retval(20) 36 __naked void sdiv32_non_zero_imm_3(void) 37 { 38 asm volatile (" \ 39 w0 = -41; \ 40 w0 s/= -2; \ 41 exit; \ 42 " ::: __clobber_all); 43 } 44 45 SEC("socket") 46 __description("SDIV32, non-zero imm divisor, check 4") 47 __success __success_unpriv __retval(-21) 48 __naked void sdiv32_non_zero_imm_4(void) 49 { 50 asm volatile (" \ 51 w0 = -42; \ 52 w0 s/= 2; \ 53 exit; \ 54 " ::: __clobber_all); 55 } 56 57 SEC("socket") 58 __description("SDIV32, non-zero imm divisor, check 5") 59 __success __success_unpriv __retval(-21) 60 __naked void sdiv32_non_zero_imm_5(void) 61 { 62 asm volatile (" \ 63 w0 = 42; \ 64 w0 s/= -2; \ 65 exit; \ 66 " ::: __clobber_all); 67 } 68 69 SEC("socket") 70 __description("SDIV32, non-zero imm divisor, check 6") 71 __success __success_unpriv __retval(21) 72 __naked void sdiv32_non_zero_imm_6(void) 73 { 74 asm volatile (" \ 75 w0 = -42; \ 76 w0 s/= -2; \ 77 exit; \ 78 " ::: __clobber_all); 79 } 80 81 SEC("socket") 82 __description("SDIV32, non-zero imm divisor, check 7") 83 __success __success_unpriv __retval(21) 84 __naked void sdiv32_non_zero_imm_7(void) 85 { 86 asm volatile (" \ 87 w0 = 42; \ 88 w0 s/= 2; \ 89 exit; \ 90 " ::: __clobber_all); 91 } 92 93 SEC("socket") 94 __description("SDIV32, non-zero imm divisor, check 8") 95 __success __success_unpriv __retval(20) 96 __naked void sdiv32_non_zero_imm_8(void) 97 { 98 asm volatile (" \ 99 w0 = 41; \ 100 w0 s/= 2; \ 101 exit; \ 102 " ::: __clobber_all); 103 } 104 105 SEC("socket") 106 __description("SDIV32, non-zero reg divisor, check 1") 107 __success __success_unpriv __retval(-20) 108 __naked void sdiv32_non_zero_reg_1(void) 109 { 110 asm volatile (" \ 111 w0 = -41; \ 112 w1 = 2; \ 113 w0 s/= w1; \ 114 exit; \ 115 " ::: __clobber_all); 116 } 117 118 SEC("socket") 119 __description("SDIV32, non-zero reg divisor, check 2") 120 __success __success_unpriv __retval(-20) 121 __naked void sdiv32_non_zero_reg_2(void) 122 { 123 asm volatile (" \ 124 w0 = 41; \ 125 w1 = -2; \ 126 w0 s/= w1; \ 127 exit; \ 128 " ::: __clobber_all); 129 } 130 131 SEC("socket") 132 __description("SDIV32, non-zero reg divisor, check 3") 133 __success __success_unpriv __retval(20) 134 __naked void sdiv32_non_zero_reg_3(void) 135 { 136 asm volatile (" \ 137 w0 = -41; \ 138 w1 = -2; \ 139 w0 s/= w1; \ 140 exit; \ 141 " ::: __clobber_all); 142 } 143 144 SEC("socket") 145 __description("SDIV32, non-zero reg divisor, check 4") 146 __success __success_unpriv __retval(-21) 147 __naked void sdiv32_non_zero_reg_4(void) 148 { 149 asm volatile (" \ 150 w0 = -42; \ 151 w1 = 2; \ 152 w0 s/= w1; \ 153 exit; \ 154 " ::: __clobber_all); 155 } 156 157 SEC("socket") 158 __description("SDIV32, non-zero reg divisor, check 5") 159 __success __success_unpriv __retval(-21) 160 __naked void sdiv32_non_zero_reg_5(void) 161 { 162 asm volatile (" \ 163 w0 = 42; \ 164 w1 = -2; \ 165 w0 s/= w1; \ 166 exit; \ 167 " ::: __clobber_all); 168 } 169 170 SEC("socket") 171 __description("SDIV32, non-zero reg divisor, check 6") 172 __success __success_unpriv __retval(21) 173 __naked void sdiv32_non_zero_reg_6(void) 174 { 175 asm volatile (" \ 176 w0 = -42; \ 177 w1 = -2; \ 178 w0 s/= w1; \ 179 exit; \ 180 " ::: __clobber_all); 181 } 182 183 SEC("socket") 184 __description("SDIV32, non-zero reg divisor, check 7") 185 __success __success_unpriv __retval(21) 186 __naked void sdiv32_non_zero_reg_7(void) 187 { 188 asm volatile (" \ 189 w0 = 42; \ 190 w1 = 2; \ 191 w0 s/= w1; \ 192 exit; \ 193 " ::: __clobber_all); 194 } 195 196 SEC("socket") 197 __description("SDIV32, non-zero reg divisor, check 8") 198 __success __success_unpriv __retval(20) 199 __naked void sdiv32_non_zero_reg_8(void) 200 { 201 asm volatile (" \ 202 w0 = 41; \ 203 w1 = 2; \ 204 w0 s/= w1; \ 205 exit; \ 206 " ::: __clobber_all); 207 } 208 209 SEC("socket") 210 __description("SDIV64, non-zero imm divisor, check 1") 211 __success __success_unpriv __retval(-20) 212 __naked void sdiv64_non_zero_imm_1(void) 213 { 214 asm volatile (" \ 215 r0 = -41; \ 216 r0 s/= 2; \ 217 exit; \ 218 " ::: __clobber_all); 219 } 220 221 SEC("socket") 222 __description("SDIV64, non-zero imm divisor, check 2") 223 __success __success_unpriv __retval(-20) 224 __naked void sdiv64_non_zero_imm_2(void) 225 { 226 asm volatile (" \ 227 r0 = 41; \ 228 r0 s/= -2; \ 229 exit; \ 230 " ::: __clobber_all); 231 } 232 233 SEC("socket") 234 __description("SDIV64, non-zero imm divisor, check 3") 235 __success __success_unpriv __retval(20) 236 __naked void sdiv64_non_zero_imm_3(void) 237 { 238 asm volatile (" \ 239 r0 = -41; \ 240 r0 s/= -2; \ 241 exit; \ 242 " ::: __clobber_all); 243 } 244 245 SEC("socket") 246 __description("SDIV64, non-zero imm divisor, check 4") 247 __success __success_unpriv __retval(-21) 248 __naked void sdiv64_non_zero_imm_4(void) 249 { 250 asm volatile (" \ 251 r0 = -42; \ 252 r0 s/= 2; \ 253 exit; \ 254 " ::: __clobber_all); 255 } 256 257 SEC("socket") 258 __description("SDIV64, non-zero imm divisor, check 5") 259 __success __success_unpriv __retval(-21) 260 __naked void sdiv64_non_zero_imm_5(void) 261 { 262 asm volatile (" \ 263 r0 = 42; \ 264 r0 s/= -2; \ 265 exit; \ 266 " ::: __clobber_all); 267 } 268 269 SEC("socket") 270 __description("SDIV64, non-zero imm divisor, check 6") 271 __success __success_unpriv __retval(21) 272 __naked void sdiv64_non_zero_imm_6(void) 273 { 274 asm volatile (" \ 275 r0 = -42; \ 276 r0 s/= -2; \ 277 exit; \ 278 " ::: __clobber_all); 279 } 280 281 SEC("socket") 282 __description("SDIV64, non-zero reg divisor, check 1") 283 __success __success_unpriv __retval(-20) 284 __naked void sdiv64_non_zero_reg_1(void) 285 { 286 asm volatile (" \ 287 r0 = -41; \ 288 r1 = 2; \ 289 r0 s/= r1; \ 290 exit; \ 291 " ::: __clobber_all); 292 } 293 294 SEC("socket") 295 __description("SDIV64, non-zero reg divisor, check 2") 296 __success __success_unpriv __retval(-20) 297 __naked void sdiv64_non_zero_reg_2(void) 298 { 299 asm volatile (" \ 300 r0 = 41; \ 301 r1 = -2; \ 302 r0 s/= r1; \ 303 exit; \ 304 " ::: __clobber_all); 305 } 306 307 SEC("socket") 308 __description("SDIV64, non-zero reg divisor, check 3") 309 __success __success_unpriv __retval(20) 310 __naked void sdiv64_non_zero_reg_3(void) 311 { 312 asm volatile (" \ 313 r0 = -41; \ 314 r1 = -2; \ 315 r0 s/= r1; \ 316 exit; \ 317 " ::: __clobber_all); 318 } 319 320 SEC("socket") 321 __description("SDIV64, non-zero reg divisor, check 4") 322 __success __success_unpriv __retval(-21) 323 __naked void sdiv64_non_zero_reg_4(void) 324 { 325 asm volatile (" \ 326 r0 = -42; \ 327 r1 = 2; \ 328 r0 s/= r1; \ 329 exit; \ 330 " ::: __clobber_all); 331 } 332 333 SEC("socket") 334 __description("SDIV64, non-zero reg divisor, check 5") 335 __success __success_unpriv __retval(-21) 336 __naked void sdiv64_non_zero_reg_5(void) 337 { 338 asm volatile (" \ 339 r0 = 42; \ 340 r1 = -2; \ 341 r0 s/= r1; \ 342 exit; \ 343 " ::: __clobber_all); 344 } 345 346 SEC("socket") 347 __description("SDIV64, non-zero reg divisor, check 6") 348 __success __success_unpriv __retval(21) 349 __naked void sdiv64_non_zero_reg_6(void) 350 { 351 asm volatile (" \ 352 r0 = -42; \ 353 r1 = -2; \ 354 r0 s/= r1; \ 355 exit; \ 356 " ::: __clobber_all); 357 } 358 359 SEC("socket") 360 __description("SMOD32, non-zero imm divisor, check 1") 361 __success __success_unpriv __retval(-1) 362 __naked void smod32_non_zero_imm_1(void) 363 { 364 asm volatile (" \ 365 w0 = -41; \ 366 w0 s%%= 2; \ 367 exit; \ 368 " ::: __clobber_all); 369 } 370 371 SEC("socket") 372 __description("SMOD32, non-zero imm divisor, check 2") 373 __success __success_unpriv __retval(1) 374 __naked void smod32_non_zero_imm_2(void) 375 { 376 asm volatile (" \ 377 w0 = 41; \ 378 w0 s%%= -2; \ 379 exit; \ 380 " ::: __clobber_all); 381 } 382 383 SEC("socket") 384 __description("SMOD32, non-zero imm divisor, check 3") 385 __success __success_unpriv __retval(-1) 386 __naked void smod32_non_zero_imm_3(void) 387 { 388 asm volatile (" \ 389 w0 = -41; \ 390 w0 s%%= -2; \ 391 exit; \ 392 " ::: __clobber_all); 393 } 394 395 SEC("socket") 396 __description("SMOD32, non-zero imm divisor, check 4") 397 __success __success_unpriv __retval(0) 398 __naked void smod32_non_zero_imm_4(void) 399 { 400 asm volatile (" \ 401 w0 = -42; \ 402 w0 s%%= 2; \ 403 exit; \ 404 " ::: __clobber_all); 405 } 406 407 SEC("socket") 408 __description("SMOD32, non-zero imm divisor, check 5") 409 __success __success_unpriv __retval(0) 410 __naked void smod32_non_zero_imm_5(void) 411 { 412 asm volatile (" \ 413 w0 = 42; \ 414 w0 s%%= -2; \ 415 exit; \ 416 " ::: __clobber_all); 417 } 418 419 SEC("socket") 420 __description("SMOD32, non-zero imm divisor, check 6") 421 __success __success_unpriv __retval(0) 422 __naked void smod32_non_zero_imm_6(void) 423 { 424 asm volatile (" \ 425 w0 = -42; \ 426 w0 s%%= -2; \ 427 exit; \ 428 " ::: __clobber_all); 429 } 430 431 SEC("socket") 432 __description("SMOD32, non-zero reg divisor, check 1") 433 __success __success_unpriv __retval(-1) 434 __naked void smod32_non_zero_reg_1(void) 435 { 436 asm volatile (" \ 437 w0 = -41; \ 438 w1 = 2; \ 439 w0 s%%= w1; \ 440 exit; \ 441 " ::: __clobber_all); 442 } 443 444 SEC("socket") 445 __description("SMOD32, non-zero reg divisor, check 2") 446 __success __success_unpriv __retval(1) 447 __naked void smod32_non_zero_reg_2(void) 448 { 449 asm volatile (" \ 450 w0 = 41; \ 451 w1 = -2; \ 452 w0 s%%= w1; \ 453 exit; \ 454 " ::: __clobber_all); 455 } 456 457 SEC("socket") 458 __description("SMOD32, non-zero reg divisor, check 3") 459 __success __success_unpriv __retval(-1) 460 __naked void smod32_non_zero_reg_3(void) 461 { 462 asm volatile (" \ 463 w0 = -41; \ 464 w1 = -2; \ 465 w0 s%%= w1; \ 466 exit; \ 467 " ::: __clobber_all); 468 } 469 470 SEC("socket") 471 __description("SMOD32, non-zero reg divisor, check 4") 472 __success __success_unpriv __retval(0) 473 __naked void smod32_non_zero_reg_4(void) 474 { 475 asm volatile (" \ 476 w0 = -42; \ 477 w1 = 2; \ 478 w0 s%%= w1; \ 479 exit; \ 480 " ::: __clobber_all); 481 } 482 483 SEC("socket") 484 __description("SMOD32, non-zero reg divisor, check 5") 485 __success __success_unpriv __retval(0) 486 __naked void smod32_non_zero_reg_5(void) 487 { 488 asm volatile (" \ 489 w0 = 42; \ 490 w1 = -2; \ 491 w0 s%%= w1; \ 492 exit; \ 493 " ::: __clobber_all); 494 } 495 496 SEC("socket") 497 __description("SMOD32, non-zero reg divisor, check 6") 498 __success __success_unpriv __retval(0) 499 __naked void smod32_non_zero_reg_6(void) 500 { 501 asm volatile (" \ 502 w0 = -42; \ 503 w1 = -2; \ 504 w0 s%%= w1; \ 505 exit; \ 506 " ::: __clobber_all); 507 } 508 509 SEC("socket") 510 __description("SMOD64, non-zero imm divisor, check 1") 511 __success __success_unpriv __retval(-1) 512 __naked void smod64_non_zero_imm_1(void) 513 { 514 asm volatile (" \ 515 r0 = -41; \ 516 r0 s%%= 2; \ 517 exit; \ 518 " ::: __clobber_all); 519 } 520 521 SEC("socket") 522 __description("SMOD64, non-zero imm divisor, check 2") 523 __success __success_unpriv __retval(1) 524 __naked void smod64_non_zero_imm_2(void) 525 { 526 asm volatile (" \ 527 r0 = 41; \ 528 r0 s%%= -2; \ 529 exit; \ 530 " ::: __clobber_all); 531 } 532 533 SEC("socket") 534 __description("SMOD64, non-zero imm divisor, check 3") 535 __success __success_unpriv __retval(-1) 536 __naked void smod64_non_zero_imm_3(void) 537 { 538 asm volatile (" \ 539 r0 = -41; \ 540 r0 s%%= -2; \ 541 exit; \ 542 " ::: __clobber_all); 543 } 544 545 SEC("socket") 546 __description("SMOD64, non-zero imm divisor, check 4") 547 __success __success_unpriv __retval(0) 548 __naked void smod64_non_zero_imm_4(void) 549 { 550 asm volatile (" \ 551 r0 = -42; \ 552 r0 s%%= 2; \ 553 exit; \ 554 " ::: __clobber_all); 555 } 556 557 SEC("socket") 558 __description("SMOD64, non-zero imm divisor, check 5") 559 __success __success_unpriv __retval(-0) 560 __naked void smod64_non_zero_imm_5(void) 561 { 562 asm volatile (" \ 563 r0 = 42; \ 564 r0 s%%= -2; \ 565 exit; \ 566 " ::: __clobber_all); 567 } 568 569 SEC("socket") 570 __description("SMOD64, non-zero imm divisor, check 6") 571 __success __success_unpriv __retval(0) 572 __naked void smod64_non_zero_imm_6(void) 573 { 574 asm volatile (" \ 575 r0 = -42; \ 576 r0 s%%= -2; \ 577 exit; \ 578 " ::: __clobber_all); 579 } 580 581 SEC("socket") 582 __description("SMOD64, non-zero imm divisor, check 7") 583 __success __success_unpriv __retval(0) 584 __naked void smod64_non_zero_imm_7(void) 585 { 586 asm volatile (" \ 587 r0 = 42; \ 588 r0 s%%= 2; \ 589 exit; \ 590 " ::: __clobber_all); 591 } 592 593 SEC("socket") 594 __description("SMOD64, non-zero imm divisor, check 8") 595 __success __success_unpriv __retval(1) 596 __naked void smod64_non_zero_imm_8(void) 597 { 598 asm volatile (" \ 599 r0 = 41; \ 600 r0 s%%= 2; \ 601 exit; \ 602 " ::: __clobber_all); 603 } 604 605 SEC("socket") 606 __description("SMOD64, non-zero reg divisor, check 1") 607 __success __success_unpriv __retval(-1) 608 __naked void smod64_non_zero_reg_1(void) 609 { 610 asm volatile (" \ 611 r0 = -41; \ 612 r1 = 2; \ 613 r0 s%%= r1; \ 614 exit; \ 615 " ::: __clobber_all); 616 } 617 618 SEC("socket") 619 __description("SMOD64, non-zero reg divisor, check 2") 620 __success __success_unpriv __retval(1) 621 __naked void smod64_non_zero_reg_2(void) 622 { 623 asm volatile (" \ 624 r0 = 41; \ 625 r1 = -2; \ 626 r0 s%%= r1; \ 627 exit; \ 628 " ::: __clobber_all); 629 } 630 631 SEC("socket") 632 __description("SMOD64, non-zero reg divisor, check 3") 633 __success __success_unpriv __retval(-1) 634 __naked void smod64_non_zero_reg_3(void) 635 { 636 asm volatile (" \ 637 r0 = -41; \ 638 r1 = -2; \ 639 r0 s%%= r1; \ 640 exit; \ 641 " ::: __clobber_all); 642 } 643 644 SEC("socket") 645 __description("SMOD64, non-zero reg divisor, check 4") 646 __success __success_unpriv __retval(0) 647 __naked void smod64_non_zero_reg_4(void) 648 { 649 asm volatile (" \ 650 r0 = -42; \ 651 r1 = 2; \ 652 r0 s%%= r1; \ 653 exit; \ 654 " ::: __clobber_all); 655 } 656 657 SEC("socket") 658 __description("SMOD64, non-zero reg divisor, check 5") 659 __success __success_unpriv __retval(0) 660 __naked void smod64_non_zero_reg_5(void) 661 { 662 asm volatile (" \ 663 r0 = 42; \ 664 r1 = -2; \ 665 r0 s%%= r1; \ 666 exit; \ 667 " ::: __clobber_all); 668 } 669 670 SEC("socket") 671 __description("SMOD64, non-zero reg divisor, check 6") 672 __success __success_unpriv __retval(0) 673 __naked void smod64_non_zero_reg_6(void) 674 { 675 asm volatile (" \ 676 r0 = -42; \ 677 r1 = -2; \ 678 r0 s%%= r1; \ 679 exit; \ 680 " ::: __clobber_all); 681 } 682 683 SEC("socket") 684 __description("SMOD64, non-zero reg divisor, check 7") 685 __success __success_unpriv __retval(0) 686 __naked void smod64_non_zero_reg_7(void) 687 { 688 asm volatile (" \ 689 r0 = 42; \ 690 r1 = 2; \ 691 r0 s%%= r1; \ 692 exit; \ 693 " ::: __clobber_all); 694 } 695 696 SEC("socket") 697 __description("SMOD64, non-zero reg divisor, check 8") 698 __success __success_unpriv __retval(1) 699 __naked void smod64_non_zero_reg_8(void) 700 { 701 asm volatile (" \ 702 r0 = 41; \ 703 r1 = 2; \ 704 r0 s%%= r1; \ 705 exit; \ 706 " ::: __clobber_all); 707 } 708 709 SEC("socket") 710 __description("SDIV32, zero divisor") 711 __success __success_unpriv __retval(0) 712 __naked void sdiv32_zero_divisor(void) 713 { 714 asm volatile (" \ 715 w0 = 42; \ 716 w1 = 0; \ 717 w2 = -1; \ 718 w2 s/= w1; \ 719 w0 = w2; \ 720 exit; \ 721 " ::: __clobber_all); 722 } 723 724 SEC("socket") 725 __description("SDIV64, zero divisor") 726 __success __success_unpriv __retval(0) 727 __naked void sdiv64_zero_divisor(void) 728 { 729 asm volatile (" \ 730 r0 = 42; \ 731 r1 = 0; \ 732 r2 = -1; \ 733 r2 s/= r1; \ 734 r0 = r2; \ 735 exit; \ 736 " ::: __clobber_all); 737 } 738 739 SEC("socket") 740 __description("SMOD32, zero divisor") 741 __success __success_unpriv __retval(-1) 742 __naked void smod32_zero_divisor(void) 743 { 744 asm volatile (" \ 745 w0 = 42; \ 746 w1 = 0; \ 747 w2 = -1; \ 748 w2 s%%= w1; \ 749 w0 = w2; \ 750 exit; \ 751 " ::: __clobber_all); 752 } 753 754 SEC("socket") 755 __description("SMOD64, zero divisor") 756 __success __success_unpriv __retval(-1) 757 __naked void smod64_zero_divisor(void) 758 { 759 asm volatile (" \ 760 r0 = 42; \ 761 r1 = 0; \ 762 r2 = -1; \ 763 r2 s%%= r1; \ 764 r0 = r2; \ 765 exit; \ 766 " ::: __clobber_all); 767 } 768 769 #else 770 771 SEC("socket") 772 __description("cpuv4 is not supported by compiler or jit, use a dummy test") 773 __success 774 int dummy_test(void) 775 { 776 return 0; 777 } 778 779 #endif 780 781 char _license[] SEC("license") = "GPL"; 782