Skip to contentSkip to conversation

io_uring/rsrc: failed file update still removes the old file

BUG Cheng Yongkang 1 participant 1 message Nov 15 io_uring

lore
Share & tools
lore
#0 lore 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