Skip to content

Commit 69f4524

Browse files
Lai Jiangshanmehmetb0
authored andcommitted
workqueue: Put the pwq after detaching the rescuer from the pool
BugLink: https://bugs.launchpad.net/bugs/2104873 [ Upstream commit e769461 ] The commit 68f8305("workqueue: Reap workers via kthread_stop() and remove detach_completion") adds code to reap the normal workers but mistakenly does not handle the rescuer and also removes the code waiting for the rescuer in put_unbound_pool(), which caused a use-after-free bug reported by Cheung Wall. To avoid the use-after-free bug, the pool’s reference must be held until the detachment is complete. Therefore, move the code that puts the pwq after detaching the rescuer from the pool. Reported-by: cheung wall <zzqq0103.hey@gmail.com> Cc: cheung wall <zzqq0103.hey@gmail.com> Link: https://lore.kernel.org/lkml/CAKHoSAvP3iQW+GwmKzWjEAOoPvzeWeoMO0Gz7Pp3_4kxt-RMoA@mail.gmail.com/ Fixes: 68f8305("workqueue: Reap workers via kthread_stop() and remove detach_completion") Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com> Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Noah Wager <noah.wager@canonical.com>
1 parent 7d5a9a8 commit 69f4524

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kernel/workqueue.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,12 +3511,6 @@ static int rescuer_thread(void *__rescuer)
35113511
}
35123512
}
35133513

3514-
/*
3515-
* Put the reference grabbed by send_mayday(). @pool won't
3516-
* go away while we're still attached to it.
3517-
*/
3518-
put_pwq(pwq);
3519-
35203514
/*
35213515
* Leave this pool. Notify regular workers; otherwise, we end up
35223516
* with 0 concurrency and stalling the execution.
@@ -3527,6 +3521,12 @@ static int rescuer_thread(void *__rescuer)
35273521

35283522
worker_detach_from_pool(rescuer);
35293523

3524+
/*
3525+
* Put the reference grabbed by send_mayday(). @pool might
3526+
* go away any time after it.
3527+
*/
3528+
put_pwq_unlocked(pwq);
3529+
35303530
raw_spin_lock_irq(&wq_mayday_lock);
35313531
}
35323532

0 commit comments

Comments
 (0)