io_uring/net: fix sr->len for IORING_OP_RECV with MSG_WAITALL and buffers

commit 72bd80252feeb3bef8724230ee15d9f7ab541c6e upstream.

If we use IORING_OP_RECV with provided buffers and pass in '0' as the
length of the request, the length is retrieved from the selected buffer.
If MSG_WAITALL is also set and we get a short receive, then we may hit
the retry path which decrements sr->len and increments the buffer for
a retry. However, the length is still zero at this point, which means
that sr->len now becomes huge and import_ubuf() will cap it to
MAX_RW_COUNT and subsequently return -EFAULT for the range as a whole.

Fix this by always assigning sr->len once the buffer has been selected.

Cc: stable@vger.kernel.org
Fixes: 7ba89d2af1 ("io_uring: ensure recv and recvmsg handle MSG_WAITALL correctly")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jens Axboe 2024-02-01 06:42:36 -07:00 committed by Greg Kroah-Hartman
parent 08249dc3d9
commit fbd77ce1d1
1 changed files with 1 additions and 0 deletions

View File

@ -875,6 +875,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
if (!buf) if (!buf)
return -ENOBUFS; return -ENOBUFS;
sr->buf = buf; sr->buf = buf;
sr->len = len;
} }
ret = import_single_range(ITER_DEST, sr->buf, len, &iov, &msg.msg_iter); ret = import_single_range(ITER_DEST, sr->buf, len, &iov, &msg.msg_iter);