For IORING_OP_RECV with IORING_RECV_MULTISHOT, sqe->optlen limits the total number of bytes the request receives. The bundle path caps each receive at what is left of the limit. The non-bundle path receives up to sqe->len bytes into the selected buffer, or up to the buffer size if sqe->len is 0 or larger, so the last receive can go over the limit by almost a whole buffer. With sqe->len 0, a limit of 100, 4096-byte provided buffers and 8192 bytes queued, the request posts one 4096-byte CQE. Cap the non-bundle length the same way. On a datagram socket, the datagram that crosses the limit is then cut at the limit and the rest of it is dropped, as on the bundle path. Found, fixed and tested by Claude Code, I handled the review process. Fixes: 0ebc9a7ecf6a ("io_uring/net: Support multishot receive len cap") Cc: stable@vger.kernel.org # v6.17+ Signed-off-by: Hang Zhengyang --- Tested on for-7.5/io_uring and 6.18.66 in a KVM guest with 4096-byte buffers and 8192 bytes queued: limits of 100 and 6000 give 4096 and 8192 bytes without the patch and exactly the limit with it. On for-7.5/io_uring the liburing tests show no new failures. I'll send a liburing test separately. With 1500-byte datagrams and a limit of 4000, the third CQE is 1500 bytes without the patch and 1000 with it, as with a bundle. As with a bundle, the CQE doesn't show that the datagram was cut unless the request passed MSG_TRUNC. io_uring/net.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 994f6aadbda1..15f8d4558aff 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1201,6 +1201,9 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg len = arg.out_len; } else { len = sel->val; + /* if mshot limited, ensure we don't go over */ + if (sr->flags & IORING_RECV_MSHOT_LIM) + len = min_not_zero(len, sr->mshot_total_len); *sel = io_buffer_select(req, &len, sr->buf_group, issue_flags); if (!sel->addr) base-commit: 416f1d31a8acea8b45b5da50e78147b83ccf63a8 -- 2.53.0