Skip to content

Commit adeaa3f

Browse files
committed
io_uring/io-wq: clear current->worker_private on exit
A recent fix stopped clearing PF_IO_WORKER from current->flags on exit, which meant that we can now call inc/dec running on the worker after it has been removed if it ends up scheduling in/out as part of exit. If this happens after an RCU grace period has passed, then the struct pointed to by current->worker_private may have been freed, and we can now be accessing memory that is freed. Ensure this doesn't happen by clearing the task worker_private field. Both io_wq_worker_running() and io_wq_worker_sleeping() check this field before going any further, and we don't need any accounting etc done after this worker has exited. Fixes: fd37b88 ("io_uring/io-wq: don't clear PF_IO_WORKER on exit") Reported-by: Zorro Lang <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent cac9e44 commit adeaa3f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

io_uring/io-wq.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ static void io_worker_exit(struct io_worker *worker)
220220
list_del_rcu(&worker->all_list);
221221
raw_spin_unlock(&wq->lock);
222222
io_wq_dec_running(worker);
223-
worker->flags = 0;
223+
/*
224+
* this worker is a goner, clear ->worker_private to avoid any
225+
* inc/dec running calls that could happen as part of exit from
226+
* touching 'worker'.
227+
*/
228+
current->worker_private = NULL;
224229

225230
kfree_rcu(worker, rcu);
226231
io_worker_ref_put(wq);

0 commit comments

Comments
 (0)