* [PATCH RESEND] io_uring/rsrc: hold uring_lock across index-alloc put_user
@ 2026-11-04 15:46 Yuansheng Yang
2026-11-04 16:18 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Yuansheng Yang @ 2026-11-04 15:46 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring
io_files_update_with_index_alloc() installs a fixed file via
io_fixed_fd_install(), which drops ->uring_lock when the request runs on
io-wq, then put_user()s the allocated slot back to userspace. If that
faults, the error path calls __io_close_fixed() by slot index after
re-taking the lock.
The slot can be closed and reused between the install and that cleanup:
another fixed CLOSE plus open/accept/pipe/socket, or a FILES_UPDATE, can
put an unrelated file into the same slot. The error path then removes
that file instead of the one this request installed, ending an unrelated
file's fixed-table reference early. This is a correctness/DoS issue, not
a use-after-free: fixed-file requests hold an io_rsrc_node reference, so
the node and file stay alive until they are done.
Hold ->uring_lock across __io_fixed_fd_install() and put_user(), and do
the failure cleanup with io_fixed_fd_remove() under the same lock. This
is the same class as the io_pipe_fixed() fix; faulting while holding
->uring_lock is fine, the registration paths already do it.
Fixes: a7c41b4687f5 ("io_uring: let IORING_OP_FILES_UPDATE support choosing fixed file slots")
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
Resending with corrected Signed-off-by and without the CVE reference (being invalidated); no code changes.
io_uring/rsrc.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index e0345c3e76..6c85eb50f0 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -570,13 +570,14 @@ int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
static int io_files_update_with_index_alloc(struct io_kiocb *req,
unsigned int issue_flags)
{
+ struct io_ring_ctx *ctx = req->ctx;
struct io_rsrc_update *up = io_kiocb_to_cmd(req, struct io_rsrc_update);
__s32 __user *fds = u64_to_user_ptr(up->arg);
unsigned int done;
struct file *file;
int ret, fd;
- if (!req->ctx->file_table.data.nr)
+ if (!ctx->file_table.data.nr)
return -ENXIO;
for (done = 0; done < up->nr_args; done++) {
@@ -590,15 +591,28 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req,
ret = -EBADF;
break;
}
- ret = io_fixed_fd_install(req, issue_flags, file,
- IORING_FILE_INDEX_ALLOC);
- if (ret < 0)
+ /*
+ * io_fixed_fd_install() drops ->uring_lock when running on
+ * io-wq, leaving a window where the slot can be closed and
+ * reused before put_user() faults. Keep the lock and undo
+ * the install under it. Faulting under ->uring_lock is fine,
+ * registration paths already do that.
+ */
+ io_ring_submit_lock(ctx, issue_flags);
+ ret = __io_fixed_fd_install(ctx, file,
+ IORING_FILE_INDEX_ALLOC);
+ if (ret < 0) {
+ io_ring_submit_unlock(ctx, issue_flags);
+ fput(file);
break;
+ }
if (put_user(ret, &fds[done])) {
- __io_close_fixed(req->ctx, issue_flags, ret);
+ io_fixed_fd_remove(ctx, ret);
+ io_ring_submit_unlock(ctx, issue_flags);
ret = -EFAULT;
break;
}
+ io_ring_submit_unlock(ctx, issue_flags);
}
if (done)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH RESEND] io_uring/rsrc: hold uring_lock across index-alloc put_user
2026-11-04 15:46 [PATCH RESEND] io_uring/rsrc: hold uring_lock across index-alloc put_user Yuansheng Yang
@ 2026-11-04 16:18 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2026-11-04 16:18 UTC (permalink / raw)
To: Yuansheng Yang; +Cc: io-uring
On Wed, 04 Nov 2026 23:46:55 +0800, Yuansheng Yang wrote:
> io_files_update_with_index_alloc() installs a fixed file via
> io_fixed_fd_install(), which drops ->uring_lock when the request runs on
> io-wq, then put_user()s the allocated slot back to userspace. If that
> faults, the error path calls __io_close_fixed() by slot index after
> re-taking the lock.
>
> The slot can be closed and reused between the install and that cleanup:
> another fixed CLOSE plus open/accept/pipe/socket, or a FILES_UPDATE, can
> put an unrelated file into the same slot. The error path then removes
> that file instead of the one this request installed, ending an unrelated
> file's fixed-table reference early. This is a correctness/DoS issue, not
> a use-after-free: fixed-file requests hold an io_rsrc_node reference, so
> the node and file stay alive until they are done.
>
> [...]
Applied, thanks!
[1/1] io_uring/rsrc: hold uring_lock across index-alloc put_user
commit: d7c7037253f6935af243570635d71b4920b5a4ea
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-04 16:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 15:46 [PATCH RESEND] io_uring/rsrc: hold uring_lock across index-alloc put_user Yuansheng Yang
2026-11-04 16:18 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox