]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
md: protect against NULL reference when waiting to start a raid10.
authorNeilBrown <neilb@suse.de>
Thu, 9 Dec 2010 06:02:14 +0000 (17:02 +1100)
committerAK <andi@firstfloor.org>
Sun, 6 Feb 2011 19:03:42 +0000 (11:03 -0800)
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

index 7265d117afd791dde0bb3d926e2495419b6e80ff..ef1dae2770caaaf9963c943e77ce26536764a2d1 100644 (file)
@@ -5989,9 +5989,8 @@ static int md_thread(void * arg)
                         || kthread_should_stop(),
                         thread->timeout);
 
-               clear_bit(THREAD_WAKEUP, &thread->flags);
-
-               thread->run(thread->mddev);
+               if (test_and_clear_bit(THREAD_WAKEUP, &thread->flags))
+                       thread->run(thread->mddev);
        }
 
        return 0;
index d1d6891263469f5c84be025c004e411ed93f2171..66fe4874ffd8a3db96f19abfc6842123be2a9685 100644 (file)
@@ -2393,13 +2393,13 @@ static int run(mddev_t *mddev)
        return 0;
 
 out_free_conf:
+       md_unregister_thread(mddev->thread);
        if (conf->r10bio_pool)
                mempool_destroy(conf->r10bio_pool);
        safe_put_page(conf->tmppage);
        kfree(conf->mirrors);
        kfree(conf);
        mddev->private = NULL;
-       md_unregister_thread(mddev->thread);
 out:
        return -EIO;
 }