Skip to content

Commit

Permalink
io_uring: fix races with buffer table unregister
Browse files Browse the repository at this point in the history
[ Upstream commit d11d31f ]

Fixed buffer table quiesce might unlock ->uring_lock, potentially
letting new requests to be submitted, don't allow those requests to
use the table as they will race with unregistration.

Reported-and-tested-by: van fantasy <[email protected]>
Fixes: bd54b6f ("io_uring: implement fixed buffers registration similar to fixed files")
Signed-off-by: Pavel Begunkov <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
isilence authored and gregkh committed Jun 22, 2022
1 parent b1e7cad commit 91f5a60
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -8905,12 +8905,19 @@ static void __io_sqe_buffers_unregister(struct io_ring_ctx *ctx)

static int io_sqe_buffers_unregister(struct io_ring_ctx *ctx)
{
unsigned nr = ctx->nr_user_bufs;
int ret;

if (!ctx->buf_data)
return -ENXIO;

/*
* Quiesce may unlock ->uring_lock, and while it's not held
* prevent new requests using the table.
*/
ctx->nr_user_bufs = 0;
ret = io_rsrc_ref_quiesce(ctx->buf_data, ctx);
ctx->nr_user_bufs = nr;
if (!ret)
__io_sqe_buffers_unregister(ctx);
return ret;
Expand Down

0 comments on commit 91f5a60

Please sign in to comment.