Skip to content

Commit c21a802

Browse files
isilenceaxboe
authored andcommitted
io_uring/net: fix iter retargeting for selected buf
When using selected buffer feature, io_uring delays data iter setup until later. If io_setup_async_msg() is called before that it might see not correctly setup iterator. Pre-init nr_segs and judge from its state whether we repointing. Cc: stable@vger.kernel.org Reported-by: syzbot+a4c6e5ef999b68b26ed1@syzkaller.appspotmail.com Fixes: 0455d4c ("io_uring: add POLL_FIRST support for send/sendmsg and recv/recvmsg") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/0000000000002770be06053c7757@google.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 0bb80ec commit c21a802

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

io_uring/net.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ static int io_setup_async_msg(struct io_kiocb *req,
183183
memcpy(async_msg, kmsg, sizeof(*kmsg));
184184
if (async_msg->msg.msg_name)
185185
async_msg->msg.msg_name = &async_msg->addr;
186+
187+
if ((req->flags & REQ_F_BUFFER_SELECT) && !async_msg->msg.msg_iter.nr_segs)
188+
return -EAGAIN;
189+
186190
/* if were using fast_iov, set it to the new one */
187191
if (iter_is_iovec(&kmsg->msg.msg_iter) && !kmsg->free_iov) {
188192
size_t fast_idx = iter_iov(&kmsg->msg.msg_iter) - kmsg->fast_iov;
@@ -542,6 +546,7 @@ static int io_recvmsg_copy_hdr(struct io_kiocb *req,
542546
struct io_async_msghdr *iomsg)
543547
{
544548
iomsg->msg.msg_name = &iomsg->addr;
549+
iomsg->msg.msg_iter.nr_segs = 0;
545550

546551
#ifdef CONFIG_COMPAT
547552
if (req->ctx->compat)

0 commit comments

Comments
 (0)