Skip to content

Commit b0727b1

Browse files
committed
io_uring/msg_ring: check for dead submitter task
The change for improving the handling of the target CQE posting inadvertently dropped the NULL check for the submitter task on the target ring, reinstate that. Fixes: 0617bb5 ("io_uring/msg_ring: improve handling of target CQE posting") Reported-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 50cf5f3 commit b0727b1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

io_uring/msg_ring.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,21 @@ static void io_msg_tw_complete(struct io_kiocb *req, struct io_tw_state *ts)
8686
percpu_ref_put(&ctx->refs);
8787
}
8888

89-
static void io_msg_remote_post(struct io_ring_ctx *ctx, struct io_kiocb *req,
90-
int res, u32 cflags, u64 user_data)
89+
static int io_msg_remote_post(struct io_ring_ctx *ctx, struct io_kiocb *req,
90+
int res, u32 cflags, u64 user_data)
9191
{
92+
req->task = READ_ONCE(ctx->submitter_task);
93+
if (!req->task) {
94+
kmem_cache_free(req_cachep, req);
95+
return -EOWNERDEAD;
96+
}
9297
req->cqe.user_data = user_data;
9398
io_req_set_res(req, res, cflags);
9499
percpu_ref_get(&ctx->refs);
95100
req->ctx = ctx;
96-
req->task = READ_ONCE(ctx->submitter_task);
97101
req->io_task_work.func = io_msg_tw_complete;
98102
io_req_task_work_add_remote(req, ctx, IOU_F_TWQ_LAZY_WAKE);
103+
return 0;
99104
}
100105

101106
static struct io_kiocb *io_msg_get_kiocb(struct io_ring_ctx *ctx)
@@ -125,8 +130,8 @@ static int io_msg_data_remote(struct io_kiocb *req)
125130
if (msg->flags & IORING_MSG_RING_FLAGS_PASS)
126131
flags = msg->cqe_flags;
127132

128-
io_msg_remote_post(target_ctx, target, msg->len, flags, msg->user_data);
129-
return 0;
133+
return io_msg_remote_post(target_ctx, target, msg->len, flags,
134+
msg->user_data);
130135
}
131136

132137
static int io_msg_ring_data(struct io_kiocb *req, unsigned int issue_flags)

0 commit comments

Comments
 (0)