Skip to content

Commit 7a8737e

Browse files
calebsanderaxboe
authored andcommitted
io_uring: use release-acquire ordering for IORING_SETUP_R_DISABLED
io_uring_enter(), __io_msg_ring_data(), and io_msg_send_fd() read ctx->flags and ctx->submitter_task without holding the ctx's uring_lock. This means they may race with the assignment to ctx->submitter_task and the clearing of IORING_SETUP_R_DISABLED from ctx->flags in io_register_enable_rings(). Ensure the correct ordering of the ctx->flags and ctx->submitter_task memory accesses by storing to ctx->flags using release ordering and loading it using acquire ordering. Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Fixes: 4add705 ("io_uring: remove io_register_submitter") Reviewed-by: Joanne Koong <joannelkoong@gmail.com> Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 48ed701 commit 7a8737e

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

io_uring/io_uring.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3228,7 +3228,11 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
32283228

32293229
ctx = file->private_data;
32303230
ret = -EBADFD;
3231-
if (unlikely(ctx->flags & IORING_SETUP_R_DISABLED))
3231+
/*
3232+
* Keep IORING_SETUP_R_DISABLED check before submitter_task load
3233+
* in io_uring_add_tctx_node() -> __io_uring_add_tctx_node_from_submit()
3234+
*/
3235+
if (unlikely(smp_load_acquire(&ctx->flags) & IORING_SETUP_R_DISABLED))
32323236
goto out;
32333237

32343238
/*

io_uring/msg_ring.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ static int __io_msg_ring_data(struct io_ring_ctx *target_ctx,
125125
return -EINVAL;
126126
if (!(msg->flags & IORING_MSG_RING_FLAGS_PASS) && msg->dst_fd)
127127
return -EINVAL;
128-
if (target_ctx->flags & IORING_SETUP_R_DISABLED)
128+
/*
129+
* Keep IORING_SETUP_R_DISABLED check before submitter_task load
130+
* in io_msg_data_remote() -> io_msg_remote_post()
131+
*/
132+
if (smp_load_acquire(&target_ctx->flags) & IORING_SETUP_R_DISABLED)
129133
return -EBADFD;
130134

131135
if (io_msg_need_remote(target_ctx))
@@ -245,7 +249,11 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
245249
return -EINVAL;
246250
if (target_ctx == ctx)
247251
return -EINVAL;
248-
if (target_ctx->flags & IORING_SETUP_R_DISABLED)
252+
/*
253+
* Keep IORING_SETUP_R_DISABLED check before submitter_task load
254+
* in io_msg_fd_remote()
255+
*/
256+
if (smp_load_acquire(&target_ctx->flags) & IORING_SETUP_R_DISABLED)
249257
return -EBADFD;
250258
if (!msg->src_file) {
251259
int ret = io_msg_grab_file(req, issue_flags);

io_uring/register.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ static int io_register_enable_rings(struct io_ring_ctx *ctx)
193193
if (ctx->restrictions.registered)
194194
ctx->restricted = 1;
195195

196-
ctx->flags &= ~IORING_SETUP_R_DISABLED;
196+
/* Keep submitter_task store before clearing IORING_SETUP_R_DISABLED */
197+
smp_store_release(&ctx->flags, ctx->flags & ~IORING_SETUP_R_DISABLED);
197198
if (ctx->sq_data && wq_has_sleeper(&ctx->sq_data->wait))
198199
wake_up(&ctx->sq_data->wait);
199200
return 0;

0 commit comments

Comments
 (0)