Skip to content
/ linux Public

Commit 439a672

Browse files
axboegregkh
authored andcommitted
io_uring/kbuf: check if target buffer list is still legacy on recycle
Commit c2c185b 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: c7fb194 ("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>
1 parent d774019 commit 439a672

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

io_uring/kbuf.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ void io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags)
7070

7171
buf = req->kbuf;
7272
bl = io_buffer_get_list(ctx, buf->bgid);
73-
list_add(&buf->list, &bl->buf_list);
73+
/*
74+
* If the buffer list was upgraded to a ring-based one, or removed,
75+
* while the request was in-flight in io-wq, drop it.
76+
*/
77+
if (bl && !bl->is_mapped)
78+
list_add(&buf->list, &bl->buf_list);
7479
req->flags &= ~REQ_F_BUFFER_SELECTED;
7580
req->buf_index = buf->bgid;
81+
req->kbuf = NULL;
7682

7783
io_ring_submit_unlock(ctx, issue_flags);
7884
return;

0 commit comments

Comments
 (0)