From: Jens Axboe <axboe@kernel.dk>
To: stable@vger.kernel.org
Subject: [PATCH 6.12.y 7/9] io_uring/rsrc: keep the old file when a file update fails
Date: Sat, 21 Nov 2026 21:31:19 +0000 [thread overview]
Message-ID: <20261121213121.1789042-8-axboe@kernel.dk> (raw)
In-Reply-To: <20261121213121.1789042-1-axboe@kernel.dk>
From: Cheng Yongkang <teel4res@gmail.com>
Commit e5a346e4309d720c47fe8331a00068608fad47dd upstream.
__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.
Fixes: c3a31e605620 ("io_uring: add support for IORING_REGISTER_FILES_UPDATE")
Cc: stable@vger.kernel.org
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
Link: https://patch.msgid.link/20261116044531.281978-1-teel4res@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.12 has no rsrc nodes for files, the old file is queued for
removal with io_queue_rsrc_removal(), which can fail. Get and check the
new file first, and only remove the old one once that has succeeded]
---
io_uring/rsrc.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 168c6987435e..5a3f3e4e3fa1 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -348,6 +348,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
return -EINVAL;
for (done = 0; done < nr_args; done++) {
+ struct file *file = NULL;
u64 tag = 0;
if ((tags && copy_from_user(&tag, &tags[done], sizeof(tag))) ||
@@ -365,17 +366,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
i = array_index_nospec(up->offset + done, ctx->nr_user_files);
file_slot = io_fixed_file_slot(&ctx->file_table, i);
- if (file_slot->file_ptr) {
- err = io_queue_rsrc_removal(data, i,
- io_slot_file(file_slot));
- if (err)
- break;
- file_slot->file_ptr = 0;
- io_file_bitmap_clear(&ctx->file_table, i);
- }
if (fd != -1) {
- struct file *file = fget(fd);
-
+ file = fget(fd);
if (!file) {
err = -EBADF;
break;
@@ -388,6 +380,19 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
err = -EBADF;
break;
}
+ }
+ if (file_slot->file_ptr) {
+ err = io_queue_rsrc_removal(data, i,
+ io_slot_file(file_slot));
+ if (err) {
+ if (file)
+ fput(file);
+ break;
+ }
+ file_slot->file_ptr = 0;
+ io_file_bitmap_clear(&ctx->file_table, i);
+ }
+ if (file) {
*io_get_tag_slot(data, i) = tag;
io_fixed_file_set(file_slot, file);
io_file_bitmap_set(&ctx->file_table, i);
--
2.55.0
next prev parent reply other threads:[~2026-11-21 21:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 21:31 [PATCH 6.12.y 0/9] io_uring fixes for 6.12-stable Jens Axboe
2026-11-21 21:31 ` [PATCH 6.12.y 1/9] io_uring: enable toggle of iowait usage when waiting on CQEs Jens Axboe
2026-11-21 21:31 ` [PATCH 6.12.y 2/9] io_uring/napi: don't end the single NAPI busy poll early on need_resched() Jens Axboe
2026-11-21 21:31 ` [PATCH 6.12.y 3/9] io_uring: fail soft links on negative IOU_COMPLETE results Jens Axboe
2026-11-21 21:31 ` [PATCH 6.12.y 4/9] io_uring/futex: fail soft links when cancelling a wait Jens Axboe
2026-11-21 21:31 ` [PATCH 6.12.y 5/9] io_uring/rw: fail soft links on IOPOLL short or error IO Jens Axboe
2026-11-21 21:31 ` [PATCH 6.12.y 6/9] io_uring/timeout: don't rearm a multishot timeout on cancel Jens Axboe
2026-11-21 21:31 ` Jens Axboe [this message]
2026-11-21 21:31 ` [PATCH 6.12.y 8/9] io_uring/kbuf: initialize arg->out_len from arg->max_len in io_buffers_select() Jens Axboe
2026-11-21 21:31 ` [PATCH 6.12.y 9/9] io_uring/io-wq: apply the current cpuset to new workers Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121213121.1789042-8-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox