@nxtedition/rocksdb 5.2.36 → 5.2.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/binding.cc +66 -91
  2. package/deps/liburing/liburing/COPYING +502 -0
  3. package/deps/liburing/liburing/COPYING.GPL +339 -0
  4. package/deps/liburing/liburing/LICENSE +7 -0
  5. package/deps/liburing/liburing/Makefile +84 -0
  6. package/deps/liburing/liburing/Makefile.quiet +11 -0
  7. package/deps/liburing/liburing/README +46 -0
  8. package/deps/liburing/liburing/configure +420 -0
  9. package/deps/liburing/liburing/debian/README.Debian +7 -0
  10. package/deps/liburing/liburing/debian/changelog +27 -0
  11. package/deps/liburing/liburing/debian/compat +1 -0
  12. package/deps/liburing/liburing/debian/control +48 -0
  13. package/deps/liburing/liburing/debian/copyright +49 -0
  14. package/deps/liburing/liburing/debian/liburing-dev.install +4 -0
  15. package/deps/liburing/liburing/debian/liburing-dev.manpages +6 -0
  16. package/deps/liburing/liburing/debian/liburing1-udeb.install +1 -0
  17. package/deps/liburing/liburing/debian/liburing1.install +1 -0
  18. package/deps/liburing/liburing/debian/liburing1.symbols +32 -0
  19. package/deps/liburing/liburing/debian/patches/series +1 -0
  20. package/deps/liburing/liburing/debian/rules +81 -0
  21. package/deps/liburing/liburing/debian/source/format +1 -0
  22. package/deps/liburing/liburing/debian/source/local-options +2 -0
  23. package/deps/liburing/liburing/debian/source/options +1 -0
  24. package/deps/liburing/liburing/debian/watch +3 -0
  25. package/deps/liburing/liburing/examples/Makefile +29 -0
  26. package/deps/liburing/liburing/examples/io_uring-cp.c +279 -0
  27. package/deps/liburing/liburing/examples/io_uring-test.c +112 -0
  28. package/deps/liburing/liburing/examples/link-cp.c +193 -0
  29. package/deps/liburing/liburing/examples/ucontext-cp.c +273 -0
  30. package/deps/liburing/liburing/liburing.pc.in +12 -0
  31. package/deps/liburing/liburing/liburing.spec +66 -0
  32. package/deps/liburing/liburing/make-debs.sh +53 -0
  33. package/deps/liburing/liburing/man/io_uring.7 +736 -0
  34. package/deps/liburing/liburing/man/io_uring_enter.2 +1403 -0
  35. package/deps/liburing/liburing/man/io_uring_get_sqe.3 +37 -0
  36. package/deps/liburing/liburing/man/io_uring_queue_exit.3 +27 -0
  37. package/deps/liburing/liburing/man/io_uring_queue_init.3 +44 -0
  38. package/deps/liburing/liburing/man/io_uring_register.2 +605 -0
  39. package/deps/liburing/liburing/man/io_uring_setup.2 +515 -0
  40. package/deps/liburing/liburing/src/Makefile +76 -0
  41. package/deps/liburing/liburing/src/include/liburing/barrier.h +73 -0
  42. package/deps/liburing/liburing/src/include/liburing/io_uring.h +422 -0
  43. package/deps/liburing/liburing/src/include/liburing.h +775 -0
  44. package/deps/liburing/liburing/src/liburing.map +46 -0
  45. package/deps/liburing/liburing/src/queue.c +403 -0
  46. package/deps/liburing/liburing/src/register.c +299 -0
  47. package/deps/liburing/liburing/src/setup.c +356 -0
  48. package/deps/liburing/liburing/src/syscall.c +73 -0
  49. package/deps/liburing/liburing/src/syscall.h +20 -0
  50. package/deps/liburing/liburing/test/232c93d07b74-test.c +305 -0
  51. package/deps/liburing/liburing/test/35fa71a030ca-test.c +329 -0
  52. package/deps/liburing/liburing/test/500f9fbadef8-test.c +89 -0
  53. package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +93 -0
  54. package/deps/liburing/liburing/test/8a9973408177-test.c +106 -0
  55. package/deps/liburing/liburing/test/917257daa0fe-test.c +53 -0
  56. package/deps/liburing/liburing/test/Makefile +312 -0
  57. package/deps/liburing/liburing/test/a0908ae19763-test.c +58 -0
  58. package/deps/liburing/liburing/test/a4c0b3decb33-test.c +180 -0
  59. package/deps/liburing/liburing/test/accept-link.c +251 -0
  60. package/deps/liburing/liburing/test/accept-reuse.c +164 -0
  61. package/deps/liburing/liburing/test/accept-test.c +79 -0
  62. package/deps/liburing/liburing/test/accept.c +476 -0
  63. package/deps/liburing/liburing/test/across-fork.c +283 -0
  64. package/deps/liburing/liburing/test/b19062a56726-test.c +53 -0
  65. package/deps/liburing/liburing/test/b5837bd5311d-test.c +77 -0
  66. package/deps/liburing/liburing/test/ce593a6c480a-test.c +135 -0
  67. package/deps/liburing/liburing/test/close-opath.c +122 -0
  68. package/deps/liburing/liburing/test/config +10 -0
  69. package/deps/liburing/liburing/test/connect.c +398 -0
  70. package/deps/liburing/liburing/test/cq-full.c +96 -0
  71. package/deps/liburing/liburing/test/cq-overflow.c +294 -0
  72. package/deps/liburing/liburing/test/cq-peek-batch.c +102 -0
  73. package/deps/liburing/liburing/test/cq-ready.c +94 -0
  74. package/deps/liburing/liburing/test/cq-size.c +58 -0
  75. package/deps/liburing/liburing/test/d4ae271dfaae-test.c +96 -0
  76. package/deps/liburing/liburing/test/d77a67ed5f27-test.c +65 -0
  77. package/deps/liburing/liburing/test/defer.c +307 -0
  78. package/deps/liburing/liburing/test/double-poll-crash.c +186 -0
  79. package/deps/liburing/liburing/test/eeed8b54e0df-test.c +114 -0
  80. package/deps/liburing/liburing/test/empty-eownerdead.c +42 -0
  81. package/deps/liburing/liburing/test/eventfd-disable.c +151 -0
  82. package/deps/liburing/liburing/test/eventfd-ring.c +97 -0
  83. package/deps/liburing/liburing/test/eventfd.c +112 -0
  84. package/deps/liburing/liburing/test/fadvise.c +202 -0
  85. package/deps/liburing/liburing/test/fallocate.c +249 -0
  86. package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +138 -0
  87. package/deps/liburing/liburing/test/file-register.c +843 -0
  88. package/deps/liburing/liburing/test/file-update.c +173 -0
  89. package/deps/liburing/liburing/test/files-exit-hang-poll.c +128 -0
  90. package/deps/liburing/liburing/test/files-exit-hang-timeout.c +134 -0
  91. package/deps/liburing/liburing/test/fixed-link.c +90 -0
  92. package/deps/liburing/liburing/test/fsync.c +224 -0
  93. package/deps/liburing/liburing/test/hardlink.c +136 -0
  94. package/deps/liburing/liburing/test/helpers.c +135 -0
  95. package/deps/liburing/liburing/test/helpers.h +67 -0
  96. package/deps/liburing/liburing/test/io-cancel.c +537 -0
  97. package/deps/liburing/liburing/test/io_uring_enter.c +296 -0
  98. package/deps/liburing/liburing/test/io_uring_register.c +664 -0
  99. package/deps/liburing/liburing/test/io_uring_setup.c +192 -0
  100. package/deps/liburing/liburing/test/iopoll.c +366 -0
  101. package/deps/liburing/liburing/test/lfs-openat-write.c +117 -0
  102. package/deps/liburing/liburing/test/lfs-openat.c +273 -0
  103. package/deps/liburing/liburing/test/link-timeout.c +1107 -0
  104. package/deps/liburing/liburing/test/link.c +496 -0
  105. package/deps/liburing/liburing/test/link_drain.c +229 -0
  106. package/deps/liburing/liburing/test/madvise.c +195 -0
  107. package/deps/liburing/liburing/test/mkdir.c +108 -0
  108. package/deps/liburing/liburing/test/multicqes_drain.c +383 -0
  109. package/deps/liburing/liburing/test/nop-all-sizes.c +107 -0
  110. package/deps/liburing/liburing/test/nop.c +115 -0
  111. package/deps/liburing/liburing/test/open-close.c +146 -0
  112. package/deps/liburing/liburing/test/openat2.c +240 -0
  113. package/deps/liburing/liburing/test/personality.c +204 -0
  114. package/deps/liburing/liburing/test/pipe-eof.c +81 -0
  115. package/deps/liburing/liburing/test/pipe-reuse.c +105 -0
  116. package/deps/liburing/liburing/test/poll-cancel-ton.c +139 -0
  117. package/deps/liburing/liburing/test/poll-cancel.c +135 -0
  118. package/deps/liburing/liburing/test/poll-link.c +227 -0
  119. package/deps/liburing/liburing/test/poll-many.c +208 -0
  120. package/deps/liburing/liburing/test/poll-mshot-update.c +273 -0
  121. package/deps/liburing/liburing/test/poll-ring.c +48 -0
  122. package/deps/liburing/liburing/test/poll-v-poll.c +353 -0
  123. package/deps/liburing/liburing/test/poll.c +109 -0
  124. package/deps/liburing/liburing/test/probe.c +137 -0
  125. package/deps/liburing/liburing/test/read-write.c +876 -0
  126. package/deps/liburing/liburing/test/register-restrictions.c +633 -0
  127. package/deps/liburing/liburing/test/rename.c +134 -0
  128. package/deps/liburing/liburing/test/ring-leak.c +173 -0
  129. package/deps/liburing/liburing/test/ring-leak2.c +249 -0
  130. package/deps/liburing/liburing/test/rsrc_tags.c +449 -0
  131. package/deps/liburing/liburing/test/runtests-loop.sh +16 -0
  132. package/deps/liburing/liburing/test/runtests.sh +170 -0
  133. package/deps/liburing/liburing/test/rw_merge_test.c +97 -0
  134. package/deps/liburing/liburing/test/self.c +91 -0
  135. package/deps/liburing/liburing/test/send_recv.c +291 -0
  136. package/deps/liburing/liburing/test/send_recvmsg.c +345 -0
  137. package/deps/liburing/liburing/test/sendmsg_fs_cve.c +198 -0
  138. package/deps/liburing/liburing/test/shared-wq.c +84 -0
  139. package/deps/liburing/liburing/test/short-read.c +75 -0
  140. package/deps/liburing/liburing/test/shutdown.c +163 -0
  141. package/deps/liburing/liburing/test/sigfd-deadlock.c +74 -0
  142. package/deps/liburing/liburing/test/socket-rw-eagain.c +156 -0
  143. package/deps/liburing/liburing/test/socket-rw.c +147 -0
  144. package/deps/liburing/liburing/test/splice.c +511 -0
  145. package/deps/liburing/liburing/test/sq-full-cpp.cc +45 -0
  146. package/deps/liburing/liburing/test/sq-full.c +45 -0
  147. package/deps/liburing/liburing/test/sq-poll-dup.c +200 -0
  148. package/deps/liburing/liburing/test/sq-poll-kthread.c +168 -0
  149. package/deps/liburing/liburing/test/sq-poll-share.c +137 -0
  150. package/deps/liburing/liburing/test/sq-space_left.c +159 -0
  151. package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +159 -0
  152. package/deps/liburing/liburing/test/sqpoll-disable-exit.c +195 -0
  153. package/deps/liburing/liburing/test/sqpoll-exit-hang.c +77 -0
  154. package/deps/liburing/liburing/test/sqpoll-sleep.c +68 -0
  155. package/deps/liburing/liburing/test/statx.c +172 -0
  156. package/deps/liburing/liburing/test/stdout.c +232 -0
  157. package/deps/liburing/liburing/test/submit-link-fail.c +154 -0
  158. package/deps/liburing/liburing/test/submit-reuse.c +239 -0
  159. package/deps/liburing/liburing/test/symlink.c +116 -0
  160. package/deps/liburing/liburing/test/teardowns.c +58 -0
  161. package/deps/liburing/liburing/test/thread-exit.c +131 -0
  162. package/deps/liburing/liburing/test/timeout-new.c +246 -0
  163. package/deps/liburing/liburing/test/timeout-overflow.c +204 -0
  164. package/deps/liburing/liburing/test/timeout.c +1354 -0
  165. package/deps/liburing/liburing/test/unlink.c +111 -0
  166. package/deps/liburing/liburing/test/wakeup-hang.c +162 -0
  167. package/deps/liburing/liburing.gyp +20 -0
  168. package/deps/rocksdb/rocksdb/db/corruption_test.cc +62 -0
  169. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +7 -62
  170. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +25 -11
  171. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +74 -155
  172. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +1 -2
  173. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +2 -2
  174. package/deps/rocksdb/rocksdb/env/fs_posix.cc +13 -0
  175. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +4 -2
  176. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +22 -4
  177. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +5 -0
  178. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +15 -0
  179. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +5 -0
  180. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
  181. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +3 -0
  182. package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +3 -7
  183. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +2 -1
  184. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +44 -29
  185. package/deps/rocksdb/rocksdb.gyp +4 -3
  186. package/package.json +1 -1
  187. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  188. package/prebuilds/darwin-x64/node.napi.node +0 -0
  189. package/prebuilds/linux-x64/node.napi.node +0 -0
  190. package/prebuilds/prebuilds/linux-x64/node.napi.node +0 -0
@@ -0,0 +1,159 @@
1
+ #include <fcntl.h>
2
+ #include <signal.h>
3
+ #include <stdint.h>
4
+ #include <stdlib.h>
5
+ #include <string.h>
6
+ #include <sys/mman.h>
7
+ #include <sys/syscall.h>
8
+ #include <sys/wait.h>
9
+ #include <time.h>
10
+ #include <unistd.h>
11
+ #include "liburing.h"
12
+ #include "../src/syscall.h"
13
+
14
+ static uint64_t current_time_ms(void)
15
+ {
16
+ struct timespec ts;
17
+ if (clock_gettime(CLOCK_MONOTONIC, &ts))
18
+ exit(1);
19
+ return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
20
+ }
21
+
22
+ #define SIZEOF_IO_URING_SQE 64
23
+ #define SIZEOF_IO_URING_CQE 16
24
+ #define SQ_TAIL_OFFSET 64
25
+ #define SQ_RING_MASK_OFFSET 256
26
+ #define SQ_RING_ENTRIES_OFFSET 264
27
+ #define CQ_RING_ENTRIES_OFFSET 268
28
+ #define CQ_CQES_OFFSET 320
29
+
30
+ #define IORING_OFF_SQES 0x10000000ULL
31
+
32
+ #define sys_io_uring_setup 425
33
+
34
+ static void kill_and_wait(int pid, int* status)
35
+ {
36
+ kill(-pid, SIGKILL);
37
+ kill(pid, SIGKILL);
38
+ while (waitpid(-1, status, __WALL) != pid) {
39
+ }
40
+ }
41
+
42
+ #define WAIT_FLAGS __WALL
43
+
44
+ uint64_t r[3] = {0xffffffffffffffff, 0x0, 0x0};
45
+
46
+ static long syz_io_uring_setup(volatile long a0, volatile long a1,
47
+ volatile long a2, volatile long a3, volatile long a4, volatile long
48
+ a5)
49
+ {
50
+ uint32_t entries = (uint32_t)a0;
51
+ struct io_uring_params* setup_params = (struct io_uring_params*)a1;
52
+ void* vma1 = (void*)a2;
53
+ void* vma2 = (void*)a3;
54
+ void** ring_ptr_out = (void**)a4;
55
+ void** sqes_ptr_out = (void**)a5;
56
+ uint32_t fd_io_uring = syscall(sys_io_uring_setup, entries, setup_params);
57
+ uint32_t sq_ring_sz = setup_params->sq_off.array +
58
+ setup_params->sq_entries * sizeof(uint32_t);
59
+ uint32_t cq_ring_sz = setup_params->cq_off.cqes +
60
+ setup_params->cq_entries * SIZEOF_IO_URING_CQE;
61
+ uint32_t ring_sz = sq_ring_sz > cq_ring_sz ? sq_ring_sz : cq_ring_sz;
62
+ *ring_ptr_out = mmap(vma1, ring_sz, PROT_READ | PROT_WRITE,
63
+ MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd_io_uring,
64
+ IORING_OFF_SQ_RING);
65
+ uint32_t sqes_sz = setup_params->sq_entries * SIZEOF_IO_URING_SQE;
66
+ *sqes_ptr_out = mmap(vma2, sqes_sz, PROT_READ | PROT_WRITE,
67
+ MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd_io_uring, IORING_OFF_SQES);
68
+ return fd_io_uring;
69
+ }
70
+
71
+ static long syz_io_uring_submit(volatile long a0, volatile long a1,
72
+ volatile long a2, volatile long a3)
73
+ {
74
+ char* ring_ptr = (char*)a0;
75
+ char* sqes_ptr = (char*)a1;
76
+ char* sqe = (char*)a2;
77
+ uint32_t sqes_index = (uint32_t)a3;
78
+ uint32_t sq_ring_entries = *(uint32_t*)(ring_ptr + SQ_RING_ENTRIES_OFFSET);
79
+ uint32_t cq_ring_entries = *(uint32_t*)(ring_ptr + CQ_RING_ENTRIES_OFFSET);
80
+ uint32_t sq_array_off = (CQ_CQES_OFFSET + cq_ring_entries *
81
+ SIZEOF_IO_URING_CQE + 63) & ~63;
82
+ if (sq_ring_entries)
83
+ sqes_index %= sq_ring_entries;
84
+ char* sqe_dest = sqes_ptr + sqes_index * SIZEOF_IO_URING_SQE;
85
+ memcpy(sqe_dest, sqe, SIZEOF_IO_URING_SQE);
86
+ uint32_t sq_ring_mask = *(uint32_t*)(ring_ptr + SQ_RING_MASK_OFFSET);
87
+ uint32_t* sq_tail_ptr = (uint32_t*)(ring_ptr + SQ_TAIL_OFFSET);
88
+ uint32_t sq_tail = *sq_tail_ptr & sq_ring_mask;
89
+ uint32_t sq_tail_next = *sq_tail_ptr + 1;
90
+ uint32_t* sq_array = (uint32_t*)(ring_ptr + sq_array_off);
91
+ *(sq_array + sq_tail) = sqes_index;
92
+ __atomic_store_n(sq_tail_ptr, sq_tail_next, __ATOMIC_RELEASE);
93
+ return 0;
94
+ }
95
+
96
+
97
+ void trigger_bug(void)
98
+ {
99
+ intptr_t res = 0;
100
+ *(uint32_t*)0x20000204 = 0;
101
+ *(uint32_t*)0x20000208 = 2;
102
+ *(uint32_t*)0x2000020c = 0;
103
+ *(uint32_t*)0x20000210 = 0;
104
+ *(uint32_t*)0x20000218 = -1;
105
+ memset((void*)0x2000021c, 0, 12);
106
+ res = -1;
107
+ res = syz_io_uring_setup(0x7987, 0x20000200, 0x20400000, 0x20ffd000, 0x200000c0, 0x200001c0);
108
+ if (res != -1) {
109
+ r[0] = res;
110
+ r[1] = *(uint64_t*)0x200000c0;
111
+ r[2] = *(uint64_t*)0x200001c0;
112
+ }
113
+ *(uint8_t*)0x20000180 = 0xb;
114
+ *(uint8_t*)0x20000181 = 1;
115
+ *(uint16_t*)0x20000182 = 0;
116
+ *(uint32_t*)0x20000184 = 0;
117
+ *(uint64_t*)0x20000188 = 4;
118
+ *(uint64_t*)0x20000190 = 0x20000140;
119
+ *(uint64_t*)0x20000140 = 0x77359400;
120
+ *(uint64_t*)0x20000148 = 0;
121
+ *(uint32_t*)0x20000198 = 1;
122
+ *(uint32_t*)0x2000019c = 0;
123
+ *(uint64_t*)0x200001a0 = 0;
124
+ *(uint16_t*)0x200001a8 = 0;
125
+ *(uint16_t*)0x200001aa = 0;
126
+ memset((void*)0x200001ac, 0, 20);
127
+ syz_io_uring_submit(r[1], r[2], 0x20000180, 1);
128
+ *(uint32_t*)0x20000544 = 0;
129
+ *(uint32_t*)0x20000548 = 0x36;
130
+ *(uint32_t*)0x2000054c = 0;
131
+ *(uint32_t*)0x20000550 = 0;
132
+ *(uint32_t*)0x20000558 = r[0];
133
+ memset((void*)0x2000055c, 0, 12);
134
+
135
+ }
136
+ int main(void)
137
+ {
138
+ syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
139
+ int pid = fork();
140
+ if (pid < 0)
141
+ exit(1);
142
+ if (pid == 0) {
143
+ trigger_bug();
144
+ exit(0);
145
+ }
146
+ int status = 0;
147
+ uint64_t start = current_time_ms();
148
+ for (;;) {
149
+ if (current_time_ms() - start < 1000) {
150
+ continue;
151
+ }
152
+ kill_and_wait(pid, &status);
153
+ break;
154
+ }
155
+ return 0;
156
+ }
157
+
158
+
159
+
@@ -0,0 +1,195 @@
1
+ // https://syzkaller.appspot.com/bug?id=99f4ea77bb9b9ef24cefb66469be319f4aa9f162
2
+ // autogenerated by syzkaller (https://github.com/google/syzkaller)
3
+
4
+ #include <dirent.h>
5
+ #include <endian.h>
6
+ #include <errno.h>
7
+ #include <fcntl.h>
8
+ #include <signal.h>
9
+ #include <stdarg.h>
10
+ #include <stdbool.h>
11
+ #include <stdint.h>
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
+ #include <sys/mman.h>
16
+ #include <sys/prctl.h>
17
+ #include <sys/stat.h>
18
+ #include <sys/types.h>
19
+ #include <sys/wait.h>
20
+ #include <time.h>
21
+ #include <unistd.h>
22
+
23
+ #include "liburing.h"
24
+ #include "../src/syscall.h"
25
+
26
+ static void sleep_ms(uint64_t ms)
27
+ {
28
+ usleep(ms * 1000);
29
+ }
30
+
31
+ static uint64_t current_time_ms(void)
32
+ {
33
+ struct timespec ts;
34
+ if (clock_gettime(CLOCK_MONOTONIC, &ts))
35
+ exit(1);
36
+ return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
37
+ }
38
+
39
+ static bool write_file(const char* file, const char* what, ...)
40
+ {
41
+ char buf[1024];
42
+ va_list args;
43
+ va_start(args, what);
44
+ vsnprintf(buf, sizeof(buf), what, args);
45
+ va_end(args);
46
+ buf[sizeof(buf) - 1] = 0;
47
+ int len = strlen(buf);
48
+ int fd = open(file, O_WRONLY | O_CLOEXEC);
49
+ if (fd == -1)
50
+ return false;
51
+ if (write(fd, buf, len) != len) {
52
+ int err = errno;
53
+ close(fd);
54
+ errno = err;
55
+ return false;
56
+ }
57
+ close(fd);
58
+ return true;
59
+ }
60
+
61
+ #define SIZEOF_IO_URING_SQE 64
62
+ #define SIZEOF_IO_URING_CQE 16
63
+ #define SQ_HEAD_OFFSET 0
64
+ #define SQ_TAIL_OFFSET 64
65
+ #define SQ_RING_MASK_OFFSET 256
66
+ #define SQ_RING_ENTRIES_OFFSET 264
67
+ #define SQ_FLAGS_OFFSET 276
68
+ #define SQ_DROPPED_OFFSET 272
69
+ #define CQ_HEAD_OFFSET 128
70
+ #define CQ_TAIL_OFFSET 192
71
+ #define CQ_RING_MASK_OFFSET 260
72
+ #define CQ_RING_ENTRIES_OFFSET 268
73
+ #define CQ_RING_OVERFLOW_OFFSET 284
74
+ #define CQ_FLAGS_OFFSET 280
75
+ #define CQ_CQES_OFFSET 320
76
+
77
+ static long syz_io_uring_setup(volatile long a0, volatile long a1,
78
+ volatile long a2, volatile long a3,
79
+ volatile long a4, volatile long a5)
80
+ {
81
+ uint32_t entries = (uint32_t)a0;
82
+ struct io_uring_params* setup_params = (struct io_uring_params*)a1;
83
+ void* vma1 = (void*)a2;
84
+ void* vma2 = (void*)a3;
85
+ void** ring_ptr_out = (void**)a4;
86
+ void** sqes_ptr_out = (void**)a5;
87
+ uint32_t fd_io_uring = __sys_io_uring_setup(entries, setup_params);
88
+ uint32_t sq_ring_sz =
89
+ setup_params->sq_off.array + setup_params->sq_entries * sizeof(uint32_t);
90
+ uint32_t cq_ring_sz = setup_params->cq_off.cqes +
91
+ setup_params->cq_entries * SIZEOF_IO_URING_CQE;
92
+ uint32_t ring_sz = sq_ring_sz > cq_ring_sz ? sq_ring_sz : cq_ring_sz;
93
+ *ring_ptr_out = mmap(vma1, ring_sz, PROT_READ | PROT_WRITE,
94
+ MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd_io_uring,
95
+ IORING_OFF_SQ_RING);
96
+ uint32_t sqes_sz = setup_params->sq_entries * SIZEOF_IO_URING_SQE;
97
+ *sqes_ptr_out =
98
+ mmap(vma2, sqes_sz, PROT_READ | PROT_WRITE,
99
+ MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd_io_uring, IORING_OFF_SQES);
100
+ return fd_io_uring;
101
+ }
102
+
103
+ static void kill_and_wait(int pid, int* status)
104
+ {
105
+ kill(-pid, SIGKILL);
106
+ kill(pid, SIGKILL);
107
+ for (int i = 0; i < 100; i++) {
108
+ if (waitpid(-1, status, WNOHANG | __WALL) == pid)
109
+ return;
110
+ usleep(1000);
111
+ }
112
+ DIR* dir = opendir("/sys/fs/fuse/connections");
113
+ if (dir) {
114
+ for (;;) {
115
+ struct dirent* ent = readdir(dir);
116
+ if (!ent)
117
+ break;
118
+ if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
119
+ continue;
120
+ char abort[300];
121
+ snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
122
+ ent->d_name);
123
+ int fd = open(abort, O_WRONLY);
124
+ if (fd == -1) {
125
+ continue;
126
+ }
127
+ if (write(fd, abort, 1) < 0) {
128
+ }
129
+ close(fd);
130
+ }
131
+ closedir(dir);
132
+ } else {
133
+ }
134
+ while (waitpid(-1, status, __WALL) != pid) {
135
+ }
136
+ }
137
+
138
+ static void setup_test()
139
+ {
140
+ prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
141
+ setpgrp();
142
+ write_file("/proc/self/oom_score_adj", "1000");
143
+ }
144
+
145
+ static void execute_one(void);
146
+
147
+ #define WAIT_FLAGS __WALL
148
+
149
+ static void loop(void)
150
+ {
151
+ int iter = 0;
152
+ for (; iter < 100; iter++) {
153
+ int pid = fork();
154
+ if (pid < 0)
155
+ exit(1);
156
+ if (pid == 0) {
157
+ setup_test();
158
+ execute_one();
159
+ exit(0);
160
+ }
161
+ int status = 0;
162
+ uint64_t start = current_time_ms();
163
+ for (;;) {
164
+ if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
165
+ break;
166
+ sleep_ms(1);
167
+ if (current_time_ms() - start < 5000) {
168
+ continue;
169
+ }
170
+ kill_and_wait(pid, &status);
171
+ break;
172
+ }
173
+ }
174
+ }
175
+
176
+ void execute_one(void)
177
+ {
178
+ *(uint32_t*)0x20000044 = 0;
179
+ *(uint32_t*)0x20000048 = 0x42;
180
+ *(uint32_t*)0x2000004c = 0;
181
+ *(uint32_t*)0x20000050 = 0;
182
+ *(uint32_t*)0x20000058 = -1;
183
+ *(uint32_t*)0x2000005c = 0;
184
+ *(uint32_t*)0x20000060 = 0;
185
+ *(uint32_t*)0x20000064 = 0;
186
+ syz_io_uring_setup(0x74bc, 0x20000040, 0x20ffb000, 0x20ffc000, 0, 0);
187
+ }
188
+ int main(void)
189
+ {
190
+ mmap((void *)0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
191
+ mmap((void *)0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
192
+ mmap((void *)0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
193
+ loop();
194
+ return 0;
195
+ }
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Test that we exit properly with SQPOLL and having a request that
3
+ * adds a circular reference to the ring itself.
4
+ */
5
+ #include <errno.h>
6
+ #include <stdio.h>
7
+ #include <stdlib.h>
8
+ #include <unistd.h>
9
+ #include <sys/time.h>
10
+ #include <sys/poll.h>
11
+ #include "liburing.h"
12
+
13
+ static unsigned long long mtime_since(const struct timeval *s,
14
+ const struct timeval *e)
15
+ {
16
+ long long sec, usec;
17
+
18
+ sec = e->tv_sec - s->tv_sec;
19
+ usec = (e->tv_usec - s->tv_usec);
20
+ if (sec > 0 && usec < 0) {
21
+ sec--;
22
+ usec += 1000000;
23
+ }
24
+
25
+ sec *= 1000;
26
+ usec /= 1000;
27
+ return sec + usec;
28
+ }
29
+
30
+ static unsigned long long mtime_since_now(struct timeval *tv)
31
+ {
32
+ struct timeval end;
33
+
34
+ gettimeofday(&end, NULL);
35
+ return mtime_since(tv, &end);
36
+ }
37
+
38
+ int main(int argc, char *argv[])
39
+ {
40
+ struct io_uring_params p = {};
41
+ struct timeval tv;
42
+ struct io_uring ring;
43
+ struct io_uring_sqe *sqe;
44
+ int ret;
45
+
46
+ if (argc > 1)
47
+ return 0;
48
+
49
+ p.flags = IORING_SETUP_SQPOLL;
50
+ p.sq_thread_idle = 100;
51
+
52
+ ret = io_uring_queue_init_params(1, &ring, &p);
53
+ if (ret) {
54
+ if (geteuid()) {
55
+ printf("%s: skipped, not root\n", argv[0]);
56
+ return 0;
57
+ }
58
+ fprintf(stderr, "queue_init=%d\n", ret);
59
+ return 1;
60
+ }
61
+
62
+ if (!(p.features & IORING_FEAT_SQPOLL_NONFIXED)) {
63
+ fprintf(stdout, "Skipping\n");
64
+ return 0;
65
+ }
66
+
67
+ sqe = io_uring_get_sqe(&ring);
68
+ io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
69
+ io_uring_submit(&ring);
70
+
71
+ gettimeofday(&tv, NULL);
72
+ do {
73
+ usleep(1000);
74
+ } while (mtime_since_now(&tv) < 1000);
75
+
76
+ return 0;
77
+ }
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Test that the sqthread goes to sleep around the specified time, and that
3
+ * the NEED_WAKEUP flag is then set.
4
+ */
5
+ #include <errno.h>
6
+ #include <stdio.h>
7
+ #include <stdlib.h>
8
+ #include <unistd.h>
9
+ #include <sys/time.h>
10
+ #include "liburing.h"
11
+
12
+ static unsigned long long mtime_since(const struct timeval *s,
13
+ const struct timeval *e)
14
+ {
15
+ long long sec, usec;
16
+
17
+ sec = e->tv_sec - s->tv_sec;
18
+ usec = (e->tv_usec - s->tv_usec);
19
+ if (sec > 0 && usec < 0) {
20
+ sec--;
21
+ usec += 1000000;
22
+ }
23
+
24
+ sec *= 1000;
25
+ usec /= 1000;
26
+ return sec + usec;
27
+ }
28
+
29
+ static unsigned long long mtime_since_now(struct timeval *tv)
30
+ {
31
+ struct timeval end;
32
+
33
+ gettimeofday(&end, NULL);
34
+ return mtime_since(tv, &end);
35
+ }
36
+
37
+ int main(int argc, char *argv[])
38
+ {
39
+ struct io_uring_params p = {};
40
+ struct timeval tv;
41
+ struct io_uring ring;
42
+ int ret;
43
+
44
+ if (argc > 1)
45
+ return 0;
46
+
47
+ p.flags = IORING_SETUP_SQPOLL;
48
+ p.sq_thread_idle = 100;
49
+
50
+ ret = io_uring_queue_init_params(1, &ring, &p);
51
+ if (ret) {
52
+ if (geteuid()) {
53
+ printf("%s: skipped, not root\n", argv[0]);
54
+ return 0;
55
+ }
56
+ fprintf(stderr, "queue_init=%d\n", ret);
57
+ return 1;
58
+ }
59
+
60
+ gettimeofday(&tv, NULL);
61
+ do {
62
+ usleep(1000);
63
+ if ((*ring.sq.kflags) & IORING_SQ_NEED_WAKEUP)
64
+ return 0;
65
+ } while (mtime_since_now(&tv) < 1000);
66
+
67
+ return 1;
68
+ }
@@ -0,0 +1,172 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: run various statx(2) tests
4
+ *
5
+ */
6
+ #include <errno.h>
7
+ #include <stdio.h>
8
+ #include <unistd.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+ #include <fcntl.h>
12
+ #include <sys/types.h>
13
+ #include <sys/syscall.h>
14
+ #include <linux/stat.h>
15
+
16
+ #include "helpers.h"
17
+ #include "liburing.h"
18
+
19
+ #ifdef __NR_statx
20
+ static int do_statx(int dfd, const char *path, int flags, unsigned mask,
21
+ struct statx *statxbuf)
22
+ {
23
+ return syscall(__NR_statx, dfd, path, flags, mask, statxbuf);
24
+ }
25
+ #else
26
+ static int do_statx(int dfd, const char *path, int flags, unsigned mask,
27
+ struct statx *statxbuf)
28
+ {
29
+ errno = ENOSYS;
30
+ return -1;
31
+ }
32
+ #endif
33
+
34
+ static int statx_syscall_supported(void)
35
+ {
36
+ return errno == ENOSYS ? 0 : -1;
37
+ }
38
+
39
+ static int test_statx(struct io_uring *ring, const char *path)
40
+ {
41
+ struct io_uring_cqe *cqe;
42
+ struct io_uring_sqe *sqe;
43
+ struct statx x1, x2;
44
+ int ret;
45
+
46
+ sqe = io_uring_get_sqe(ring);
47
+ if (!sqe) {
48
+ fprintf(stderr, "get sqe failed\n");
49
+ goto err;
50
+ }
51
+ io_uring_prep_statx(sqe, -1, path, 0, STATX_ALL, &x1);
52
+
53
+ ret = io_uring_submit(ring);
54
+ if (ret <= 0) {
55
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
56
+ goto err;
57
+ }
58
+
59
+ ret = io_uring_wait_cqe(ring, &cqe);
60
+ if (ret < 0) {
61
+ fprintf(stderr, "wait completion %d\n", ret);
62
+ goto err;
63
+ }
64
+ ret = cqe->res;
65
+ io_uring_cqe_seen(ring, cqe);
66
+ if (ret)
67
+ return ret;
68
+ ret = do_statx(-1, path, 0, STATX_ALL, &x2);
69
+ if (ret < 0)
70
+ return statx_syscall_supported();
71
+ if (memcmp(&x1, &x2, sizeof(x1))) {
72
+ fprintf(stderr, "Miscompare between io_uring and statx\n");
73
+ goto err;
74
+ }
75
+ return 0;
76
+ err:
77
+ return -1;
78
+ }
79
+
80
+ static int test_statx_fd(struct io_uring *ring, const char *path)
81
+ {
82
+ struct io_uring_cqe *cqe;
83
+ struct io_uring_sqe *sqe;
84
+ struct statx x1, x2;
85
+ int ret, fd;
86
+
87
+ fd = open(path, O_RDONLY);
88
+ if (fd < 0) {
89
+ perror("open");
90
+ return 1;
91
+ }
92
+
93
+ memset(&x1, 0, sizeof(x1));
94
+
95
+ sqe = io_uring_get_sqe(ring);
96
+ if (!sqe) {
97
+ fprintf(stderr, "get sqe failed\n");
98
+ goto err;
99
+ }
100
+ io_uring_prep_statx(sqe, fd, "", AT_EMPTY_PATH, STATX_ALL, &x1);
101
+
102
+ ret = io_uring_submit(ring);
103
+ if (ret <= 0) {
104
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
105
+ goto err;
106
+ }
107
+
108
+ ret = io_uring_wait_cqe(ring, &cqe);
109
+ if (ret < 0) {
110
+ fprintf(stderr, "wait completion %d\n", ret);
111
+ goto err;
112
+ }
113
+ ret = cqe->res;
114
+ io_uring_cqe_seen(ring, cqe);
115
+ if (ret)
116
+ return ret;
117
+ memset(&x2, 0, sizeof(x2));
118
+ ret = do_statx(fd, "", AT_EMPTY_PATH, STATX_ALL, &x2);
119
+ if (ret < 0)
120
+ return statx_syscall_supported();
121
+ if (memcmp(&x1, &x2, sizeof(x1))) {
122
+ fprintf(stderr, "Miscompare between io_uring and statx\n");
123
+ goto err;
124
+ }
125
+ return 0;
126
+ err:
127
+ return -1;
128
+ }
129
+
130
+ int main(int argc, char *argv[])
131
+ {
132
+ struct io_uring ring;
133
+ const char *fname;
134
+ int ret;
135
+
136
+ ret = io_uring_queue_init(8, &ring, 0);
137
+ if (ret) {
138
+ fprintf(stderr, "ring setup failed\n");
139
+ return 1;
140
+ }
141
+
142
+ if (argc > 1) {
143
+ fname = argv[1];
144
+ } else {
145
+ fname = "/tmp/.statx";
146
+ t_create_file(fname, 4096);
147
+ }
148
+
149
+ ret = test_statx(&ring, fname);
150
+ if (ret) {
151
+ if (ret == -EINVAL) {
152
+ fprintf(stdout, "statx not supported, skipping\n");
153
+ goto done;
154
+ }
155
+ fprintf(stderr, "test_statx failed: %d\n", ret);
156
+ goto err;
157
+ }
158
+
159
+ ret = test_statx_fd(&ring, fname);
160
+ if (ret) {
161
+ fprintf(stderr, "test_statx_fd failed: %d\n", ret);
162
+ goto err;
163
+ }
164
+ done:
165
+ if (fname != argv[1])
166
+ unlink(fname);
167
+ return 0;
168
+ err:
169
+ if (fname != argv[1])
170
+ unlink(fname);
171
+ return 1;
172
+ }