Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 589a594b authored by NeilBrown's avatar NeilBrown
Browse files

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: default avatar"Citizen" <citizen_lee@thecus.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent 1a855a06
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -6044,8 +6044,7 @@ static int md_thread(void * arg)
			 || kthread_should_stop(),
			 thread->timeout);

		clear_bit(THREAD_WAKEUP, &thread->flags);

		if (test_and_clear_bit(THREAD_WAKEUP, &thread->flags))
			thread->run(thread->mddev);
	}

+1 −1
Original line number Diff line number Diff line
@@ -2397,13 +2397,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;
}