Skip to contentSkip to conversation

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

PATCH New Jens Axboe 1 participant 1 message Feb 1, 2024 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

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

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.

Fixes 7ba89d2af17a ("io_uring: ensure recv and recvmsg handle MSG_WAITALL correctly")

---

io_uring/net.c +1 -0
index a12ff69e6843..43bc9a5f96f9 100644
@@ -923,6 +923,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
 		if (!buf)
 			return -ENOBUFS;
 		sr->buf = buf;
+		sr->len = len;
 	}
 
 	ret = import_ubuf(ITER_DEST, sr->buf, len, &msg.msg_iter);
Signature · 1 line
Jens Axboe