Skip to content

Commit

Permalink
io_uring/net: save msghdr->msg_control for retries
Browse files Browse the repository at this point in the history
Commit cac9e44 upstream.

If the application sets ->msg_control and we have to later retry this
command, or if it got queued with IOSQE_ASYNC to begin with, then we
need to retain the original msg_control value. This is due to the net
stack overwriting this field with an in-kernel pointer, to copy it
in. Hitting that path for the second time will now fail the copy from
user, as it's attempting to copy from a non-user address.

Cc: stable@vger.kernel.org # 5.10+
Link: axboe/liburing#880
Reported-and-tested-by: Marek Majkowski <marek@cloudflare.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 34a7e5021a437bf813e1b52fc9043b43d48e2325)
Signed-off-by: Jack Vogel <jack.vogel@oracle.com>
  • Loading branch information
axboe authored and jfvogel committed Jun 29, 2023
1 parent a0a666f commit 3d0de20
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion io_uring/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ struct io_sr_msg {
size_t len;
size_t done_io;
struct io_buffer *kbuf;
void __user *msg_control;
};

struct io_open {
Expand Down Expand Up @@ -4864,10 +4865,16 @@ static int io_setup_async_msg(struct io_kiocb *req,
static int io_sendmsg_copy_hdr(struct io_kiocb *req,
struct io_async_msghdr *iomsg)
{
struct io_sr_msg *sr = &req->sr_msg;
int ret;

iomsg->msg.msg_name = &iomsg->addr;
iomsg->free_iov = iomsg->fast_iov;
return sendmsg_copy_msghdr(&iomsg->msg, req->sr_msg.umsg,
ret = sendmsg_copy_msghdr(&iomsg->msg, req->sr_msg.umsg,
req->sr_msg.msg_flags, &iomsg->free_iov);
/* save msg_control as sys_sendmsg() overwrites it */
sr->msg_control = iomsg->msg.msg_control;
return ret;
}

static int io_sendmsg_prep_async(struct io_kiocb *req)
Expand Down Expand Up @@ -4924,6 +4931,8 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
if (ret)
return ret;
kmsg = &iomsg;
} else {
kmsg->msg.msg_control = sr->msg_control;
}

flags = req->sr_msg.msg_flags;
Expand Down

0 comments on commit 3d0de20

Please sign in to comment.