* [PATCH -stable] kthreads: fix kthread_create() vs kthread_stop() race
@ 2009-08-24 10:45 Oleg Nesterov
2009-08-25 14:36 ` Rusty Russell
0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2009-08-24 10:45 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rusty Russell; +Cc: Robert Peterson, stable, linux-kernel
The bug should be "accidently" fixed by recent changes in 2.6.31,
all kernels <= 2.6.30 need the fix. The problem was never noticed before,
it was found because it causes mysterious failures with GFS mount/umount.
Credits to Robert Peterson. He blaimed kthread.c from the very beginning.
But, despite my promise, I forgot to inspect the old implementation until
he did a lot of testing and reminded me. This led to huge delay in fixing
this bug.
kthread_stop() does put_task_struct(k) before it clears kthread_stop_info.k.
This means another kthread_create() can re-use this task_struct, but the
new kthread can still see kthread_should_stop() == T and exit even without
calling threadfn().
Reported-by: Robert Peterson <rpeterso@redhat.com>
Tested-by: Robert Peterson <rpeterso@redhat.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -216,12 +216,12 @@ int kthread_stop(struct task_struct *k)
/* Now set kthread_should_stop() to true, and wake it up. */
kthread_stop_info.k = k;
wake_up_process(k);
- put_task_struct(k);
/* Once it dies, reset stop ptr, gather result and we're done. */
wait_for_completion(&kthread_stop_info.done);
kthread_stop_info.k = NULL;
ret = kthread_stop_info.err;
+ put_task_struct(k);
mutex_unlock(&kthread_stop_lock);
trace_sched_kthread_stop_ret(ret);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH -stable] kthreads: fix kthread_create() vs kthread_stop() race
2009-08-24 10:45 [PATCH -stable] kthreads: fix kthread_create() vs kthread_stop() race Oleg Nesterov
@ 2009-08-25 14:36 ` Rusty Russell
0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2009-08-25 14:36 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: Greg Kroah-Hartman, Robert Peterson, stable, linux-kernel
On Mon, 24 Aug 2009 08:15:29 pm Oleg Nesterov wrote:
> The bug should be "accidently" fixed by recent changes in 2.6.31,
> all kernels <= 2.6.30 need the fix. The problem was never noticed before,
> it was found because it causes mysterious failures with GFS mount/umount.
>
> Credits to Robert Peterson. He blaimed kthread.c from the very beginning.
> But, despite my promise, I forgot to inspect the old implementation until
> he did a lot of testing and reminded me. This led to huge delay in fixing
> this bug.
>
> kthread_stop() does put_task_struct(k) before it clears kthread_stop_info.k.
> This means another kthread_create() can re-use this task_struct, but the
> new kthread can still see kthread_should_stop() == T and exit even without
> calling threadfn().
>
> Reported-by: Robert Peterson <rpeterso@redhat.com>
> Tested-by: Robert Peterson <rpeterso@redhat.com>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Thanks, good catch!
Rusty.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-08-25 14:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-24 10:45 [PATCH -stable] kthreads: fix kthread_create() vs kthread_stop() race Oleg Nesterov
2009-08-25 14:36 ` Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox