]> git.karo-electronics.de Git - karo-tx-linux.git/commit
freezer: fix current->state restoration race in refrigerator()
authorTejun Heo <tj@kernel.org>
Sat, 20 Aug 2011 09:31:39 +0000 (11:31 +0200)
committerTejun Heo <tj@kernel.org>
Sat, 20 Aug 2011 09:31:39 +0000 (11:31 +0200)
commitf0043f7496d92de839b0582b0343d2ebc92f9bde
treefefa42deaeb68ec95e9eecf3d84406743640b79a
parentaf0fa9cb7923ad65da11a71cef89fc4860fb618a
freezer: fix current->state restoration race in refrigerator()

refrigerator() saves current->state before entering frozen state and
restores it before returning using __set_current_state(); however,
this is racy, for example, please consider the following sequence.

set_current_state(TASK_INTERRUPTIBLE);
try_to_freeze();
if (kthread_should_stop())
break;
schedule();

If kthread_stop() races with ->state restoration, the restoration can
restore ->state to TASK_INTERRUPTIBLE after kthread_stop() sets it to
TASK_RUNNING but kthread_should_stop() may still see zero
->should_stop because there's no memory barrier between restoring
TASK_INTERRUPTIBLE and kthread_should_stop() test.

This isn't restricted to kthread_should_stop().  current->state is
often used in memory barrier based synchronization and silently
restoring it w/o mb breaks them.

Use set_current_state() instead.

Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/freezer.c