mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cheng Yongkang <teel4res@gmail.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [BUG] io_uring/rsrc: failed file update still removes the old file
Date: Sun, 15 Nov 2026 08:36:12 -0800	[thread overview]
Message-ID: <20261115163612.225619-1-teel4res@gmail.com> (raw)

Hi Jens,

This is a small error-path issue. It only happens when a fixed file
update fails, for example because userspace passes a closed fd, so it
may not matter much in practice.

__io_sqe_files_update() removes the old file from the slot before it
calls fget() on the new fd. If fget() fails, or the fd is an io_uring
fd, or the node allocation fails, the update stops there and reports
that entry as not done (an error, or a short count in a batch), but
the slot is already empty. The old file is gone, and if it was
registered with a tag, its tag CQE is posted as if it had been removed
on purpose. io_install_fixed_file() does it the other way round: it
checks the file and allocates the node before it resets the slot.

On v7.3, updating slot 0 with a closed fd returned -EBADF, posted the
old file's tag CQE, and a later fixed-file NOP on slot 0 got -EBADF.

Moving the removal after the new file and node are ready keeps the old
file on failure:

  -		if (io_reset_rsrc_node(ctx, &ctx->file_table.data, i))
  -			io_file_bitmap_clear(&ctx->file_table, i);
   		if (fd != -1) {
   			...
  +			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;
   			...
  +		} else if (io_reset_rsrc_node(ctx, &ctx->file_table.data, i)) {
  +			io_file_bitmap_clear(&ctx->file_table, i);
   		}

With this change the update still returns -EBADF, but slot 0 keeps
working and no tag CQE is posted. Replacement, removal with fd -1 and
SKIP behave as before, and in a partial update the entries before the
failing one are still applied. In next-20261113 the removal still
comes before fget(). I can send a patch if you want one.

Thanks,
Cheng Yongkang

                 reply	other threads:[~2026-11-15 16:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261115163612.225619-1-teel4res@gmail.com \
    --to=teel4res@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®