rpms/kernel/F-11 linux-2.6-kthreads-fix-kthread-create-vs-kthread-stop.patch, NONE, 1.1 kernel.spec, 1.1719, 1.1720

Chuck Ebbert cebbert at fedoraproject.org
Thu Aug 27 20:23:31 UTC 2009


Author: cebbert

Update of /cvs/pkgs/rpms/kernel/F-11
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv19714

Modified Files:
	kernel.spec 
Added Files:
	linux-2.6-kthreads-fix-kthread-create-vs-kthread-stop.patch 
Log Message:
linux-2.6-kthreads-fix-kthread-create-vs-kthread-stop.patch:
  fix race in kthreads.

linux-2.6-kthreads-fix-kthread-create-vs-kthread-stop.patch:
 kthread.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- NEW FILE linux-2.6-kthreads-fix-kthread-create-vs-kthread-stop.patch ---
Date	Mon, 24 Aug 2009 12:45:29 +0200
From	Oleg Nesterov <>
Subject	[PATCH -stable] kthreads: fix kthread_create() vs kthread_stop() race

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 at redhat.com>
Tested-by: Robert Peterson <rpeterso at redhat.com>
Signed-off-by: Oleg Nesterov <oleg at 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);


Index: kernel.spec
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/F-11/kernel.spec,v
retrieving revision 1.1719
retrieving revision 1.1720
diff -u -p -r1.1719 -r1.1720
--- kernel.spec	27 Aug 2009 19:40:55 -0000	1.1719
+++ kernel.spec	27 Aug 2009 20:23:30 -0000	1.1720
@@ -735,6 +735,10 @@ Patch14040: linux-2.6-clone-fix-race-bet
 # Fix string overflows found by stackprotector:
 Patch14050: hda-check-strcpy-length.patch
 Patch14060: linux-2.6-v4l-dvb-af9015-fix-stack-corruption.patch
+
+# fix race in kthreads
+Patch14070: linux-2.6-kthreads-fix-kthread-create-vs-kthread-stop.patch
+
 %endif
 
 BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root
@@ -1362,6 +1366,9 @@ ApplyPatch linux-2.6-clone-fix-race-betw
 ApplyPatch hda-check-strcpy-length.patch
 ApplyPatch linux-2.6-v4l-dvb-af9015-fix-stack-corruption.patch
 
+# fix race in kthreads
+ApplyPatch linux-2.6-kthreads-fix-kthread-create-vs-kthread-stop.patch
+
 # END OF PATCH APPLICATIONS
 
 %endif
@@ -1947,6 +1954,10 @@ fi
 # and build.
 
 %changelog
+* Thu Aug 27 2009 Chuck Ebbert <cebbert at redhat.com> 2.6.30.5-41
+- linux-2.6-kthreads-fix-kthread-create-vs-kthread-stop.patch:
+  fix race in kthreads.
+
 * Thu Aug 27 2009 Justin M. Forbes <jforbes at redhat.com> 2.6.30.5-40
 - xen: Fix guest crash when trying to debug. (#458385)
 




More information about the scm-commits mailing list