Skip to content

Commit 991468d

Browse files
committed
io_uring: explicitly catch any illegal async queue attempt
Catch an illegal case to queue async from an unrelated task that got the ring fd passed to it. This should not be possible to hit, but better be proactive and catch it explicitly. io-wq is extended to check for early IO_WQ_WORK_CANCEL being set on a work item as well, so it can run the request through the normal cancelation path. Signed-off-by: Jens Axboe <[email protected]>
1 parent 3c30ef0 commit 991468d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

fs/io-wq.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,12 @@ static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work)
731731
int work_flags;
732732
unsigned long flags;
733733

734-
if (test_bit(IO_WQ_BIT_EXIT, &wqe->wq->state)) {
734+
/*
735+
* If io-wq is exiting for this task, or if the request has explicitly
736+
* been marked as one that should not get executed, cancel it here.
737+
*/
738+
if (test_bit(IO_WQ_BIT_EXIT, &wqe->wq->state) ||
739+
(work->flags & IO_WQ_WORK_CANCEL)) {
735740
io_run_cancel(work, wqe);
736741
return;
737742
}

fs/io_uring.c

+11
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,17 @@ static void io_queue_async_work(struct io_kiocb *req)
12941294

12951295
/* init ->work of the whole link before punting */
12961296
io_prep_async_link(req);
1297+
1298+
/*
1299+
* Not expected to happen, but if we do have a bug where this _can_
1300+
* happen, catch it here and ensure the request is marked as
1301+
* canceled. That will make io-wq go through the usual work cancel
1302+
* procedure rather than attempt to run this request (or create a new
1303+
* worker for it).
1304+
*/
1305+
if (WARN_ON_ONCE(!same_thread_group(req->task, current)))
1306+
req->work.flags |= IO_WQ_WORK_CANCEL;
1307+
12971308
trace_io_uring_queue_async_work(ctx, io_wq_is_hashed(&req->work), req,
12981309
&req->work, req->flags);
12991310
io_wq_enqueue(tctx->io_wq, &req->work);

0 commit comments

Comments
 (0)