polyphony 0.85 → 0.86
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/ext/polyphony/io_extensions.c +2 -3
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +1 -1
- data/test/test_backend.rb +1 -1
- data/test/test_signal.rb +3 -3
- data/vendor/liburing/.github/pull_request_template.md +86 -0
- data/vendor/liburing/.github/workflows/build.yml +85 -0
- data/vendor/liburing/.github/workflows/shellcheck.yml +20 -0
- data/vendor/liburing/.gitignore +149 -0
- data/vendor/liburing/COPYING +502 -0
- data/vendor/liburing/COPYING.GPL +339 -0
- data/vendor/liburing/LICENSE +7 -0
- data/vendor/liburing/Makefile +82 -0
- data/vendor/liburing/Makefile.common +5 -0
- data/vendor/liburing/Makefile.quiet +11 -0
- data/vendor/liburing/README +46 -0
- data/vendor/liburing/configure +486 -0
- data/vendor/liburing/debian/README.Debian +7 -0
- data/vendor/liburing/debian/changelog +27 -0
- data/vendor/liburing/debian/compat +1 -0
- data/vendor/liburing/debian/control +48 -0
- data/vendor/liburing/debian/copyright +49 -0
- data/vendor/liburing/debian/liburing-dev.install +4 -0
- data/vendor/liburing/debian/liburing-dev.manpages +6 -0
- data/vendor/liburing/debian/liburing1-udeb.install +1 -0
- data/vendor/liburing/debian/liburing1.install +1 -0
- data/vendor/liburing/debian/liburing1.symbols +32 -0
- data/vendor/liburing/debian/patches/series +1 -0
- data/vendor/liburing/debian/rules +81 -0
- data/vendor/liburing/debian/source/format +1 -0
- data/vendor/liburing/debian/source/local-options +2 -0
- data/vendor/liburing/debian/source/options +1 -0
- data/vendor/liburing/debian/watch +3 -0
- data/vendor/liburing/examples/Makefile +38 -0
- data/vendor/liburing/examples/io_uring-cp.c +282 -0
- data/vendor/liburing/examples/io_uring-test.c +112 -0
- data/vendor/liburing/examples/link-cp.c +193 -0
- data/vendor/liburing/examples/ucontext-cp.c +273 -0
- data/vendor/liburing/liburing.pc.in +12 -0
- data/vendor/liburing/liburing.spec +66 -0
- data/vendor/liburing/make-debs.sh +53 -0
- data/vendor/liburing/man/io_uring.7 +754 -0
- data/vendor/liburing/man/io_uring_cq_advance.3 +35 -0
- data/vendor/liburing/man/io_uring_cq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_cqe_get_data.3 +34 -0
- data/vendor/liburing/man/io_uring_cqe_seen.3 +32 -0
- data/vendor/liburing/man/io_uring_enter.2 +1483 -0
- data/vendor/liburing/man/io_uring_free_probe.3 +24 -0
- data/vendor/liburing/man/io_uring_get_probe.3 +29 -0
- data/vendor/liburing/man/io_uring_get_sqe.3 +38 -0
- data/vendor/liburing/man/io_uring_opcode_supported.3 +29 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +58 -0
- data/vendor/liburing/man/io_uring_prep_read.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_read_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_readv.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_readv2.3 +79 -0
- data/vendor/liburing/man/io_uring_prep_write.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_write_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_writev.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_writev2.3 +78 -0
- data/vendor/liburing/man/io_uring_queue_exit.3 +27 -0
- data/vendor/liburing/man/io_uring_queue_init.3 +44 -0
- data/vendor/liburing/man/io_uring_register.2 +688 -0
- data/vendor/liburing/man/io_uring_register_buffers.3 +41 -0
- data/vendor/liburing/man/io_uring_register_files.3 +35 -0
- data/vendor/liburing/man/io_uring_setup.2 +534 -0
- data/vendor/liburing/man/io_uring_sq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_sq_space_left.3 +25 -0
- data/vendor/liburing/man/io_uring_sqe_set_data.3 +30 -0
- data/vendor/liburing/man/io_uring_sqe_set_flags.3 +60 -0
- data/vendor/liburing/man/io_uring_sqring_wait.3 +30 -0
- data/vendor/liburing/man/io_uring_submit.3 +29 -0
- data/vendor/liburing/man/io_uring_submit_and_wait.3 +34 -0
- data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +49 -0
- data/vendor/liburing/man/io_uring_unregister_buffers.3 +26 -0
- data/vendor/liburing/man/io_uring_unregister_files.3 +26 -0
- data/vendor/liburing/man/io_uring_wait_cqe.3 +33 -0
- data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +36 -0
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +39 -0
- data/vendor/liburing/man/io_uring_wait_cqes.3 +46 -0
- data/vendor/liburing/src/Makefile +89 -0
- data/vendor/liburing/src/arch/aarch64/syscall.h +95 -0
- data/vendor/liburing/src/arch/generic/lib.h +21 -0
- data/vendor/liburing/src/arch/generic/syscall.h +87 -0
- data/vendor/liburing/src/arch/syscall-defs.h +67 -0
- data/vendor/liburing/src/arch/x86/lib.h +32 -0
- data/vendor/liburing/src/arch/x86/syscall.h +160 -0
- data/vendor/liburing/src/include/liburing/barrier.h +81 -0
- data/vendor/liburing/src/include/liburing/io_uring.h +442 -0
- data/vendor/liburing/src/include/liburing.h +921 -0
- data/vendor/liburing/src/int_flags.h +8 -0
- data/vendor/liburing/src/lib.h +57 -0
- data/vendor/liburing/src/liburing.map +53 -0
- data/vendor/liburing/src/nolibc.c +48 -0
- data/vendor/liburing/src/queue.c +403 -0
- data/vendor/liburing/src/register.c +293 -0
- data/vendor/liburing/src/setup.c +332 -0
- data/vendor/liburing/src/syscall.c +47 -0
- data/vendor/liburing/src/syscall.h +103 -0
- data/vendor/liburing/test/232c93d07b74-test.c +306 -0
- data/vendor/liburing/test/35fa71a030ca-test.c +329 -0
- data/vendor/liburing/test/500f9fbadef8-test.c +89 -0
- data/vendor/liburing/test/7ad0e4b2f83c-test.c +93 -0
- data/vendor/liburing/test/8a9973408177-test.c +106 -0
- data/vendor/liburing/test/917257daa0fe-test.c +53 -0
- data/vendor/liburing/test/Makefile +244 -0
- data/vendor/liburing/test/a0908ae19763-test.c +58 -0
- data/vendor/liburing/test/a4c0b3decb33-test.c +180 -0
- data/vendor/liburing/test/accept-link.c +254 -0
- data/vendor/liburing/test/accept-reuse.c +164 -0
- data/vendor/liburing/test/accept-test.c +79 -0
- data/vendor/liburing/test/accept.c +477 -0
- data/vendor/liburing/test/across-fork.c +283 -0
- data/vendor/liburing/test/b19062a56726-test.c +53 -0
- data/vendor/liburing/test/b5837bd5311d-test.c +77 -0
- data/vendor/liburing/test/ce593a6c480a-test.c +136 -0
- data/vendor/liburing/test/close-opath.c +122 -0
- data/vendor/liburing/test/config +10 -0
- data/vendor/liburing/test/connect.c +398 -0
- data/vendor/liburing/test/cq-full.c +96 -0
- data/vendor/liburing/test/cq-overflow.c +294 -0
- data/vendor/liburing/test/cq-peek-batch.c +102 -0
- data/vendor/liburing/test/cq-ready.c +94 -0
- data/vendor/liburing/test/cq-size.c +64 -0
- data/vendor/liburing/test/d4ae271dfaae-test.c +96 -0
- data/vendor/liburing/test/d77a67ed5f27-test.c +65 -0
- data/vendor/liburing/test/defer.c +307 -0
- data/vendor/liburing/test/double-poll-crash.c +185 -0
- data/vendor/liburing/test/drop-submit.c +92 -0
- data/vendor/liburing/test/eeed8b54e0df-test.c +114 -0
- data/vendor/liburing/test/empty-eownerdead.c +45 -0
- data/vendor/liburing/test/eventfd-disable.c +151 -0
- data/vendor/liburing/test/eventfd-reg.c +76 -0
- data/vendor/liburing/test/eventfd-ring.c +97 -0
- data/vendor/liburing/test/eventfd.c +112 -0
- data/vendor/liburing/test/exec-target.c +6 -0
- data/vendor/liburing/test/exit-no-cleanup.c +117 -0
- data/vendor/liburing/test/fadvise.c +202 -0
- data/vendor/liburing/test/fallocate.c +249 -0
- data/vendor/liburing/test/fc2a85cb02ef-test.c +131 -0
- data/vendor/liburing/test/file-register.c +858 -0
- data/vendor/liburing/test/file-update.c +173 -0
- data/vendor/liburing/test/file-verify.c +629 -0
- data/vendor/liburing/test/files-exit-hang-poll.c +128 -0
- data/vendor/liburing/test/files-exit-hang-timeout.c +134 -0
- data/vendor/liburing/test/fixed-link.c +90 -0
- data/vendor/liburing/test/fpos.c +252 -0
- data/vendor/liburing/test/fsync.c +224 -0
- data/vendor/liburing/test/hardlink.c +136 -0
- data/vendor/liburing/test/helpers.c +135 -0
- data/vendor/liburing/test/helpers.h +67 -0
- data/vendor/liburing/test/io-cancel.c +550 -0
- data/vendor/liburing/test/io_uring_enter.c +296 -0
- data/vendor/liburing/test/io_uring_register.c +676 -0
- data/vendor/liburing/test/io_uring_setup.c +192 -0
- data/vendor/liburing/test/iopoll.c +372 -0
- data/vendor/liburing/test/lfs-openat-write.c +119 -0
- data/vendor/liburing/test/lfs-openat.c +275 -0
- data/vendor/liburing/test/link-timeout.c +1107 -0
- data/vendor/liburing/test/link.c +496 -0
- data/vendor/liburing/test/link_drain.c +229 -0
- data/vendor/liburing/test/madvise.c +195 -0
- data/vendor/liburing/test/mkdir.c +108 -0
- data/vendor/liburing/test/msg-ring.c +234 -0
- data/vendor/liburing/test/multicqes_drain.c +387 -0
- data/vendor/liburing/test/nop-all-sizes.c +99 -0
- data/vendor/liburing/test/nop.c +115 -0
- data/vendor/liburing/test/open-close.c +261 -0
- data/vendor/liburing/test/openat2.c +308 -0
- data/vendor/liburing/test/personality.c +204 -0
- data/vendor/liburing/test/pipe-eof.c +83 -0
- data/vendor/liburing/test/pipe-reuse.c +105 -0
- data/vendor/liburing/test/poll-cancel-ton.c +135 -0
- data/vendor/liburing/test/poll-cancel.c +228 -0
- data/vendor/liburing/test/poll-link.c +230 -0
- data/vendor/liburing/test/poll-many.c +208 -0
- data/vendor/liburing/test/poll-mshot-update.c +273 -0
- data/vendor/liburing/test/poll-ring.c +48 -0
- data/vendor/liburing/test/poll-v-poll.c +353 -0
- data/vendor/liburing/test/poll.c +109 -0
- data/vendor/liburing/test/pollfree.c +426 -0
- data/vendor/liburing/test/probe.c +135 -0
- data/vendor/liburing/test/read-write.c +876 -0
- data/vendor/liburing/test/register-restrictions.c +633 -0
- data/vendor/liburing/test/rename.c +135 -0
- data/vendor/liburing/test/ring-leak.c +173 -0
- data/vendor/liburing/test/ring-leak2.c +249 -0
- data/vendor/liburing/test/rsrc_tags.c +449 -0
- data/vendor/liburing/test/runtests-loop.sh +16 -0
- data/vendor/liburing/test/runtests.sh +170 -0
- data/vendor/liburing/test/rw_merge_test.c +97 -0
- data/vendor/liburing/test/self.c +91 -0
- data/vendor/liburing/test/send_recv.c +286 -0
- data/vendor/liburing/test/send_recvmsg.c +345 -0
- data/vendor/liburing/test/sendmsg_fs_cve.c +200 -0
- data/vendor/liburing/test/shared-wq.c +84 -0
- data/vendor/liburing/test/short-read.c +75 -0
- data/vendor/liburing/test/shutdown.c +165 -0
- data/vendor/liburing/test/sigfd-deadlock.c +74 -0
- data/vendor/liburing/test/skip-cqe.c +429 -0
- data/vendor/liburing/test/socket-rw-eagain.c +158 -0
- data/vendor/liburing/test/socket-rw-offset.c +157 -0
- data/vendor/liburing/test/socket-rw.c +145 -0
- data/vendor/liburing/test/splice.c +512 -0
- data/vendor/liburing/test/sq-full-cpp.cc +45 -0
- data/vendor/liburing/test/sq-full.c +45 -0
- data/vendor/liburing/test/sq-poll-dup.c +204 -0
- data/vendor/liburing/test/sq-poll-kthread.c +169 -0
- data/vendor/liburing/test/sq-poll-share.c +137 -0
- data/vendor/liburing/test/sq-space_left.c +159 -0
- data/vendor/liburing/test/sqpoll-cancel-hang.c +157 -0
- data/vendor/liburing/test/sqpoll-disable-exit.c +196 -0
- data/vendor/liburing/test/sqpoll-exit-hang.c +78 -0
- data/vendor/liburing/test/sqpoll-sleep.c +69 -0
- data/vendor/liburing/test/statx.c +172 -0
- data/vendor/liburing/test/stdout.c +232 -0
- data/vendor/liburing/test/submit-link-fail.c +154 -0
- data/vendor/liburing/test/submit-reuse.c +239 -0
- data/vendor/liburing/test/symlink.c +116 -0
- data/vendor/liburing/test/teardowns.c +58 -0
- data/vendor/liburing/test/thread-exit.c +143 -0
- data/vendor/liburing/test/timeout-new.c +252 -0
- data/vendor/liburing/test/timeout-overflow.c +204 -0
- data/vendor/liburing/test/timeout.c +1523 -0
- data/vendor/liburing/test/unlink.c +112 -0
- data/vendor/liburing/test/wakeup-hang.c +162 -0
- metadata +223 -2
@@ -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,200 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* repro-CVE-2020-29373 -- Reproducer for CVE-2020-29373.
|
4
|
+
*
|
5
|
+
* Copyright (c) 2021 SUSE
|
6
|
+
* Author: Nicolai Stange <nstange@suse.de>
|
7
|
+
*
|
8
|
+
* This program is free software; you can redistribute it and/or
|
9
|
+
* modify it under the terms of the GNU General Public License
|
10
|
+
* as published by the Free Software Foundation; either version 2
|
11
|
+
* of the License, or (at your option) any later version.
|
12
|
+
*
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
* GNU General Public License for more details.
|
17
|
+
*
|
18
|
+
* You should have received a copy of the GNU General Public License
|
19
|
+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include <unistd.h>
|
23
|
+
#include <stdio.h>
|
24
|
+
#include <string.h>
|
25
|
+
#include <sys/mman.h>
|
26
|
+
#include <sys/socket.h>
|
27
|
+
#include <sys/un.h>
|
28
|
+
#include <fcntl.h>
|
29
|
+
#include <errno.h>
|
30
|
+
#include <inttypes.h>
|
31
|
+
#include <stdlib.h>
|
32
|
+
#include <sys/types.h>
|
33
|
+
#include <sys/wait.h>
|
34
|
+
#include "liburing.h"
|
35
|
+
|
36
|
+
/*
|
37
|
+
* This attempts to make the kernel issue a sendmsg() to
|
38
|
+
* path from io_uring's async io_sq_wq_submit_work().
|
39
|
+
*
|
40
|
+
* Unfortunately, IOSQE_ASYNC is available only from kernel version
|
41
|
+
* 5.6 onwards. To still force io_uring to process the request
|
42
|
+
* asynchronously from io_sq_wq_submit_work(), queue a couple of
|
43
|
+
* auxiliary requests all failing with EAGAIN before. This is
|
44
|
+
* implemented by writing repeatedly to an auxiliary O_NONBLOCK
|
45
|
+
* AF_UNIX socketpair with a small SO_SNDBUF.
|
46
|
+
*/
|
47
|
+
static int try_sendmsg_async(const char * const path)
|
48
|
+
{
|
49
|
+
int snd_sock, r;
|
50
|
+
struct io_uring ring;
|
51
|
+
char sbuf[16] = {};
|
52
|
+
struct iovec siov = { .iov_base = &sbuf, .iov_len = sizeof(sbuf) };
|
53
|
+
struct sockaddr_un addr = {};
|
54
|
+
struct msghdr msg = {
|
55
|
+
.msg_name = &addr,
|
56
|
+
.msg_namelen = sizeof(addr),
|
57
|
+
.msg_iov = &siov,
|
58
|
+
.msg_iovlen = 1,
|
59
|
+
};
|
60
|
+
struct io_uring_cqe *cqe;
|
61
|
+
struct io_uring_sqe *sqe;
|
62
|
+
|
63
|
+
snd_sock = socket(AF_UNIX, SOCK_DGRAM, 0);
|
64
|
+
if (snd_sock < 0) {
|
65
|
+
perror("socket(AF_UNIX)");
|
66
|
+
return -1;
|
67
|
+
}
|
68
|
+
|
69
|
+
addr.sun_family = AF_UNIX;
|
70
|
+
strcpy(addr.sun_path, path);
|
71
|
+
|
72
|
+
r = io_uring_queue_init(512, &ring, 0);
|
73
|
+
if (r < 0) {
|
74
|
+
fprintf(stderr, "ring setup failed: %d\n", r);
|
75
|
+
goto close_iour;
|
76
|
+
}
|
77
|
+
|
78
|
+
sqe = io_uring_get_sqe(&ring);
|
79
|
+
if (!sqe) {
|
80
|
+
fprintf(stderr, "get sqe failed\n");
|
81
|
+
r = -EFAULT;
|
82
|
+
goto close_iour;
|
83
|
+
}
|
84
|
+
|
85
|
+
/* the actual one supposed to fail with -ENOENT. */
|
86
|
+
io_uring_prep_sendmsg(sqe, snd_sock, &msg, 0);
|
87
|
+
sqe->flags = IOSQE_ASYNC;
|
88
|
+
sqe->user_data = 255;
|
89
|
+
|
90
|
+
r = io_uring_submit(&ring);
|
91
|
+
if (r != 1) {
|
92
|
+
fprintf(stderr, "sqe submit failed: %d\n", r);
|
93
|
+
r = -EFAULT;
|
94
|
+
goto close_iour;
|
95
|
+
}
|
96
|
+
|
97
|
+
r = io_uring_wait_cqe(&ring, &cqe);
|
98
|
+
if (r < 0) {
|
99
|
+
fprintf(stderr, "wait completion %d\n", r);
|
100
|
+
r = -EFAULT;
|
101
|
+
goto close_iour;
|
102
|
+
}
|
103
|
+
if (cqe->user_data != 255) {
|
104
|
+
fprintf(stderr, "user data %d\n", r);
|
105
|
+
r = -EFAULT;
|
106
|
+
goto close_iour;
|
107
|
+
}
|
108
|
+
if (cqe->res != -ENOENT) {
|
109
|
+
r = 3;
|
110
|
+
fprintf(stderr,
|
111
|
+
"error: cqe %i: res=%i, but expected -ENOENT\n",
|
112
|
+
(int)cqe->user_data, (int)cqe->res);
|
113
|
+
}
|
114
|
+
io_uring_cqe_seen(&ring, cqe);
|
115
|
+
|
116
|
+
close_iour:
|
117
|
+
io_uring_queue_exit(&ring);
|
118
|
+
close(snd_sock);
|
119
|
+
return r;
|
120
|
+
}
|
121
|
+
|
122
|
+
int main(int argc, char *argv[])
|
123
|
+
{
|
124
|
+
int r;
|
125
|
+
char tmpdir[] = "/tmp/tmp.XXXXXX";
|
126
|
+
int rcv_sock;
|
127
|
+
struct sockaddr_un addr = {};
|
128
|
+
pid_t c;
|
129
|
+
int wstatus;
|
130
|
+
|
131
|
+
if (!mkdtemp(tmpdir)) {
|
132
|
+
perror("mkdtemp()");
|
133
|
+
return 1;
|
134
|
+
}
|
135
|
+
|
136
|
+
rcv_sock = socket(AF_UNIX, SOCK_DGRAM, 0);
|
137
|
+
if (rcv_sock < 0) {
|
138
|
+
perror("socket(AF_UNIX)");
|
139
|
+
r = 1;
|
140
|
+
goto rmtmpdir;
|
141
|
+
}
|
142
|
+
|
143
|
+
addr.sun_family = AF_UNIX;
|
144
|
+
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/sock", tmpdir);
|
145
|
+
|
146
|
+
r = bind(rcv_sock, (struct sockaddr *)&addr,
|
147
|
+
sizeof(addr));
|
148
|
+
if (r < 0) {
|
149
|
+
perror("bind()");
|
150
|
+
close(rcv_sock);
|
151
|
+
r = 1;
|
152
|
+
goto rmtmpdir;
|
153
|
+
}
|
154
|
+
|
155
|
+
c = fork();
|
156
|
+
if (!c) {
|
157
|
+
close(rcv_sock);
|
158
|
+
|
159
|
+
r = chroot(tmpdir);
|
160
|
+
if (r) {
|
161
|
+
if (errno == EPERM) {
|
162
|
+
fprintf(stderr, "chroot not allowed, skip\n");
|
163
|
+
return 0;
|
164
|
+
}
|
165
|
+
|
166
|
+
perror("chroot()");
|
167
|
+
return 1;
|
168
|
+
}
|
169
|
+
|
170
|
+
r = try_sendmsg_async(addr.sun_path);
|
171
|
+
if (r < 0) {
|
172
|
+
/* system call failure */
|
173
|
+
r = 1;
|
174
|
+
} else if (r) {
|
175
|
+
/* test case failure */
|
176
|
+
r += 1;
|
177
|
+
}
|
178
|
+
return r;
|
179
|
+
}
|
180
|
+
|
181
|
+
if (waitpid(c, &wstatus, 0) == (pid_t)-1) {
|
182
|
+
perror("waitpid()");
|
183
|
+
r = 1;
|
184
|
+
goto rmsock;
|
185
|
+
}
|
186
|
+
if (!WIFEXITED(wstatus)) {
|
187
|
+
fprintf(stderr, "child got terminated\n");
|
188
|
+
r = 1;
|
189
|
+
goto rmsock;
|
190
|
+
}
|
191
|
+
r = WEXITSTATUS(wstatus);
|
192
|
+
if (r)
|
193
|
+
fprintf(stderr, "error: Test failed\n");
|
194
|
+
rmsock:
|
195
|
+
close(rcv_sock);
|
196
|
+
unlink(addr.sun_path);
|
197
|
+
rmtmpdir:
|
198
|
+
rmdir(tmpdir);
|
199
|
+
return r;
|
200
|
+
}
|
@@ -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 <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
|
+
}
|