@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.
- package/binding.cc +66 -91
- package/deps/liburing/liburing/COPYING +502 -0
- package/deps/liburing/liburing/COPYING.GPL +339 -0
- package/deps/liburing/liburing/LICENSE +7 -0
- package/deps/liburing/liburing/Makefile +84 -0
- package/deps/liburing/liburing/Makefile.quiet +11 -0
- package/deps/liburing/liburing/README +46 -0
- package/deps/liburing/liburing/configure +420 -0
- package/deps/liburing/liburing/debian/README.Debian +7 -0
- package/deps/liburing/liburing/debian/changelog +27 -0
- package/deps/liburing/liburing/debian/compat +1 -0
- package/deps/liburing/liburing/debian/control +48 -0
- package/deps/liburing/liburing/debian/copyright +49 -0
- package/deps/liburing/liburing/debian/liburing-dev.install +4 -0
- package/deps/liburing/liburing/debian/liburing-dev.manpages +6 -0
- package/deps/liburing/liburing/debian/liburing1-udeb.install +1 -0
- package/deps/liburing/liburing/debian/liburing1.install +1 -0
- package/deps/liburing/liburing/debian/liburing1.symbols +32 -0
- package/deps/liburing/liburing/debian/patches/series +1 -0
- package/deps/liburing/liburing/debian/rules +81 -0
- package/deps/liburing/liburing/debian/source/format +1 -0
- package/deps/liburing/liburing/debian/source/local-options +2 -0
- package/deps/liburing/liburing/debian/source/options +1 -0
- package/deps/liburing/liburing/debian/watch +3 -0
- package/deps/liburing/liburing/examples/Makefile +29 -0
- package/deps/liburing/liburing/examples/io_uring-cp.c +279 -0
- package/deps/liburing/liburing/examples/io_uring-test.c +112 -0
- package/deps/liburing/liburing/examples/link-cp.c +193 -0
- package/deps/liburing/liburing/examples/ucontext-cp.c +273 -0
- package/deps/liburing/liburing/liburing.pc.in +12 -0
- package/deps/liburing/liburing/liburing.spec +66 -0
- package/deps/liburing/liburing/make-debs.sh +53 -0
- package/deps/liburing/liburing/man/io_uring.7 +736 -0
- package/deps/liburing/liburing/man/io_uring_enter.2 +1403 -0
- package/deps/liburing/liburing/man/io_uring_get_sqe.3 +37 -0
- package/deps/liburing/liburing/man/io_uring_queue_exit.3 +27 -0
- package/deps/liburing/liburing/man/io_uring_queue_init.3 +44 -0
- package/deps/liburing/liburing/man/io_uring_register.2 +605 -0
- package/deps/liburing/liburing/man/io_uring_setup.2 +515 -0
- package/deps/liburing/liburing/src/Makefile +76 -0
- package/deps/liburing/liburing/src/include/liburing/barrier.h +73 -0
- package/deps/liburing/liburing/src/include/liburing/io_uring.h +422 -0
- package/deps/liburing/liburing/src/include/liburing.h +775 -0
- package/deps/liburing/liburing/src/liburing.map +46 -0
- package/deps/liburing/liburing/src/queue.c +403 -0
- package/deps/liburing/liburing/src/register.c +299 -0
- package/deps/liburing/liburing/src/setup.c +356 -0
- package/deps/liburing/liburing/src/syscall.c +73 -0
- package/deps/liburing/liburing/src/syscall.h +20 -0
- package/deps/liburing/liburing/test/232c93d07b74-test.c +305 -0
- package/deps/liburing/liburing/test/35fa71a030ca-test.c +329 -0
- package/deps/liburing/liburing/test/500f9fbadef8-test.c +89 -0
- package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +93 -0
- package/deps/liburing/liburing/test/8a9973408177-test.c +106 -0
- package/deps/liburing/liburing/test/917257daa0fe-test.c +53 -0
- package/deps/liburing/liburing/test/Makefile +312 -0
- package/deps/liburing/liburing/test/a0908ae19763-test.c +58 -0
- package/deps/liburing/liburing/test/a4c0b3decb33-test.c +180 -0
- package/deps/liburing/liburing/test/accept-link.c +251 -0
- package/deps/liburing/liburing/test/accept-reuse.c +164 -0
- package/deps/liburing/liburing/test/accept-test.c +79 -0
- package/deps/liburing/liburing/test/accept.c +476 -0
- package/deps/liburing/liburing/test/across-fork.c +283 -0
- package/deps/liburing/liburing/test/b19062a56726-test.c +53 -0
- package/deps/liburing/liburing/test/b5837bd5311d-test.c +77 -0
- package/deps/liburing/liburing/test/ce593a6c480a-test.c +135 -0
- package/deps/liburing/liburing/test/close-opath.c +122 -0
- package/deps/liburing/liburing/test/config +10 -0
- package/deps/liburing/liburing/test/connect.c +398 -0
- package/deps/liburing/liburing/test/cq-full.c +96 -0
- package/deps/liburing/liburing/test/cq-overflow.c +294 -0
- package/deps/liburing/liburing/test/cq-peek-batch.c +102 -0
- package/deps/liburing/liburing/test/cq-ready.c +94 -0
- package/deps/liburing/liburing/test/cq-size.c +58 -0
- package/deps/liburing/liburing/test/d4ae271dfaae-test.c +96 -0
- package/deps/liburing/liburing/test/d77a67ed5f27-test.c +65 -0
- package/deps/liburing/liburing/test/defer.c +307 -0
- package/deps/liburing/liburing/test/double-poll-crash.c +186 -0
- package/deps/liburing/liburing/test/eeed8b54e0df-test.c +114 -0
- package/deps/liburing/liburing/test/empty-eownerdead.c +42 -0
- package/deps/liburing/liburing/test/eventfd-disable.c +151 -0
- package/deps/liburing/liburing/test/eventfd-ring.c +97 -0
- package/deps/liburing/liburing/test/eventfd.c +112 -0
- package/deps/liburing/liburing/test/fadvise.c +202 -0
- package/deps/liburing/liburing/test/fallocate.c +249 -0
- package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +138 -0
- package/deps/liburing/liburing/test/file-register.c +843 -0
- package/deps/liburing/liburing/test/file-update.c +173 -0
- package/deps/liburing/liburing/test/files-exit-hang-poll.c +128 -0
- package/deps/liburing/liburing/test/files-exit-hang-timeout.c +134 -0
- package/deps/liburing/liburing/test/fixed-link.c +90 -0
- package/deps/liburing/liburing/test/fsync.c +224 -0
- package/deps/liburing/liburing/test/hardlink.c +136 -0
- package/deps/liburing/liburing/test/helpers.c +135 -0
- package/deps/liburing/liburing/test/helpers.h +67 -0
- package/deps/liburing/liburing/test/io-cancel.c +537 -0
- package/deps/liburing/liburing/test/io_uring_enter.c +296 -0
- package/deps/liburing/liburing/test/io_uring_register.c +664 -0
- package/deps/liburing/liburing/test/io_uring_setup.c +192 -0
- package/deps/liburing/liburing/test/iopoll.c +366 -0
- package/deps/liburing/liburing/test/lfs-openat-write.c +117 -0
- package/deps/liburing/liburing/test/lfs-openat.c +273 -0
- package/deps/liburing/liburing/test/link-timeout.c +1107 -0
- package/deps/liburing/liburing/test/link.c +496 -0
- package/deps/liburing/liburing/test/link_drain.c +229 -0
- package/deps/liburing/liburing/test/madvise.c +195 -0
- package/deps/liburing/liburing/test/mkdir.c +108 -0
- package/deps/liburing/liburing/test/multicqes_drain.c +383 -0
- package/deps/liburing/liburing/test/nop-all-sizes.c +107 -0
- package/deps/liburing/liburing/test/nop.c +115 -0
- package/deps/liburing/liburing/test/open-close.c +146 -0
- package/deps/liburing/liburing/test/openat2.c +240 -0
- package/deps/liburing/liburing/test/personality.c +204 -0
- package/deps/liburing/liburing/test/pipe-eof.c +81 -0
- package/deps/liburing/liburing/test/pipe-reuse.c +105 -0
- package/deps/liburing/liburing/test/poll-cancel-ton.c +139 -0
- package/deps/liburing/liburing/test/poll-cancel.c +135 -0
- package/deps/liburing/liburing/test/poll-link.c +227 -0
- package/deps/liburing/liburing/test/poll-many.c +208 -0
- package/deps/liburing/liburing/test/poll-mshot-update.c +273 -0
- package/deps/liburing/liburing/test/poll-ring.c +48 -0
- package/deps/liburing/liburing/test/poll-v-poll.c +353 -0
- package/deps/liburing/liburing/test/poll.c +109 -0
- package/deps/liburing/liburing/test/probe.c +137 -0
- package/deps/liburing/liburing/test/read-write.c +876 -0
- package/deps/liburing/liburing/test/register-restrictions.c +633 -0
- package/deps/liburing/liburing/test/rename.c +134 -0
- package/deps/liburing/liburing/test/ring-leak.c +173 -0
- package/deps/liburing/liburing/test/ring-leak2.c +249 -0
- package/deps/liburing/liburing/test/rsrc_tags.c +449 -0
- package/deps/liburing/liburing/test/runtests-loop.sh +16 -0
- package/deps/liburing/liburing/test/runtests.sh +170 -0
- package/deps/liburing/liburing/test/rw_merge_test.c +97 -0
- package/deps/liburing/liburing/test/self.c +91 -0
- package/deps/liburing/liburing/test/send_recv.c +291 -0
- package/deps/liburing/liburing/test/send_recvmsg.c +345 -0
- package/deps/liburing/liburing/test/sendmsg_fs_cve.c +198 -0
- package/deps/liburing/liburing/test/shared-wq.c +84 -0
- package/deps/liburing/liburing/test/short-read.c +75 -0
- package/deps/liburing/liburing/test/shutdown.c +163 -0
- package/deps/liburing/liburing/test/sigfd-deadlock.c +74 -0
- package/deps/liburing/liburing/test/socket-rw-eagain.c +156 -0
- package/deps/liburing/liburing/test/socket-rw.c +147 -0
- package/deps/liburing/liburing/test/splice.c +511 -0
- package/deps/liburing/liburing/test/sq-full-cpp.cc +45 -0
- package/deps/liburing/liburing/test/sq-full.c +45 -0
- package/deps/liburing/liburing/test/sq-poll-dup.c +200 -0
- package/deps/liburing/liburing/test/sq-poll-kthread.c +168 -0
- package/deps/liburing/liburing/test/sq-poll-share.c +137 -0
- package/deps/liburing/liburing/test/sq-space_left.c +159 -0
- package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +159 -0
- package/deps/liburing/liburing/test/sqpoll-disable-exit.c +195 -0
- package/deps/liburing/liburing/test/sqpoll-exit-hang.c +77 -0
- package/deps/liburing/liburing/test/sqpoll-sleep.c +68 -0
- package/deps/liburing/liburing/test/statx.c +172 -0
- package/deps/liburing/liburing/test/stdout.c +232 -0
- package/deps/liburing/liburing/test/submit-link-fail.c +154 -0
- package/deps/liburing/liburing/test/submit-reuse.c +239 -0
- package/deps/liburing/liburing/test/symlink.c +116 -0
- package/deps/liburing/liburing/test/teardowns.c +58 -0
- package/deps/liburing/liburing/test/thread-exit.c +131 -0
- package/deps/liburing/liburing/test/timeout-new.c +246 -0
- package/deps/liburing/liburing/test/timeout-overflow.c +204 -0
- package/deps/liburing/liburing/test/timeout.c +1354 -0
- package/deps/liburing/liburing/test/unlink.c +111 -0
- package/deps/liburing/liburing/test/wakeup-hang.c +162 -0
- package/deps/liburing/liburing.gyp +20 -0
- package/deps/rocksdb/rocksdb/db/corruption_test.cc +62 -0
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +7 -62
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +25 -11
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +74 -155
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +1 -2
- package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +2 -2
- package/deps/rocksdb/rocksdb/env/fs_posix.cc +13 -0
- package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +4 -2
- package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +22 -4
- package/deps/rocksdb/rocksdb/file/prefetch_test.cc +5 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +15 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +5 -0
- package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
- package/deps/rocksdb/rocksdb/monitoring/statistics.cc +3 -0
- package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +3 -7
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +2 -1
- package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +44 -29
- package/deps/rocksdb/rocksdb.gyp +4 -3
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/darwin-x64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/prebuilds/prebuilds/linux-x64/node.napi.node +0 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* Simple test case showing using sendmsg and recvmsg through io_uring
|
|
4
|
+
*/
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <string.h>
|
|
8
|
+
#include <unistd.h>
|
|
9
|
+
#include <errno.h>
|
|
10
|
+
#include <arpa/inet.h>
|
|
11
|
+
#include <sys/types.h>
|
|
12
|
+
#include <sys/socket.h>
|
|
13
|
+
#include <pthread.h>
|
|
14
|
+
#include <assert.h>
|
|
15
|
+
|
|
16
|
+
#include "liburing.h"
|
|
17
|
+
|
|
18
|
+
static char str[] = "This is a test of sendmsg and recvmsg over io_uring!";
|
|
19
|
+
|
|
20
|
+
#define MAX_MSG 128
|
|
21
|
+
|
|
22
|
+
#define PORT 10200
|
|
23
|
+
#define HOST "127.0.0.1"
|
|
24
|
+
|
|
25
|
+
#define BUF_BGID 10
|
|
26
|
+
#define BUF_BID 89
|
|
27
|
+
|
|
28
|
+
#define MAX_IOV_COUNT 10
|
|
29
|
+
|
|
30
|
+
static int recv_prep(struct io_uring *ring, struct iovec iov[], int iov_count,
|
|
31
|
+
int bgid)
|
|
32
|
+
{
|
|
33
|
+
struct sockaddr_in saddr;
|
|
34
|
+
struct msghdr msg;
|
|
35
|
+
struct io_uring_sqe *sqe;
|
|
36
|
+
int sockfd, ret;
|
|
37
|
+
int val = 1;
|
|
38
|
+
|
|
39
|
+
memset(&saddr, 0, sizeof(saddr));
|
|
40
|
+
saddr.sin_family = AF_INET;
|
|
41
|
+
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
42
|
+
saddr.sin_port = htons(PORT);
|
|
43
|
+
|
|
44
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
45
|
+
if (sockfd < 0) {
|
|
46
|
+
perror("socket");
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
val = 1;
|
|
51
|
+
setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val));
|
|
52
|
+
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
|
53
|
+
|
|
54
|
+
ret = bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr));
|
|
55
|
+
if (ret < 0) {
|
|
56
|
+
perror("bind");
|
|
57
|
+
goto err;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
sqe = io_uring_get_sqe(ring);
|
|
61
|
+
if (!sqe) {
|
|
62
|
+
fprintf(stderr, "io_uring_get_sqe failed\n");
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
io_uring_prep_recvmsg(sqe, sockfd, &msg, 0);
|
|
67
|
+
if (bgid) {
|
|
68
|
+
iov->iov_base = NULL;
|
|
69
|
+
sqe->flags |= IOSQE_BUFFER_SELECT;
|
|
70
|
+
sqe->buf_group = bgid;
|
|
71
|
+
iov_count = 1;
|
|
72
|
+
}
|
|
73
|
+
memset(&msg, 0, sizeof(msg));
|
|
74
|
+
msg.msg_namelen = sizeof(struct sockaddr_in);
|
|
75
|
+
msg.msg_iov = iov;
|
|
76
|
+
msg.msg_iovlen = iov_count;
|
|
77
|
+
|
|
78
|
+
ret = io_uring_submit(ring);
|
|
79
|
+
if (ret <= 0) {
|
|
80
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
|
81
|
+
goto err;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
close(sockfd);
|
|
85
|
+
return 0;
|
|
86
|
+
err:
|
|
87
|
+
close(sockfd);
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
struct recv_data {
|
|
92
|
+
pthread_mutex_t *mutex;
|
|
93
|
+
int buf_select;
|
|
94
|
+
int no_buf_add;
|
|
95
|
+
int iov_count;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
static int do_recvmsg(struct io_uring *ring, char buf[MAX_MSG + 1],
|
|
99
|
+
struct recv_data *rd)
|
|
100
|
+
{
|
|
101
|
+
struct io_uring_cqe *cqe;
|
|
102
|
+
int ret;
|
|
103
|
+
|
|
104
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
|
105
|
+
if (ret) {
|
|
106
|
+
fprintf(stdout, "wait_cqe: %d\n", ret);
|
|
107
|
+
goto err;
|
|
108
|
+
}
|
|
109
|
+
if (cqe->res < 0) {
|
|
110
|
+
if (rd->no_buf_add && rd->buf_select)
|
|
111
|
+
return 0;
|
|
112
|
+
fprintf(stderr, "%s: failed cqe: %d\n", __FUNCTION__, cqe->res);
|
|
113
|
+
goto err;
|
|
114
|
+
}
|
|
115
|
+
if (cqe->flags) {
|
|
116
|
+
int bid = cqe->flags >> 16;
|
|
117
|
+
if (bid != BUF_BID)
|
|
118
|
+
fprintf(stderr, "Buffer ID mismatch %d\n", bid);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (rd->no_buf_add && rd->buf_select) {
|
|
122
|
+
fprintf(stderr, "Expected -ENOBUFS: %d\n", cqe->res);
|
|
123
|
+
goto err;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (cqe->res -1 != strlen(str)) {
|
|
127
|
+
fprintf(stderr, "got wrong length: %d/%d\n", cqe->res,
|
|
128
|
+
(int) strlen(str) + 1);
|
|
129
|
+
goto err;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (strncmp(str, buf, MAX_MSG + 1)) {
|
|
133
|
+
fprintf(stderr, "string mismatch\n");
|
|
134
|
+
goto err;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return 0;
|
|
138
|
+
err:
|
|
139
|
+
return 1;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
static void init_iov(struct iovec iov[MAX_IOV_COUNT], int iov_to_use,
|
|
143
|
+
char buf[MAX_MSG + 1])
|
|
144
|
+
{
|
|
145
|
+
int i, last_idx = iov_to_use - 1;
|
|
146
|
+
|
|
147
|
+
assert(0 < iov_to_use && iov_to_use <= MAX_IOV_COUNT);
|
|
148
|
+
for (i = 0; i < last_idx; ++i) {
|
|
149
|
+
iov[i].iov_base = buf + i;
|
|
150
|
+
iov[i].iov_len = 1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
iov[last_idx].iov_base = buf + last_idx;
|
|
154
|
+
iov[last_idx].iov_len = MAX_MSG - last_idx;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static void *recv_fn(void *data)
|
|
158
|
+
{
|
|
159
|
+
struct recv_data *rd = data;
|
|
160
|
+
pthread_mutex_t *mutex = rd->mutex;
|
|
161
|
+
char buf[MAX_MSG + 1];
|
|
162
|
+
struct iovec iov[MAX_IOV_COUNT];
|
|
163
|
+
struct io_uring_sqe *sqe;
|
|
164
|
+
struct io_uring_cqe *cqe;
|
|
165
|
+
struct io_uring ring;
|
|
166
|
+
int ret;
|
|
167
|
+
|
|
168
|
+
init_iov(iov, rd->iov_count, buf);
|
|
169
|
+
|
|
170
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
|
171
|
+
if (ret) {
|
|
172
|
+
fprintf(stderr, "queue init failed: %d\n", ret);
|
|
173
|
+
goto err;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (rd->buf_select && !rd->no_buf_add) {
|
|
177
|
+
sqe = io_uring_get_sqe(&ring);
|
|
178
|
+
io_uring_prep_provide_buffers(sqe, buf, sizeof(buf) -1, 1,
|
|
179
|
+
BUF_BGID, BUF_BID);
|
|
180
|
+
ret = io_uring_submit(&ring);
|
|
181
|
+
if (ret != 1) {
|
|
182
|
+
fprintf(stderr, "submit ret=%d\n", ret);
|
|
183
|
+
goto err;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
187
|
+
if (ret) {
|
|
188
|
+
fprintf(stderr, "wait_cqe=%d\n", ret);
|
|
189
|
+
goto err;
|
|
190
|
+
}
|
|
191
|
+
ret = cqe->res;
|
|
192
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
193
|
+
if (ret == -EINVAL) {
|
|
194
|
+
fprintf(stdout, "PROVIDE_BUFFERS not supported, skip\n");
|
|
195
|
+
goto out;
|
|
196
|
+
goto err;
|
|
197
|
+
} else if (ret < 0) {
|
|
198
|
+
fprintf(stderr, "PROVIDER_BUFFERS %d\n", ret);
|
|
199
|
+
goto err;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
ret = recv_prep(&ring, iov, rd->iov_count, rd->buf_select ? BUF_BGID : 0);
|
|
204
|
+
if (ret) {
|
|
205
|
+
fprintf(stderr, "recv_prep failed: %d\n", ret);
|
|
206
|
+
goto err;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
pthread_mutex_unlock(mutex);
|
|
210
|
+
ret = do_recvmsg(&ring, buf, rd);
|
|
211
|
+
|
|
212
|
+
io_uring_queue_exit(&ring);
|
|
213
|
+
|
|
214
|
+
err:
|
|
215
|
+
return (void *)(intptr_t)ret;
|
|
216
|
+
out:
|
|
217
|
+
pthread_mutex_unlock(mutex);
|
|
218
|
+
io_uring_queue_exit(&ring);
|
|
219
|
+
return NULL;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static int do_sendmsg(void)
|
|
223
|
+
{
|
|
224
|
+
struct sockaddr_in saddr;
|
|
225
|
+
struct iovec iov = {
|
|
226
|
+
.iov_base = str,
|
|
227
|
+
.iov_len = sizeof(str),
|
|
228
|
+
};
|
|
229
|
+
struct msghdr msg;
|
|
230
|
+
struct io_uring ring;
|
|
231
|
+
struct io_uring_cqe *cqe;
|
|
232
|
+
struct io_uring_sqe *sqe;
|
|
233
|
+
int sockfd, ret;
|
|
234
|
+
|
|
235
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
|
236
|
+
if (ret) {
|
|
237
|
+
fprintf(stderr, "queue init failed: %d\n", ret);
|
|
238
|
+
return 1;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
memset(&saddr, 0, sizeof(saddr));
|
|
242
|
+
saddr.sin_family = AF_INET;
|
|
243
|
+
saddr.sin_port = htons(PORT);
|
|
244
|
+
inet_pton(AF_INET, HOST, &saddr.sin_addr);
|
|
245
|
+
|
|
246
|
+
memset(&msg, 0, sizeof(msg));
|
|
247
|
+
msg.msg_name = &saddr;
|
|
248
|
+
msg.msg_namelen = sizeof(struct sockaddr_in);
|
|
249
|
+
msg.msg_iov = &iov;
|
|
250
|
+
msg.msg_iovlen = 1;
|
|
251
|
+
|
|
252
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
253
|
+
if (sockfd < 0) {
|
|
254
|
+
perror("socket");
|
|
255
|
+
return 1;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
sqe = io_uring_get_sqe(&ring);
|
|
259
|
+
io_uring_prep_sendmsg(sqe, sockfd, &msg, 0);
|
|
260
|
+
|
|
261
|
+
ret = io_uring_submit(&ring);
|
|
262
|
+
if (ret <= 0) {
|
|
263
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
|
264
|
+
goto err;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
|
268
|
+
if (cqe->res < 0) {
|
|
269
|
+
fprintf(stderr, "%s: failed cqe: %d\n", __FUNCTION__, cqe->res);
|
|
270
|
+
goto err;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
close(sockfd);
|
|
274
|
+
return 0;
|
|
275
|
+
err:
|
|
276
|
+
close(sockfd);
|
|
277
|
+
return 1;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static int test(int buf_select, int no_buf_add, int iov_count)
|
|
281
|
+
{
|
|
282
|
+
struct recv_data rd;
|
|
283
|
+
pthread_mutexattr_t attr;
|
|
284
|
+
pthread_t recv_thread;
|
|
285
|
+
pthread_mutex_t mutex;
|
|
286
|
+
int ret;
|
|
287
|
+
void *retval;
|
|
288
|
+
|
|
289
|
+
pthread_mutexattr_init(&attr);
|
|
290
|
+
pthread_mutexattr_setpshared(&attr, 1);
|
|
291
|
+
pthread_mutex_init(&mutex, &attr);
|
|
292
|
+
pthread_mutex_lock(&mutex);
|
|
293
|
+
|
|
294
|
+
rd.mutex = &mutex;
|
|
295
|
+
rd.buf_select = buf_select;
|
|
296
|
+
rd.no_buf_add = no_buf_add;
|
|
297
|
+
rd.iov_count = iov_count;
|
|
298
|
+
ret = pthread_create(&recv_thread, NULL, recv_fn, &rd);
|
|
299
|
+
if (ret) {
|
|
300
|
+
pthread_mutex_unlock(&mutex);
|
|
301
|
+
fprintf(stderr, "Thread create failed\n");
|
|
302
|
+
return 1;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
pthread_mutex_lock(&mutex);
|
|
306
|
+
do_sendmsg();
|
|
307
|
+
pthread_join(recv_thread, &retval);
|
|
308
|
+
ret = (int)(intptr_t)retval;
|
|
309
|
+
|
|
310
|
+
return ret;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
int main(int argc, char *argv[])
|
|
314
|
+
{
|
|
315
|
+
int ret;
|
|
316
|
+
|
|
317
|
+
if (argc > 1)
|
|
318
|
+
return 0;
|
|
319
|
+
|
|
320
|
+
ret = test(0, 0, 1);
|
|
321
|
+
if (ret) {
|
|
322
|
+
fprintf(stderr, "send_recvmsg 0 failed\n");
|
|
323
|
+
return 1;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
ret = test(0, 0, 10);
|
|
327
|
+
if (ret) {
|
|
328
|
+
fprintf(stderr, "send_recvmsg multi iov failed\n");
|
|
329
|
+
return 1;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
ret = test(1, 0, 1);
|
|
333
|
+
if (ret) {
|
|
334
|
+
fprintf(stderr, "send_recvmsg 1 0 failed\n");
|
|
335
|
+
return 1;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
ret = test(1, 1, 1);
|
|
339
|
+
if (ret) {
|
|
340
|
+
fprintf(stderr, "send_recvmsg 1 1 failed\n");
|
|
341
|
+
return 1;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return 0;
|
|
345
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* repro-CVE-2020-29373 -- Reproducer for CVE-2020-29373.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021 SUSE
|
|
5
|
+
* Author: Nicolai Stange <nstange@suse.de>
|
|
6
|
+
*
|
|
7
|
+
* This program is free software; you can redistribute it and/or
|
|
8
|
+
* modify it under the terms of the GNU General Public License
|
|
9
|
+
* as published by the Free Software Foundation; either version 2
|
|
10
|
+
* of the License, or (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License
|
|
18
|
+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#include <unistd.h>
|
|
22
|
+
#include <stdio.h>
|
|
23
|
+
#include <sys/mman.h>
|
|
24
|
+
#include <sys/socket.h>
|
|
25
|
+
#include <sys/un.h>
|
|
26
|
+
#include <fcntl.h>
|
|
27
|
+
#include <errno.h>
|
|
28
|
+
#include <inttypes.h>
|
|
29
|
+
#include <stdlib.h>
|
|
30
|
+
#include <sys/types.h>
|
|
31
|
+
#include <sys/wait.h>
|
|
32
|
+
#include "liburing.h"
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* This attempts to make the kernel issue a sendmsg() to
|
|
36
|
+
* path from io_uring's async io_sq_wq_submit_work().
|
|
37
|
+
*
|
|
38
|
+
* Unfortunately, IOSQE_ASYNC is available only from kernel version
|
|
39
|
+
* 5.6 onwards. To still force io_uring to process the request
|
|
40
|
+
* asynchronously from io_sq_wq_submit_work(), queue a couple of
|
|
41
|
+
* auxiliary requests all failing with EAGAIN before. This is
|
|
42
|
+
* implemented by writing repeatedly to an auxiliary O_NONBLOCK
|
|
43
|
+
* AF_UNIX socketpair with a small SO_SNDBUF.
|
|
44
|
+
*/
|
|
45
|
+
static int try_sendmsg_async(const char * const path)
|
|
46
|
+
{
|
|
47
|
+
int snd_sock, r;
|
|
48
|
+
struct io_uring ring;
|
|
49
|
+
char sbuf[16] = {};
|
|
50
|
+
struct iovec siov = { .iov_base = &sbuf, .iov_len = sizeof(sbuf) };
|
|
51
|
+
struct sockaddr_un addr = {};
|
|
52
|
+
struct msghdr msg = {
|
|
53
|
+
.msg_name = &addr,
|
|
54
|
+
.msg_namelen = sizeof(addr),
|
|
55
|
+
.msg_iov = &siov,
|
|
56
|
+
.msg_iovlen = 1,
|
|
57
|
+
};
|
|
58
|
+
struct io_uring_cqe *cqe;
|
|
59
|
+
struct io_uring_sqe *sqe;
|
|
60
|
+
|
|
61
|
+
snd_sock = socket(AF_UNIX, SOCK_DGRAM, 0);
|
|
62
|
+
if (snd_sock < 0) {
|
|
63
|
+
perror("socket(AF_UNIX)");
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
addr.sun_family = AF_UNIX;
|
|
68
|
+
strcpy(addr.sun_path, path);
|
|
69
|
+
|
|
70
|
+
r = io_uring_queue_init(512, &ring, 0);
|
|
71
|
+
if (r < 0) {
|
|
72
|
+
fprintf(stderr, "ring setup failed: %d\n", r);
|
|
73
|
+
goto close_iour;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
sqe = io_uring_get_sqe(&ring);
|
|
77
|
+
if (!sqe) {
|
|
78
|
+
fprintf(stderr, "get sqe failed\n");
|
|
79
|
+
r = -EFAULT;
|
|
80
|
+
goto close_iour;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* the actual one supposed to fail with -ENOENT. */
|
|
84
|
+
io_uring_prep_sendmsg(sqe, snd_sock, &msg, 0);
|
|
85
|
+
sqe->flags = IOSQE_ASYNC;
|
|
86
|
+
sqe->user_data = 255;
|
|
87
|
+
|
|
88
|
+
r = io_uring_submit(&ring);
|
|
89
|
+
if (r != 1) {
|
|
90
|
+
fprintf(stderr, "sqe submit failed: %d\n", r);
|
|
91
|
+
r = -EFAULT;
|
|
92
|
+
goto close_iour;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
r = io_uring_wait_cqe(&ring, &cqe);
|
|
96
|
+
if (r < 0) {
|
|
97
|
+
fprintf(stderr, "wait completion %d\n", r);
|
|
98
|
+
r = -EFAULT;
|
|
99
|
+
goto close_iour;
|
|
100
|
+
}
|
|
101
|
+
if (cqe->user_data != 255) {
|
|
102
|
+
fprintf(stderr, "user data %d\n", r);
|
|
103
|
+
r = -EFAULT;
|
|
104
|
+
goto close_iour;
|
|
105
|
+
}
|
|
106
|
+
if (cqe->res != -ENOENT) {
|
|
107
|
+
r = 3;
|
|
108
|
+
fprintf(stderr,
|
|
109
|
+
"error: cqe %i: res=%i, but expected -ENOENT\n",
|
|
110
|
+
(int)cqe->user_data, (int)cqe->res);
|
|
111
|
+
}
|
|
112
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
113
|
+
|
|
114
|
+
close_iour:
|
|
115
|
+
io_uring_queue_exit(&ring);
|
|
116
|
+
close(snd_sock);
|
|
117
|
+
return r;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
int main(int argc, char *argv[])
|
|
121
|
+
{
|
|
122
|
+
int r;
|
|
123
|
+
char tmpdir[] = "/tmp/tmp.XXXXXX";
|
|
124
|
+
int rcv_sock;
|
|
125
|
+
struct sockaddr_un addr = {};
|
|
126
|
+
pid_t c;
|
|
127
|
+
int wstatus;
|
|
128
|
+
|
|
129
|
+
if (!mkdtemp(tmpdir)) {
|
|
130
|
+
perror("mkdtemp()");
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
rcv_sock = socket(AF_UNIX, SOCK_DGRAM, 0);
|
|
135
|
+
if (rcv_sock < 0) {
|
|
136
|
+
perror("socket(AF_UNIX)");
|
|
137
|
+
r = 1;
|
|
138
|
+
goto rmtmpdir;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
addr.sun_family = AF_UNIX;
|
|
142
|
+
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/sock", tmpdir);
|
|
143
|
+
|
|
144
|
+
r = bind(rcv_sock, (struct sockaddr *)&addr,
|
|
145
|
+
sizeof(addr));
|
|
146
|
+
if (r < 0) {
|
|
147
|
+
perror("bind()");
|
|
148
|
+
close(rcv_sock);
|
|
149
|
+
r = 1;
|
|
150
|
+
goto rmtmpdir;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
c = fork();
|
|
154
|
+
if (!c) {
|
|
155
|
+
close(rcv_sock);
|
|
156
|
+
|
|
157
|
+
r = chroot(tmpdir);
|
|
158
|
+
if (r) {
|
|
159
|
+
if (errno == EPERM) {
|
|
160
|
+
fprintf(stderr, "chroot not allowed, skip\n");
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
perror("chroot()");
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
r = try_sendmsg_async(addr.sun_path);
|
|
169
|
+
if (r < 0) {
|
|
170
|
+
/* system call failure */
|
|
171
|
+
r = 1;
|
|
172
|
+
} else if (r) {
|
|
173
|
+
/* test case failure */
|
|
174
|
+
r += 1;
|
|
175
|
+
}
|
|
176
|
+
return r;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (waitpid(c, &wstatus, 0) == (pid_t)-1) {
|
|
180
|
+
perror("waitpid()");
|
|
181
|
+
r = 1;
|
|
182
|
+
goto rmsock;
|
|
183
|
+
}
|
|
184
|
+
if (!WIFEXITED(wstatus)) {
|
|
185
|
+
fprintf(stderr, "child got terminated\n");
|
|
186
|
+
r = 1;
|
|
187
|
+
goto rmsock;
|
|
188
|
+
}
|
|
189
|
+
r = WEXITSTATUS(wstatus);
|
|
190
|
+
if (r)
|
|
191
|
+
fprintf(stderr, "error: Test failed\n");
|
|
192
|
+
rmsock:
|
|
193
|
+
close(rcv_sock);
|
|
194
|
+
unlink(addr.sun_path);
|
|
195
|
+
rmtmpdir:
|
|
196
|
+
rmdir(tmpdir);
|
|
197
|
+
return r;
|
|
198
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
/*
|
|
3
|
+
* Description: test wq sharing
|
|
4
|
+
*/
|
|
5
|
+
#include <errno.h>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <unistd.h>
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
#include <string.h>
|
|
10
|
+
#include <fcntl.h>
|
|
11
|
+
|
|
12
|
+
#include "liburing.h"
|
|
13
|
+
|
|
14
|
+
static int test_attach_invalid(int ringfd)
|
|
15
|
+
{
|
|
16
|
+
struct io_uring_params p;
|
|
17
|
+
struct io_uring ring;
|
|
18
|
+
int ret;
|
|
19
|
+
|
|
20
|
+
memset(&p, 0, sizeof(p));
|
|
21
|
+
p.flags = IORING_SETUP_ATTACH_WQ;
|
|
22
|
+
p.wq_fd = ringfd;
|
|
23
|
+
ret = io_uring_queue_init_params(1, &ring, &p);
|
|
24
|
+
if (ret != -EINVAL) {
|
|
25
|
+
fprintf(stderr, "Attach to zero: %d\n", ret);
|
|
26
|
+
goto err;
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
err:
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static int test_attach(int ringfd)
|
|
34
|
+
{
|
|
35
|
+
struct io_uring_params p;
|
|
36
|
+
struct io_uring ring2;
|
|
37
|
+
int ret;
|
|
38
|
+
|
|
39
|
+
memset(&p, 0, sizeof(p));
|
|
40
|
+
p.flags = IORING_SETUP_ATTACH_WQ;
|
|
41
|
+
p.wq_fd = ringfd;
|
|
42
|
+
ret = io_uring_queue_init_params(1, &ring2, &p);
|
|
43
|
+
if (ret == -EINVAL) {
|
|
44
|
+
fprintf(stdout, "Sharing not supported, skipping\n");
|
|
45
|
+
return 0;
|
|
46
|
+
} else if (ret) {
|
|
47
|
+
fprintf(stderr, "Attach to id: %d\n", ret);
|
|
48
|
+
goto err;
|
|
49
|
+
}
|
|
50
|
+
io_uring_queue_exit(&ring2);
|
|
51
|
+
return 0;
|
|
52
|
+
err:
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
int main(int argc, char *argv[])
|
|
57
|
+
{
|
|
58
|
+
struct io_uring ring;
|
|
59
|
+
int ret;
|
|
60
|
+
|
|
61
|
+
if (argc > 1)
|
|
62
|
+
return 0;
|
|
63
|
+
|
|
64
|
+
ret = io_uring_queue_init(8, &ring, 0);
|
|
65
|
+
if (ret) {
|
|
66
|
+
fprintf(stderr, "ring setup failed\n");
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* stdout is definitely not an io_uring descriptor */
|
|
71
|
+
ret = test_attach_invalid(2);
|
|
72
|
+
if (ret) {
|
|
73
|
+
fprintf(stderr, "test_attach_invalid failed\n");
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ret = test_attach(ring.ring_fd);
|
|
78
|
+
if (ret) {
|
|
79
|
+
fprintf(stderr, "test_attach failed\n");
|
|
80
|
+
return ret;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
|
2
|
+
#include <errno.h>
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <unistd.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
#include <fcntl.h>
|
|
8
|
+
#include <sys/types.h>
|
|
9
|
+
#include <sys/poll.h>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#include "helpers.h"
|
|
13
|
+
#include "liburing.h"
|
|
14
|
+
|
|
15
|
+
#define BUF_SIZE 4096
|
|
16
|
+
#define FILE_SIZE 1024
|
|
17
|
+
|
|
18
|
+
int main(int argc, char *argv[])
|
|
19
|
+
{
|
|
20
|
+
int ret, fd, save_errno;
|
|
21
|
+
struct io_uring ring;
|
|
22
|
+
struct io_uring_sqe *sqe;
|
|
23
|
+
struct io_uring_cqe *cqe;
|
|
24
|
+
struct iovec vec;
|
|
25
|
+
|
|
26
|
+
if (argc > 1)
|
|
27
|
+
return 0;
|
|
28
|
+
|
|
29
|
+
vec.iov_base = t_malloc(BUF_SIZE);
|
|
30
|
+
vec.iov_len = BUF_SIZE;
|
|
31
|
+
|
|
32
|
+
t_create_file(".short-read", FILE_SIZE);
|
|
33
|
+
|
|
34
|
+
fd = open(".short-read", O_RDONLY);
|
|
35
|
+
save_errno = errno;
|
|
36
|
+
unlink(".short-read");
|
|
37
|
+
errno = save_errno;
|
|
38
|
+
if (fd < 0) {
|
|
39
|
+
perror("file open");
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
ret = io_uring_queue_init(32, &ring, 0);
|
|
44
|
+
if (ret) {
|
|
45
|
+
fprintf(stderr, "queue init failed: %d\n", ret);
|
|
46
|
+
return ret;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
sqe = io_uring_get_sqe(&ring);
|
|
50
|
+
if (!sqe) {
|
|
51
|
+
fprintf(stderr, "sqe get failed\n");
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
io_uring_prep_readv(sqe, fd, &vec, 1, 0);
|
|
55
|
+
|
|
56
|
+
ret = io_uring_submit(&ring);
|
|
57
|
+
if (ret != 1) {
|
|
58
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ret = io_uring_wait_cqes(&ring, &cqe, 1, 0, 0);
|
|
63
|
+
if (ret) {
|
|
64
|
+
fprintf(stderr, "wait_cqe failed: %d\n", ret);
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (cqe->res != FILE_SIZE) {
|
|
69
|
+
fprintf(stderr, "Read failed: %d\n", cqe->res);
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
io_uring_cqe_seen(&ring, cqe);
|
|
74
|
+
return 0;
|
|
75
|
+
}
|