diff options
author | NeilBrown <neilb@suse.de> | 2010-12-09 01:02:14 -0500 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2010-12-09 01:02:14 -0500 |
commit | 589a594be1fb8815b3f18e517be696c48664f728 (patch) | |
tree | 9de6f6b4f9244802ccf77312f7fba8612dd13a75 /drivers/md | |
parent | 1a855a0606653d2d82506281e2c686bacb4b2f45 (diff) |
md: protect against NULL reference when waiting to start a raid10.
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.
Cc: stable@kernel.org
Reported-by: "Citizen" <citizen_lee@thecus.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/md.c | 5 | ||||
-rw-r--r-- | drivers/md/raid10.c | 2 |
2 files changed, 3 insertions, 4 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c index b757da175180..e71c5fa527f5 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -6044,9 +6044,8 @@ static int md_thread(void * arg) | |||
6044 | || kthread_should_stop(), | 6044 | || kthread_should_stop(), |
6045 | thread->timeout); | 6045 | thread->timeout); |
6046 | 6046 | ||
6047 | clear_bit(THREAD_WAKEUP, &thread->flags); | 6047 | if (test_and_clear_bit(THREAD_WAKEUP, &thread->flags)) |
6048 | 6048 | thread->run(thread->mddev); | |
6049 | thread->run(thread->mddev); | ||
6050 | } | 6049 | } |
6051 | 6050 | ||
6052 | return 0; | 6051 | return 0; |
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index c67aa54694ae..0641674827f0 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c | |||
@@ -2397,13 +2397,13 @@ static int run(mddev_t *mddev) | |||
2397 | return 0; | 2397 | return 0; |
2398 | 2398 | ||
2399 | out_free_conf: | 2399 | out_free_conf: |
2400 | md_unregister_thread(mddev->thread); | ||
2400 | if (conf->r10bio_pool) | 2401 | if (conf->r10bio_pool) |
2401 | mempool_destroy(conf->r10bio_pool); | 2402 | mempool_destroy(conf->r10bio_pool); |
2402 | safe_put_page(conf->tmppage); | 2403 | safe_put_page(conf->tmppage); |
2403 | kfree(conf->mirrors); | 2404 | kfree(conf->mirrors); |
2404 | kfree(conf); | 2405 | kfree(conf); |
2405 | mddev->private = NULL; | 2406 | mddev->private = NULL; |
2406 | md_unregister_thread(mddev->thread); | ||
2407 | out: | 2407 | out: |
2408 | return -EIO; | 2408 | return -EIO; |
2409 | } | 2409 | } |