Skip to content

Commit 5283878

Browse files
isilenceaxboe
authored andcommitted
io_uring/net: don't alias send user pointer reads
We keep user pointers in an union, which could be a user buffer or a user pointer to msghdr. What is confusing is that it potenitally reads and assigns sqe->addr as one type but then uses it as another via the union. Even more, it's not even consistent across copy and zerocopy versions. Make send and sendmsg setup helpers read sqe->addr and treat it as the right type from the beginning. The end goal would be to get rid of the use of struct io_sr_msg::umsg for send requests as we only need it at the prep side. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/685d788605f5d78af18802fcabf61ba65cfd8002.1729607201.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent ad438d0 commit 5283878

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

io_uring/net.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ static int io_send_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe)
363363
u16 addr_len;
364364
int ret;
365365

366+
sr->buf = u64_to_user_ptr(READ_ONCE(sqe->addr));
367+
366368
if (READ_ONCE(sqe->__pad3[0]))
367369
return -EINVAL;
368370

@@ -390,11 +392,14 @@ static int io_send_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe)
390392
return 0;
391393
}
392394

393-
static int io_sendmsg_setup(struct io_kiocb *req)
395+
static int io_sendmsg_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe)
394396
{
397+
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
395398
struct io_async_msghdr *kmsg = req->async_data;
396399
int ret;
397400

401+
sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr));
402+
398403
ret = io_sendmsg_copy_hdr(req, kmsg);
399404
if (!ret)
400405
req->flags |= REQ_F_NEED_CLEANUP;
@@ -414,7 +419,6 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
414419
return -EINVAL;
415420
}
416421

417-
sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr));
418422
sr->len = READ_ONCE(sqe->len);
419423
sr->flags = READ_ONCE(sqe->ioprio);
420424
if (sr->flags & ~SENDMSG_FLAGS)
@@ -440,7 +444,7 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
440444
return -ENOMEM;
441445
if (req->opcode != IORING_OP_SENDMSG)
442446
return io_send_setup(req, sqe);
443-
return io_sendmsg_setup(req);
447+
return io_sendmsg_setup(req, sqe);
444448
}
445449

446450
static void io_req_msg_cleanup(struct io_kiocb *req,
@@ -1262,7 +1266,6 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
12621266
return -EINVAL;
12631267
}
12641268

1265-
zc->buf = u64_to_user_ptr(READ_ONCE(sqe->addr));
12661269
zc->len = READ_ONCE(sqe->len);
12671270
zc->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL | MSG_ZEROCOPY;
12681271
zc->buf_index = READ_ONCE(sqe->buf_index);
@@ -1277,7 +1280,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
12771280
return -ENOMEM;
12781281
if (req->opcode != IORING_OP_SENDMSG_ZC)
12791282
return io_send_setup(req, sqe);
1280-
return io_sendmsg_setup(req);
1283+
return io_sendmsg_setup(req, sqe);
12811284
}
12821285

12831286
static int io_sg_from_iter_iovec(struct sk_buff *skb,

0 commit comments

Comments
 (0)