io_uring/rsrc: keep the old file when a file update fails
PATCH 1/1 io_uring/rsrc: keep the old file when a file update fails
__io_sqe_files_update() resets the slot before it calls fget() on the new fd. If fget() fails, the fd is an io_uring file, or the node allocation fails, the update stops and reports that entry as not done, but the old file has already been removed. Later requests that use the slot fail with -EBADF, and if the old file was registered with a tag, its tag CQE is posted as if it had been removed on purpose.
Reset the slot only after the new file has been checked and its node allocated, as io_install_fixed_file() does. Removal with fd == -1 still resets the slot right away.
---
Report: https://lore.kernel.org/io-uring/[email protected]/
Runtime-tested on v7.3 with the closed-fd update from the report. __io_sqe_files_update() is the same in io_uring-7.4, where it is only build-tested.
io_uring/rsrc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
io_uring/rsrc.c +4 -2
@@ -363,8 +363,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,if (i >= ctx->file_table.data.nr)break ; i =array_index_nospec (i, ctx->file_table.data.nr); -if (io_reset_rsrc_node (ctx, &ctx->file_table.data, i)) -io_file_bitmap_clear (&ctx->file_table, i);if (fd !=-1 ) {struct file *file =fget (fd);
@@ -388,11 +386,15 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,fput (file);break ; } +if (io_reset_rsrc_node (ctx, &ctx->file_table.data, i)) +io_file_bitmap_clear (&ctx->file_table, i); ctx->file_table.data.nodes[i] = node;if (tag) node->tag = tag;io_fixed_file_set (node, file);io_file_bitmap_set (&ctx->file_table, i); + }else if (io_reset_rsrc_node (ctx, &ctx->file_table.data, i)) { +io_file_bitmap_clear (&ctx->file_table, i); } }return done ? done : err;
Signature · 1 line
2.34.1
Quoted 8 lines · Cheng Yongkang
__io_sqe_files_update()resets the slot before it callsfget()on the new fd. Iffget()fails, the fd is anio_uringfile, or the node allocation fails, the update stops and reports that entry as not done, but the old file has already been removed. Later requests that use the slot fail with-EBADF, and if the old file was registered with a tag, its tag CQE is posted as if it had been removed on purpose.[...]
Applied, thanks!
[1/1] io_uring/rsrc: keep the old file when a file update fails
(no commit info)
Best regards,
Signature · 1 line
Jens Axboe