Skip to contentSkip to conversation

io_uring/net: keep recvmsg buffer select length within MAX_RW_COUNT

PATCH Applied Yichong Chen 2 participants 3 messages Oct 23 – Oct 26 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring/net: keep recvmsg buffer select length within MAX_RW_COUNT

io_recvmsg() takes the transfer length from the ring provided buffer when sqe->len is 0, and such a buffer can be up to 4G. min_ret is an int, so 2G or more makes it negative and the (ret < min_ret) block is skipped, and the oversized length reaches the socket layer unchanged: an empty socket then completes with 0 instead of arming poll, and a short read is reported as complete. Clamp the length to MAX_RW_COUNT, as io_recv() does.

Fixes 78d0d2063bab ("io_uring/net: disable partial retries for recvmsg with cmsg")
---
 io_uring/net.c | 1 +
 1 file changed, 1 insertion(+)
io_uring/net.c +1 -0
index eeab88e77fd8..4678f29f5177 100644
@@ -1068,6 +1068,7 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
 		sel = io_buffer_select(req, &len, sr->buf_group, issue_flags);
 		if (!sel.addr)
 			return -ENOBUFS;
+		len = min_t(size_t, len, MAX_RW_COUNT);
 
 		if (req->flags & REQ_F_APOLL_MULTISHOT) {
 			ret = io_recvmsg_prep_multishot(kmsg, sr, &sel.addr, &len);
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 8 lines · Yichong Chen

io_recvmsg() takes the transfer length from the ring provided buffer when sqe->len is 0, and such a buffer can be up to 4G. min_ret is an int, so 2G or more makes it negative and the (ret < min_ret) block is skipped, and the oversized length reaches the socket layer unchanged: an empty socket then completes with 0 instead of arming poll, and a short read is reported as complete. Clamp the length to MAX_RW_COUNT, as io_recv() does.

Fixes 78d0d2063bab ("io_uring/net: disable partial retries for recvmsg with cmsg")

Don't think that's correct, it just moved the check. Should be:

c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")

instead. I will fix that up. Waiting on Linus pulling the previous bits, then I will queue this up for 7.4.

Signature · 1 line
Jens Axboe
maintainer Applied
#2 lore raw
In reply to Yichong Chen
Quoted 8 lines · Yichong Chen

io_recvmsg() takes the transfer length from the ring provided buffer when sqe->len is 0, and such a buffer can be up to 4G. min_ret is an int, so 2G or more makes it negative and the (ret < min_ret) block is skipped, and the oversized length reaches the socket layer unchanged: an empty socket then completes with 0 instead of arming poll, and a short read is reported as complete. Clamp the length to MAX_RW_COUNT, as io_recv() does.

[...]

Applied, thanks!

[1/1] io_uring/net: keep recvmsg buffer select length within MAX_RW_COUNT

      commit: 18d3f56eb6e6500a65d81cf265f0fe74fd9ecab6

Best regards,

Signature · 1 line
Jens Axboe