Commit a076e4bca2fdabb9e45d86722cc72c0944da5f94

Authored by Oleg Nesterov
Committed by Linus Torvalds
1 parent 49b12d4f5e

freezer: fix kthread_create vs freezer theoretical race

kthread() sleeps in TASK_INTERRUPTIBLE state waiting for the first wakeup.  In
theory, this wakeup may come from freeze_process()->signal_wake_up(), so the
task can disappear even before kthread_create() sets its ->comm.

Change kthread() to use TASK_UNINTERRUPTIBLE.

[akpm@linux-foundation.org: s/BUG_ON/WARN_ON+recover]
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Gautham R Shenoy <ego@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 5 additions and 2 deletions Side-by-side Diff

... ... @@ -70,7 +70,7 @@
70 70 data = create->data;
71 71  
72 72 /* OK, tell user we're spawned, wait for stop or wakeup */
73   - __set_current_state(TASK_INTERRUPTIBLE);
  73 + __set_current_state(TASK_UNINTERRUPTIBLE);
74 74 complete(&create->started);
75 75 schedule();
76 76  
... ... @@ -162,7 +162,10 @@
162 162 */
163 163 void kthread_bind(struct task_struct *k, unsigned int cpu)
164 164 {
165   - BUG_ON(k->state != TASK_INTERRUPTIBLE);
  165 + if (k->state != TASK_UNINTERRUPTIBLE) {
  166 + WARN_ON(1);
  167 + return;
  168 + }
166 169 /* Must have done schedule() in kthread() before we set_task_cpu */
167 170 wait_task_inactive(k);
168 171 set_task_cpu(k, cpu);