From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Chris Mason <mason@kernel.org>, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 02/10] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put
Date: Wed, 25 Nov 2026 11:43:11 -0700 [thread overview]
Message-ID: <20261125184439.58077-3-axboe@kernel.dk> (raw)
In-Reply-To: <20261125184439.58077-1-axboe@kernel.dk>
From: Chris Mason <mason@kernel.org>
A bundle receive with MSG_WAITALL can hit a NULL pointer dereference in
io_net_kbuf_can_retry(), or share ring provided buffers with another
request of the buffer group, if another reader of the socket takes the
data that the receive is about to append.
The buffer list is only known within the issue that selected from it, so
io_recv() has to commit or recycle ring provided buffers before it
returns IOU_RETRY. On -EAGAIN it calls io_kbuf_recycle(), which does
nothing if REQ_F_BL_NO_RECYCLE is set. A partial transfer sets that flag
for the buffer that holds the data, and nothing ever clears it. That was
fine while only a multishot receive selected more than once, as
multishot excludes MSG_WAITALL. But since commit 7c71a0af81ba
("io_uring/net: improve recv bundles") any bundle receive can put its
buffers and select new ones, and the stale flag covers these too:
io_recv() partial transfer
io_net_kbuf_recyle() sets the flag, commits the buffer
return IOU_RETRY
io_recv() fills the buffer, msg_inq > 1
io_recv_finish()
io_put_kbufs() leaves the flag set
io_buffers_peek() sets REQ_F_BUFFERS_COMMIT
sock_recvmsg() -EAGAIN, the data is gone
io_kbuf_recycle() does nothing
return IOU_RETRY buffers mapped, but not committed
io_recv() sel.buf_list is NULL, no selection
sock_recvmsg() partial transfer
io_net_kbuf_can_retry() reads bl->flags
The fix used here is to clear the flag when the request puts the buffers
that the flag was set for.
Fixes: 7c71a0af81ba ("io_uring/net: improve recv bundles")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/kbuf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 873d66a06b36..78d29008919a 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -428,6 +428,9 @@ unsigned int __io_put_kbufs(struct io_kiocb *req, struct io_buffer_list *bl,
ret = IORING_CQE_F_BUFFER | (req->buf_index << IORING_CQE_BUFFER_SHIFT);
+ /* only covers the buffer(s) being put, not a later selection */
+ req->flags &= ~REQ_F_BL_NO_RECYCLE;
+
if (unlikely(!(req->flags & REQ_F_BUFFER_RING))) {
io_kbuf_drop_legacy(req);
return ret;
--
2.55.0
next prev parent reply other threads:[~2026-11-25 18:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
2026-11-25 18:43 ` [PATCH 01/10] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-11-25 18:43 ` Jens Axboe [this message]
2026-11-25 18:43 ` [PATCH 03/10] io_uring: free the ring after a grace period Jens Axboe
2026-11-25 18:43 ` [PATCH 04/10] io_uring: free the ring from an RCU work Jens Axboe
2026-11-25 18:43 ` [PATCH 05/10] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-11-25 18:43 ` [PATCH 06/10] io_uring/timeout: hold timeout_lock for the link splice Jens Axboe
2026-11-25 18:43 ` [PATCH 07/10] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-11-25 18:43 ` [PATCH 08/10] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-11-25 18:43 ` [PATCH 09/10] io_uring: drop cached task refs on ring release Jens Axboe
2026-11-25 18:43 ` [PATCH 10/10] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125184439.58077-3-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=mason@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox