FAILED: patch "[PATCH] workqueue: Fix unbound pool lifetime for pending pwqs" failed to apply to 6.12-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x cf9c8aaea0d47410df8708bec195889f3a85cd3c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026102148-unadorned-icon-a748@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From cf9c8aaea0d47410df8708bec195889f3a85cd3c Mon Sep 17 00:00:00 2001
From: Yao Kai <[email protected]>
Date: Mon, 24 Aug 2026 11:58:52 +0800
Subject: [PATCH] workqueue: Fix unbound pool lifetime for pending pwqs
KASAN reports a use-after-free of an unbound worker_pool in node_activate_pending_pwq():
BUG: KASAN: slab-use-after-free in _raw_spin_trylock+0x6d/0x120 Read of size 4 at addr ffff8880089ce000 by task kworker/u22:0/318 CPU: 1 UID: 0 PID: 318 Comm: kworker/u22:0 Not tainted 7.2.0 #1 PREEMPT(lazy) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 Workqueue: 0x0 (flush-8:0) Call Trace: <TASK> dump_stack_lvl+0x53/0x70 print_report+0xce/0x610 kasan_report+0xce/0x100 _raw_spin_trylock+0x6d/0x120 pwq_dec_nr_in_flight+0x4b4/0xcb0 process_one_work+0x921/0x11a0 worker_thread+0x4d0/0xd20 kthread+0x2de/0x3c0 ret_from_fork+0x3aa/0x620 ret_from_fork_asm+0x1a/0x30 </TASK> Allocated by task 311: alloc_pwq+0x439/0xca0 apply_wqattrs_prepare+0x75e/0xd10 apply_workqueue_attrs_locked+0x44/0xa0 wq_nice_store+0x350/0x450 Freed by task 0: kfree+0x127/0x3b0 rcu_core+0x523/0x1780 handle_softirqs+0x1b3/0x610 Last potentially related work creation: put_unbound_pool+0x3f3/0x7d0 pwq_release_workfn+0x494/0x8e0 kthread_worker_fn+0x1ff/0x790
Canceling the last inactive work skips pwq_dec_nr_active(), so an empty pwq can remain on pending_pwqs when its refcnt reaches zero. pwq_release_workfn() currently puts the pool before removing that pwq. If this drops the last pool reference, the pool can be RCU-freed while the pwq remains reachable, and node_activate_pending_pwq() may trylock the freed pool->lock.
Remove the pwq from pending_pwqs before putting the pool.
kernel/workqueue.c +6 -6
@@ -5294,12 +5294,6 @@ static void pwq_release_workfn(struct kthread_work *work)mutex_unlock (&wq->mutex); } -if (!is_percpu_pool (pool)) { -mutex_lock (&wq_pool_mutex); -put_unbound_pool (pool); -mutex_unlock (&wq_pool_mutex); - } -if (!list_empty (&pwq->pending_node)) {struct wq_node_nr_active *nna =wq_node_nr_active (pwq->wq, pwq->pool->node);
@@ -5309,6 +5303,12 @@ static void pwq_release_workfn(struct kthread_work *work)raw_spin_unlock_irq (&nna->lock); } +if (!is_percpu_pool (pool)) { +mutex_lock (&wq_pool_mutex); +put_unbound_pool (pool); +mutex_unlock (&wq_pool_mutex); + } +kfree_rcu (pwq, rcu);/*
Sasha Levin
maintainerPATCH 1/2 workqueue: release pwq pools by pool type
From: Breno Leitao <[email protected]>
[ Upstream commit 3180ee71b676845603274c66f6bb5528939cf470 ]
Add is_percpu_pool() and test the pool directly for per cpu. Convert the other open-coded pool->cpu checks -- in put_unbound_pool(), pool_allowed_cpus() and the workqueue watchdog -- to the same helper.
No functional change.
Use a single-evaluation macro for is_percpu_pool() so the predicate conversion does not add a function. Keep the existing watchdog stall accounting; only its pool-type check needs to change. This preserves the release-path context needed by the pending-pwq lifetime fix.
Stable-dep-of: cf9c8aaea0d4 ("workqueue: Fix unbound pool lifetime for pending pwqs")
--- kernel/workqueue.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/workqueue.c +6 -4
@@ -1559,6 +1559,8 @@ work_func_t wq_worker_last_func(struct task_struct *task)return worker->last_func; } +#define is_percpu_pool (pool) ((pool)->cpu >= 0) +/** * wq_node_nr_active - Determine wq_node_nr_active to use * @wq: workqueue of interest
@@ -2683,7 +2685,7 @@ static struct worker *alloc_worker(int node)static cpumask_t *pool_allowed_cpus (struct worker_pool *pool) { -if (pool->cpu <0 && pool->attrs->affn_strict) +if (!is_percpu_pool (pool) && pool->attrs->affn_strict)return pool->attrs->__pod_cpumask;else return pool->attrs->cpumask;
@@ -4969,7 +4971,7 @@ static void put_unbound_pool(struct worker_pool *pool)return ;/* sanity checks */ -if (WARN_ON (!(pool->cpu <0 )) || +if (WARN_ON (is_percpu_pool (pool)) ||WARN_ON (!list_empty (&pool->worklist)))return ;
@@ -5121,7 +5123,7 @@ static void pwq_release_workfn(struct kthread_work *work)mutex_unlock (&wq->mutex); } -if (wq->flags &WQ_UNBOUND ) { +if (!is_percpu_pool (pool)) {mutex_lock (&wq_pool_mutex);put_unbound_pool (pool);mutex_unlock (&wq_pool_mutex);
@@ -7639,7 +7641,7 @@ static void wq_watchdog_timer_fn(struct timer_list *unused)/* did we stall? */ if (time_after (now, ts + thresh)) { lockup_detected = true; -if (pool->cpu >=0 && !(pool->flags &POOL_BH )) { +if (is_percpu_pool (pool) && !(pool->flags &POOL_BH )) { pool->cpu_stall = true; cpu_pool_stall = true; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 workqueue: Fix unbound pool lifetime for pending pwqs
From: Yao Kai <[email protected]>
[ Upstream commit cf9c8aaea0d47410df8708bec195889f3a85cd3c ]
KASAN reports a use-after-free of an unbound worker_pool in node_activate_pending_pwq():
BUG: KASAN: slab-use-after-free in _raw_spin_trylock+0x6d/0x120 Read of size 4 at addr ffff8880089ce000 by task kworker/u22:0/318 CPU: 1 UID: 0 PID: 318 Comm: kworker/u22:0 Not tainted 7.2.0 #1 PREEMPT(lazy) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 Workqueue: 0x0 (flush-8:0) Call Trace: <TASK> dump_stack_lvl+0x53/0x70 print_report+0xce/0x610 kasan_report+0xce/0x100 _raw_spin_trylock+0x6d/0x120 pwq_dec_nr_in_flight+0x4b4/0xcb0 process_one_work+0x921/0x11a0 worker_thread+0x4d0/0xd20 kthread+0x2de/0x3c0 ret_from_fork+0x3aa/0x620 ret_from_fork_asm+0x1a/0x30 </TASK> Allocated by task 311: alloc_pwq+0x439/0xca0 apply_wqattrs_prepare+0x75e/0xd10 apply_workqueue_attrs_locked+0x44/0xa0 wq_nice_store+0x350/0x450 Freed by task 0: kfree+0x127/0x3b0 rcu_core+0x523/0x1780 handle_softirqs+0x1b3/0x610 Last potentially related work creation: put_unbound_pool+0x3f3/0x7d0 pwq_release_workfn+0x494/0x8e0 kthread_worker_fn+0x1ff/0x790
Canceling the last inactive work skips pwq_dec_nr_active(), so an empty pwq can remain on pending_pwqs when its refcnt reaches zero. pwq_release_workfn() currently puts the pool before removing that pwq. If this drops the last pool reference, the pool can be RCU-freed while the pwq remains reachable, and node_activate_pending_pwq() may trylock the freed pool->lock.
Remove the pwq from pending_pwqs before putting the pool.
--- kernel/workqueue.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
kernel/workqueue.c +6 -6
@@ -5123,12 +5123,6 @@ static void pwq_release_workfn(struct kthread_work *work)mutex_unlock (&wq->mutex); } -if (!is_percpu_pool (pool)) { -mutex_lock (&wq_pool_mutex); -put_unbound_pool (pool); -mutex_unlock (&wq_pool_mutex); - } -if (!list_empty (&pwq->pending_node)) {struct wq_node_nr_active *nna =wq_node_nr_active (pwq->wq, pwq->pool->node);
@@ -5138,6 +5132,12 @@ static void pwq_release_workfn(struct kthread_work *work)raw_spin_unlock_irq (&nna->lock); } +if (!is_percpu_pool (pool)) { +mutex_lock (&wq_pool_mutex); +put_unbound_pool (pool); +mutex_unlock (&wq_pool_mutex); + } +kfree_rcu (pwq, rcu);/*
Signature · 1 line
2.53.0