md: protect against NULL reference when waiting to start a raid10.
commitc3a057e54f2cb3efc797633d7d7102db90beed50
authorNeilBrown <neilb@suse.de>
Thu, 9 Dec 2010 06:02:14 +0000 (9 17:02 +1100)
committerAK <andi@firstfloor.org>
Sun, 6 Feb 2011 19:03:42 +0000 (6 11:03 -0800)
tree1eb585a774e8adb5eff510e7603b3781e5f2bf2d
parent1eb3d729169b026e40f0094f0d602187ebdff165
md: protect against NULL reference when waiting to start a raid10.

commit 589a594be1fb8815b3f18e517be696c48664f728 upstream.

When we fail to start a raid10 for some reason, we call
md_unregister_thread to kill the thread that was created.

Unfortunately md_thread() will then make one call into the handler
(raid10d) even though md_wakeup_thread has not been called.  This is
not safe and as md_unregister_thread is called after mddev->private
has been set to NULL, it will definitely cause a NULL dereference.

So fix this at both ends:
 - md_thread should only call the handler if THREAD_WAKEUP has been
   set.
 - raid10 should call md_unregister_thread before setting things
   to NULL just like all the other raid modules do.

This is applicable to 2.6.35 and later.

Reported-by: "Citizen" <citizen_lee@thecus.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
drivers/md/md.c
drivers/md/raid10.c