Skip to content

Commit 79996b4

Browse files
krismanaxboe
authored andcommitted
io_uring: Require zeroed sqe->len on provided-buffers send
When sending from a provided buffer, we set sr->len to be the smallest between the actual buffer size and sqe->len. But, now that we disconnect the buffer from the submission request, we can get in a situation where the buffers and requests mismatch, and only part of a buffer gets sent. Assume: * buf[1]->len = 128; buf[2]->len = 256 * sqe[1]->len = 128; sqe[2]->len = 256 If sqe1 runs first, it picks buff[1] and it's all good. But, if sqe[2] runs first, sqe[1] picks buff[2], and the last half of buff[2] is never sent. While arguably the use-case of different-length sends is questionable, it has already raised confusion with potential users of this feature. Let's make the interface less tricky by forcing the length to only come from the buffer ring entry itself. Fixes: ac5f71a ("io_uring/net: add provided buffer support for IORING_OP_SEND") Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 19352a1 commit 79996b4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

io_uring/net.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
423423
sr->buf_group = req->buf_index;
424424
req->buf_list = NULL;
425425
}
426+
if (req->flags & REQ_F_BUFFER_SELECT && sr->len)
427+
return -EINVAL;
426428

427429
#ifdef CONFIG_COMPAT
428430
if (req->ctx->compat)
@@ -586,7 +588,7 @@ int io_send(struct io_kiocb *req, unsigned int issue_flags)
586588
if (io_do_buffer_select(req)) {
587589
struct buf_sel_arg arg = {
588590
.iovs = &kmsg->fast_iov,
589-
.max_len = min_not_zero(sr->len, INT_MAX),
591+
.max_len = INT_MAX,
590592
.nr_iovs = 1,
591593
.mode = KBUF_MODE_EXPAND,
592594
};

0 commit comments

Comments
 (0)