summaryrefslogtreecommitdiff
path: root/io_uring/kbuf.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2026-03-12 17:59:25 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-03-25 13:06:02 +0300
commit439a6728ec4641ffad1ca796622c19bc525e570f (patch)
tree8ee65af8a06a9d2473a214feaca061b8f16a7503 /io_uring/kbuf.c
parentd77401968c789037b1ba962705ef998133715b1f (diff)
downloadlinux-439a6728ec4641ffad1ca796622c19bc525e570f.tar.xz
io_uring/kbuf: check if target buffer list is still legacy on recycle
Commit c2c185be5c85d37215397c8e8781abf0a69bec1f upstream. There's a gap between when the buffer was grabbed and when it potentially gets recycled, where if the list is empty, someone could've upgraded it to a ring provided type. This can happen if the request is forced via io-wq. The legacy recycling is missing checking if the buffer_list still exists, and if it's of the correct type. Add those checks. Cc: stable@vger.kernel.org Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers") Reported-by: Keenan Dong <keenanat2000@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'io_uring/kbuf.c')
-rw-r--r--io_uring/kbuf.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index b2c381634393..ad1e14359662 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -70,9 +70,15 @@ void io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags)
buf = req->kbuf;
bl = io_buffer_get_list(ctx, buf->bgid);
- list_add(&buf->list, &bl->buf_list);
+ /*
+ * If the buffer list was upgraded to a ring-based one, or removed,
+ * while the request was in-flight in io-wq, drop it.
+ */
+ if (bl && !bl->is_mapped)
+ list_add(&buf->list, &bl->buf_list);
req->flags &= ~REQ_F_BUFFER_SELECTED;
req->buf_index = buf->bgid;
+ req->kbuf = NULL;
io_ring_submit_unlock(ctx, issue_flags);
return;