Skip to content

Commit cac9e44

Browse files
committed
io_uring/net: save msghdr->msg_control for retries
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: [email protected] # 5.10+ Link: axboe/liburing#880 Reported-and-tested-by: Marek Majkowski <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b6dad51 commit cac9e44

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

io_uring/net.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct io_sr_msg {
6565
u16 addr_len;
6666
u16 buf_group;
6767
void __user *addr;
68+
void __user *msg_control;
6869
/* used only for send zerocopy */
6970
struct io_kiocb *notif;
7071
};
@@ -195,11 +196,15 @@ static int io_sendmsg_copy_hdr(struct io_kiocb *req,
195196
struct io_async_msghdr *iomsg)
196197
{
197198
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
199+
int ret;
198200

199201
iomsg->msg.msg_name = &iomsg->addr;
200202
iomsg->free_iov = iomsg->fast_iov;
201-
return sendmsg_copy_msghdr(&iomsg->msg, sr->umsg, sr->msg_flags,
203+
ret = sendmsg_copy_msghdr(&iomsg->msg, sr->umsg, sr->msg_flags,
202204
&iomsg->free_iov);
205+
/* save msg_control as sys_sendmsg() overwrites it */
206+
sr->msg_control = iomsg->msg.msg_control;
207+
return ret;
203208
}
204209

205210
int io_send_prep_async(struct io_kiocb *req)
@@ -297,6 +302,7 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
297302

298303
if (req_has_async_data(req)) {
299304
kmsg = req->async_data;
305+
kmsg->msg.msg_control = sr->msg_control;
300306
} else {
301307
ret = io_sendmsg_copy_hdr(req, &iomsg);
302308
if (ret)

0 commit comments

Comments
 (0)