* [PATCH] io_uring/net: fix iter retargeting for selected buf
@ 2023-09-14 15:51 Pavel Begunkov
2023-09-14 16:05 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2023-09-14 15:51 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence, syzbot+a4c6e5ef999b68b26ed1
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: [email protected]
Reported-by: [email protected]
Fixes: 0455d4ccec548 ("io_uring: add POLL_FIRST support for send/sendmsg and recv/recvmsg")
Signed-off-by: Pavel Begunkov <[email protected]>
---
Can be cleaned up if we rely on UBUF, but it's easier to backport
this way
io_uring/net.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/io_uring/net.c b/io_uring/net.c
index 3d07bf79c1e0..7a8e298af81b 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -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)
--
2.41.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] io_uring/net: fix iter retargeting for selected buf
2023-09-14 15:51 [PATCH] io_uring/net: fix iter retargeting for selected buf Pavel Begunkov
@ 2023-09-14 16:05 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2023-09-14 16:05 UTC (permalink / raw)
To: io-uring, Pavel Begunkov; +Cc: syzbot+a4c6e5ef999b68b26ed1
On Thu, 14 Sep 2023 16:51:09 +0100, Pavel Begunkov wrote:
> 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.
>
>
Applied, thanks!
[1/1] io_uring/net: fix iter retargeting for selected buf
commit: 78a6953889b1912106bfb6e59ead30a79da90e29
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-14 16:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-14 15:51 [PATCH] io_uring/net: fix iter retargeting for selected buf Pavel Begunkov
2023-09-14 16:05 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox