io_uring: fix races with file table unregister

[ Upstream commit b0380bf6da ]

Fixed file 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 <g1042620637@gmail.com>
Fixes: 05f3fb3c53 ("io_uring: avoid ring quiesce for fixed file set unregister and update")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Pavel Begunkov 2022-06-13 06:32:44 +01:00 коммит произвёл Greg Kroah-Hartman
Родитель d460a8a3b9
Коммит b1e7cade3c
1 изменённых файлов: 8 добавлений и 0 удалений

Просмотреть файл

@ -7933,11 +7933,19 @@ static void __io_sqe_files_unregister(struct io_ring_ctx *ctx)
static int io_sqe_files_unregister(struct io_ring_ctx *ctx) static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
{ {
unsigned nr = ctx->nr_user_files;
int ret; int ret;
if (!ctx->file_data) if (!ctx->file_data)
return -ENXIO; return -ENXIO;
/*
* Quiesce may unlock ->uring_lock, and while it's not held
* prevent new requests using the table.
*/
ctx->nr_user_files = 0;
ret = io_rsrc_ref_quiesce(ctx->file_data, ctx); ret = io_rsrc_ref_quiesce(ctx->file_data, ctx);
ctx->nr_user_files = nr;
if (!ret) if (!ret)
__io_sqe_files_unregister(ctx); __io_sqe_files_unregister(ctx);
return ret; return ret;