Skip to content

Commit 8579538

Browse files
isilenceaxboe
authored andcommitted
io_uring/msg_ring: fix remote queue to disabled ring
IORING_SETUP_R_DISABLED rings don't have the submitter task set, so it's not always safe to use ->submitter_task. Disallow posting msg_ring messaged to disabled rings. Also add task NULL check for loosy sync around testing for IORING_SETUP_R_DISABLED. Cc: stable@vger.kernel.org Fixes: 6d043ee ("io_uring: do msg_ring in target task via tw") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 56d8e31 commit 8579538

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

io_uring/io_uring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,7 +3674,7 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
36743674

36753675
if (ctx->flags & IORING_SETUP_SINGLE_ISSUER
36763676
&& !(ctx->flags & IORING_SETUP_R_DISABLED))
3677-
ctx->submitter_task = get_task_struct(current);
3677+
WRITE_ONCE(ctx->submitter_task, get_task_struct(current));
36783678

36793679
file = io_uring_get_file(ctx);
36803680
if (IS_ERR(file)) {
@@ -3868,7 +3868,7 @@ static int io_register_enable_rings(struct io_ring_ctx *ctx)
38683868
return -EBADFD;
38693869

38703870
if (ctx->flags & IORING_SETUP_SINGLE_ISSUER && !ctx->submitter_task)
3871-
ctx->submitter_task = get_task_struct(current);
3871+
WRITE_ONCE(ctx->submitter_task, get_task_struct(current));
38723872

38733873
if (ctx->restrictions.registered)
38743874
ctx->restricted = 1;

io_uring/msg_ring.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ static int io_msg_exec_remote(struct io_kiocb *req, task_work_func_t func)
6969
{
7070
struct io_ring_ctx *ctx = req->file->private_data;
7171
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);
72+
struct task_struct *task = READ_ONCE(ctx->submitter_task);
73+
74+
if (unlikely(!task))
75+
return -EOWNERDEAD;
7276

7377
init_task_work(&msg->tw, func);
7478
if (task_work_add(ctx->submitter_task, &msg->tw, TWA_SIGNAL))
@@ -114,6 +118,8 @@ static int io_msg_ring_data(struct io_kiocb *req, unsigned int issue_flags)
114118

115119
if (msg->src_fd || msg->dst_fd || msg->flags)
116120
return -EINVAL;
121+
if (target_ctx->flags & IORING_SETUP_R_DISABLED)
122+
return -EBADFD;
117123

118124
if (io_msg_need_remote(target_ctx))
119125
return io_msg_exec_remote(req, io_msg_tw_complete);
@@ -206,6 +212,8 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
206212

207213
if (target_ctx == ctx)
208214
return -EINVAL;
215+
if (target_ctx->flags & IORING_SETUP_R_DISABLED)
216+
return -EBADFD;
209217
if (!src_file) {
210218
src_file = io_msg_grab_file(req, issue_flags);
211219
if (!src_file)

0 commit comments

Comments
 (0)