Skip to content

Commit 835b69c

Browse files
Lai Jiangshangregkh
Lai Jiangshan
authored andcommitted
workqueue: Put the pwq after detaching the rescuer from the pool
[ 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 <[email protected]> Cc: cheung wall <[email protected]> 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 <[email protected]> Signed-off-by: Tejun Heo <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 8401cad commit 835b69c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kernel/workqueue.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -3516,12 +3516,6 @@ static int rescuer_thread(void *__rescuer)
35163516
}
35173517
}
35183518

3519-
/*
3520-
* Put the reference grabbed by send_mayday(). @pool won't
3521-
* go away while we're still attached to it.
3522-
*/
3523-
put_pwq(pwq);
3524-
35253519
/*
35263520
* Leave this pool. Notify regular workers; otherwise, we end up
35273521
* with 0 concurrency and stalling the execution.
@@ -3532,6 +3526,12 @@ static int rescuer_thread(void *__rescuer)
35323526

35333527
worker_detach_from_pool(rescuer);
35343528

3529+
/*
3530+
* Put the reference grabbed by send_mayday(). @pool might
3531+
* go away any time after it.
3532+
*/
3533+
put_pwq_unlocked(pwq);
3534+
35353535
raw_spin_lock_irq(&wq_mayday_lock);
35363536
}
35373537

0 commit comments

Comments
 (0)