Skip to content

Commit 5da0288

Browse files
committed
Merge tag 'wq-for-6.11-rc7-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
Pull workqueue fix from Tejun Heo: "A fix for a NULL worker->pool deref bug which can be triggered when a worker is created and then destroyed immediately" * tag 'wq-for-6.11-rc7-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: Clear worker->pool in the worker thread context
2 parents 8581ae1 + 7361384 commit 5da0288

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

kernel/workqueue.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,6 @@ static void detach_worker(struct worker *worker)
27092709

27102710
unbind_worker(worker);
27112711
list_del(&worker->node);
2712-
worker->pool = NULL;
27132712
}
27142713

27152714
/**
@@ -2729,6 +2728,7 @@ static void worker_detach_from_pool(struct worker *worker)
27292728

27302729
mutex_lock(&wq_pool_attach_mutex);
27312730
detach_worker(worker);
2731+
worker->pool = NULL;
27322732
mutex_unlock(&wq_pool_attach_mutex);
27332733

27342734
/* clear leftover flags without pool->lock after it is detached */
@@ -3349,7 +3349,11 @@ static int worker_thread(void *__worker)
33493349
if (unlikely(worker->flags & WORKER_DIE)) {
33503350
raw_spin_unlock_irq(&pool->lock);
33513351
set_pf_worker(false);
3352-
3352+
/*
3353+
* The worker is dead and PF_WQ_WORKER is cleared, worker->pool
3354+
* shouldn't be accessed, reset it to NULL in case otherwise.
3355+
*/
3356+
worker->pool = NULL;
33533357
ida_free(&pool->worker_ida, worker->id);
33543358
return 0;
33553359
}

0 commit comments

Comments
 (0)