Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934106AbZIDUQ0 (ORCPT ); Fri, 4 Sep 2009 16:16:26 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S934110AbZIDUOq (ORCPT ); Fri, 4 Sep 2009 16:14:46 -0400 Received: from kroah.org ([198.145.64.141]:36283 "EHLO coco.kroah.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934097AbZIDUOn (ORCPT ); Fri, 4 Sep 2009 16:14:43 -0400 X-Mailbox-Line: From gregkh@mini.kroah.org Fri Sep 4 13:08:56 2009 Message-Id: <20090904200855.890096059@mini.kroah.org> User-Agent: quilt/0.48-1 Date: Fri, 04 Sep 2009 13:07:50 -0700 From: Greg KH To: linux-kernel@vger.kernel.org, stable@kernel.org Cc: stable-review@kernel.org, torvalds@linux-foundation.org, akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk, Robert Peterson , Oleg Nesterov , Rusty Russell Subject: [patch 38/48] kthreads: fix kthread_create() vs kthread_stop() race References: <20090904200712.724048145@mini.kroah.org> Content-Disposition: inline; filename=kthreads-fix-kthread_create-vs-kthread_stop-race.patch In-Reply-To: <20090904201112.GA8274@kroah.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1901 Lines: 43 2.6.27-stable review patch. If anyone has any objections, please let us know. ------------------ From: Oleg Nesterov 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 Tested-by: Robert Peterson Signed-off-by: Oleg Nesterov Acked-by: Rusty Russell Signed-off-by: Greg Kroah-Hartman --- kernel/kthread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -213,12 +213,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); return ret; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/