io_uring/net: fix iter retargeting for selected buf
authorPavel Begunkov <asml.silence@gmail.com>
Thu, 14 Sep 2023 15:51:09 +0000 (16:51 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 14 Sep 2023 16:12:55 +0000 (10:12 -0600)
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: 0455d4ccec548 ("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>
io_uring/net.c

index 3d07bf7..7a8e298 100644 (file)
@@ -183,6 +183,10 @@ static int io_setup_async_msg(struct io_kiocb *req,
        memcpy(async_msg, kmsg, sizeof(*kmsg));
        if (async_msg->msg.msg_name)
                async_msg->msg.msg_name = &async_msg->addr;
+
+       if ((req->flags & REQ_F_BUFFER_SELECT) && !async_msg->msg.msg_iter.nr_segs)
+               return -EAGAIN;
+
        /* if were using fast_iov, set it to the new one */
        if (iter_is_iovec(&kmsg->msg.msg_iter) && !kmsg->free_iov) {
                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,
                               struct io_async_msghdr *iomsg)
 {
        iomsg->msg.msg_name = &iomsg->addr;
+       iomsg->msg.msg_iter.nr_segs = 0;
 
 #ifdef CONFIG_COMPAT
        if (req->ctx->compat)