regbuf-merge.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "../config-host.h"
  2. /* SPDX-License-Identifier: MIT */
  3. // autogenerated by syzkaller (https://github.com/google/syzkaller)
  4. #include <endian.h>
  5. #include <stdint.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/mman.h>
  10. #include <sys/syscall.h>
  11. #include <sys/types.h>
  12. #include <unistd.h>
  13. #include "helpers.h"
  14. #ifndef CONFIG_USE_SANITIZER
  15. #ifndef __NR_io_uring_register
  16. #define __NR_io_uring_register 427
  17. #endif
  18. #ifndef __NR_io_uring_setup
  19. #define __NR_io_uring_setup 425
  20. #endif
  21. #define SIZEOF_IO_URING_SQE 64
  22. #define SIZEOF_IO_URING_CQE 16
  23. #define SQ_HEAD_OFFSET 0
  24. #define SQ_TAIL_OFFSET 64
  25. #define SQ_RING_MASK_OFFSET 256
  26. #define SQ_RING_ENTRIES_OFFSET 264
  27. #define SQ_FLAGS_OFFSET 276
  28. #define SQ_DROPPED_OFFSET 272
  29. #define CQ_HEAD_OFFSET 128
  30. #define CQ_TAIL_OFFSET 192
  31. #define CQ_RING_MASK_OFFSET 260
  32. #define CQ_RING_ENTRIES_OFFSET 268
  33. #define CQ_RING_OVERFLOW_OFFSET 284
  34. #define CQ_FLAGS_OFFSET 280
  35. #define CQ_CQES_OFFSET 320
  36. static long syz_io_uring_setup(volatile long a0, volatile long a1, volatile long a2, volatile long a3, volatile long a4, volatile long a5)
  37. {
  38. uint32_t entries = (uint32_t)a0;
  39. struct io_uring_params* setup_params = (struct io_uring_params*)a1;
  40. void* vma1 = (void*)a2;
  41. void* vma2 = (void*)a3;
  42. void** ring_ptr_out = (void**)a4;
  43. void** sqes_ptr_out = (void**)a5;
  44. uint32_t fd_io_uring = syscall(__NR_io_uring_setup, entries, setup_params);
  45. uint32_t sq_ring_sz = setup_params->sq_off.array + setup_params->sq_entries * sizeof(uint32_t);
  46. uint32_t cq_ring_sz = setup_params->cq_off.cqes + setup_params->cq_entries * SIZEOF_IO_URING_CQE;
  47. uint32_t ring_sz = sq_ring_sz > cq_ring_sz ? sq_ring_sz : cq_ring_sz;
  48. *ring_ptr_out = mmap(vma1, ring_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd_io_uring, IORING_OFF_SQ_RING);
  49. uint32_t sqes_sz = setup_params->sq_entries * SIZEOF_IO_URING_SQE;
  50. *sqes_ptr_out = mmap(vma2, sqes_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd_io_uring, IORING_OFF_SQES);
  51. return fd_io_uring;
  52. }
  53. static uint64_t r[1] = {0xffffffffffffffff};
  54. int main(int argc, char *argv[])
  55. {
  56. intptr_t res = 0;
  57. if (argc > 1)
  58. return T_EXIT_SKIP;
  59. mmap((void *) 0x1ffff000ul, 0x1000ul, PROT_NONE,
  60. MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0ul);
  61. mmap((void *) 0x20000000ul, 0x1000000ul, PROT_READ|PROT_WRITE|PROT_EXEC,
  62. MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0ul);
  63. mmap((void *) 0x21000000ul, 0x1000ul, PROT_NONE,
  64. MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0ul);
  65. *(uint32_t*)0x20000684 = 0;
  66. *(uint32_t*)0x20000688 = 0;
  67. *(uint32_t*)0x2000068c = 0;
  68. *(uint32_t*)0x20000690 = 0;
  69. *(uint32_t*)0x20000698 = -1;
  70. memset((void*)0x2000069c, 0, 12);
  71. res = syz_io_uring_setup(0x2fd6, 0x20000680, 0x20ffd000, 0x20ffc000,
  72. 0x20000700, 0x20000740);
  73. if (res != -1)
  74. r[0] = res;
  75. *(uint64_t*)0x20002840 = 0;
  76. *(uint64_t*)0x20002848 = 0;
  77. *(uint64_t*)0x20002850 = 0x20000840;
  78. *(uint64_t*)0x20002858 = 0x1000;
  79. syscall(__NR_io_uring_register, r[0], 0ul, 0x20002840ul, 2ul);
  80. return T_EXIT_PASS;
  81. }
  82. #else
  83. int main(int argc, char *argv[])
  84. {
  85. return T_EXIT_SKIP;
  86. }
  87. #endif