Skip to content

Commit

Permalink
Merge tag 'wq-for-6.11-rc7-fixes' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/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
  • Loading branch information
Linus Torvalds committed Sep 12, 2024
2 parents 8581ae1 + 7361384 commit 5da0288
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,6 @@ static void detach_worker(struct worker *worker)

unbind_worker(worker);
list_del(&worker->node);
worker->pool = NULL;
}

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

mutex_lock(&wq_pool_attach_mutex);
detach_worker(worker);
worker->pool = NULL;
mutex_unlock(&wq_pool_attach_mutex);

/* clear leftover flags without pool->lock after it is detached */
Expand Down Expand Up @@ -3349,7 +3349,11 @@ static int worker_thread(void *__worker)
if (unlikely(worker->flags & WORKER_DIE)) {
raw_spin_unlock_irq(&pool->lock);
set_pf_worker(false);

/*
* The worker is dead and PF_WQ_WORKER is cleared, worker->pool
* shouldn't be accessed, reset it to NULL in case otherwise.
*/
worker->pool = NULL;
ida_free(&pool->worker_ida, worker->id);
return 0;
}
Expand Down

0 comments on commit 5da0288

Please sign in to comment.