Commit c314094c authored by Jens Axboe's avatar Jens Axboe

io_uring/net: harden multishot termination case for recv

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: b3fdea6e ("io_uring: multishot recv")
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 17ea56b7
...@@ -1133,6 +1133,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) ...@@ -1133,6 +1133,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
int ret, min_ret = 0; int ret, min_ret = 0;
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
size_t len = sr->len; size_t len = sr->len;
bool mshot_finished;
if (!(req->flags & REQ_F_POLLED) && if (!(req->flags & REQ_F_POLLED) &&
(sr->flags & IORING_RECVSEND_POLL_FIRST)) (sr->flags & IORING_RECVSEND_POLL_FIRST))
...@@ -1187,6 +1188,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) ...@@ -1187,6 +1188,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
req_set_fail(req); req_set_fail(req);
} }
mshot_finished = ret <= 0;
if (ret > 0) if (ret > 0)
ret += sr->done_io; ret += sr->done_io;
else if (sr->done_io) else if (sr->done_io)
...@@ -1194,7 +1196,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) ...@@ -1194,7 +1196,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
else else
io_kbuf_recycle(req, issue_flags); 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; goto retry_multishot;
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment