aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2013-07-24 01:37:42 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-04 04:50:55 -0400
commit5a4de615144fd87589783402cab3ecbc29865fc8 (patch)
treee0115a3be78f242bf915cd679226bd2578815690 /drivers/md
parentc1dadcc1086bbbac1b5eeb4d5e157c76f2d8dfba (diff)
md/raid10: remove use-after-free bug.
commit 0eb25bb027a100f5a9df8991f2f628e7d851bc1e upstream. We always need to be careful when calling generic_make_request, as it can start a chain of events which might free something that we are using. Here is one place I wasn't careful enough. If the wbio2 is not in use, then it might get freed at the first generic_make_request call. So perform all necessary tests first. This bug was introduced in 3.3-rc3 (24afd80d99) and can cause an oops, so fix is suitable for any -stable since then. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/raid10.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index d61eb7ea0d81..081bb3345353 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -2268,12 +2268,18 @@ static void recovery_request_write(struct mddev *mddev, struct r10bio *r10_bio)
2268 d = r10_bio->devs[1].devnum; 2268 d = r10_bio->devs[1].devnum;
2269 wbio = r10_bio->devs[1].bio; 2269 wbio = r10_bio->devs[1].bio;
2270 wbio2 = r10_bio->devs[1].repl_bio; 2270 wbio2 = r10_bio->devs[1].repl_bio;
2271 /* Need to test wbio2->bi_end_io before we call
2272 * generic_make_request as if the former is NULL,
2273 * the latter is free to free wbio2.
2274 */
2275 if (wbio2 && !wbio2->bi_end_io)
2276 wbio2 = NULL;
2271 if (wbio->bi_end_io) { 2277 if (wbio->bi_end_io) {
2272 atomic_inc(&conf->mirrors[d].rdev->nr_pending); 2278 atomic_inc(&conf->mirrors[d].rdev->nr_pending);
2273 md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(wbio)); 2279 md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(wbio));
2274 generic_make_request(wbio); 2280 generic_make_request(wbio);
2275 } 2281 }
2276 if (wbio2 && wbio2->bi_end_io) { 2282 if (wbio2) {
2277 atomic_inc(&conf->mirrors[d].replacement->nr_pending); 2283 atomic_inc(&conf->mirrors[d].replacement->nr_pending);
2278 md_sync_acct(conf->mirrors[d].replacement->bdev, 2284 md_sync_acct(conf->mirrors[d].replacement->bdev,
2279 bio_sectors(wbio2)); 2285 bio_sectors(wbio2));