workqueue: fix a possible race condition between rescuer and pwq-release
authorLai Jiangshan <laijs@cn.fujitsu.com>
Fri, 18 Apr 2014 15:04:16 +0000 (11:04 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jun 2014 20:25:37 +0000 (13:25 -0700)
commitaac8b37ffaa2bacc0430aa7b45c7d3aad22209fc
treeb2061b8c2c2ca16ac58ca648ba27c51bcd1adb2a
parent55a3dfcc84ab3dc82708d93cd0bca4a0aad7715c
workqueue: fix a possible race condition between rescuer and pwq-release

commit 77668c8b559e4fe2acf2a0749c7c83cde49a5025 upstream.

There is a race condition between rescuer_thread() and
pwq_unbound_release_workfn().

Even after a pwq is scheduled for rescue, the associated work items
may be consumed by any worker.  If all of them are consumed before the
rescuer gets to them and the pwq's base ref was put due to attribute
change, the pwq may be released while still being linked on
@wq->maydays list making the rescuer dereference already freed pwq
later.

Make send_mayday() pin the target pwq until the rescuer is done with
it.

tj: Updated comment and patch description.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/workqueue.c