summaryrefslogtreecommitdiff
path: root/io_uring
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-09-26 07:08:10 -0600
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-10-10 12:01:06 +0200
commit83fde8356b410bd244f83ff3517059b34e112fb4 (patch)
tree7882cdbad958428e504f9486ee61db9f2a859ef0 /io_uring
parent540138377b22f601f06f55ebfa3ca171dcab471a (diff)
downloadlinux-83fde8356b410bd244f83ff3517059b34e112fb4.tar.gz
linux-83fde8356b410bd244f83ff3517059b34e112fb4.tar.bz2
linux-83fde8356b410bd244f83ff3517059b34e112fb4.zip
io_uring/net: harden multishot termination case for recv
commit c314094cb4cfa6fc5a17f4881ead2dfebfa717a7 upstream. If the recv returns zero, or an error, then it doesn't matter if more data has already been received for this buffer. A condition like that should terminate the multishot receive. Rather than pass in the collected return value, pass in whether to terminate or keep the recv going separately. Note that this isn't a bug right now, as the only way to get there is via setting MSG_WAITALL with multishot receive. And if an application does that, then -EINVAL is returned anyway. But it seems like an easy bug to introduce, so let's make it a bit more explicit. Link: https://github.com/axboe/liburing/issues/1246 Cc: stable@vger.kernel.org Fixes: b3fdea6ecb55 ("io_uring: multishot recv") Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'io_uring')
-rw-r--r--io_uring/net.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/io_uring/net.c b/io_uring/net.c
index 09bb82bc209a..a70bbd4bd7cb 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1116,6 +1116,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
int ret, min_ret = 0;
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
size_t len = sr->len;
+ bool mshot_finished;
if (!(req->flags & REQ_F_POLLED) &&
(sr->flags & IORING_RECVSEND_POLL_FIRST))
@@ -1170,6 +1171,7 @@ out_free:
req_set_fail(req);
}
+ mshot_finished = ret <= 0;
if (ret > 0)
ret += sr->done_io;
else if (sr->done_io)
@@ -1177,7 +1179,7 @@ out_free:
else
io_kbuf_recycle(req, issue_flags);
- if (!io_recv_finish(req, &ret, kmsg, ret <= 0, issue_flags))
+ if (!io_recv_finish(req, &ret, kmsg, mshot_finished, issue_flags))
goto retry_multishot;
return ret;