Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0eb25bb

Browse files
committed
md/raid10: remove use-after-free bug.
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 (24afd80) and can cause an oops, so fix is suitable for any -stable since then. Cc: [email protected] (3.3+) Signed-off-by: NeilBrown <[email protected]>
1 parent 30bc9b5 commit 0eb25bb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/md/raid10.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2290,12 +2290,18 @@ static void recovery_request_write(struct mddev *mddev, struct r10bio *r10_bio)
22902290
d = r10_bio->devs[1].devnum;
22912291
wbio = r10_bio->devs[1].bio;
22922292
wbio2 = r10_bio->devs[1].repl_bio;
2293+
/* Need to test wbio2->bi_end_io before we call
2294+
* generic_make_request as if the former is NULL,
2295+
* the latter is free to free wbio2.
2296+
*/
2297+
if (wbio2 && !wbio2->bi_end_io)
2298+
wbio2 = NULL;
22932299
if (wbio->bi_end_io) {
22942300
atomic_inc(&conf->mirrors[d].rdev->nr_pending);
22952301
md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(wbio));
22962302
generic_make_request(wbio);
22972303
}
2298-
if (wbio2 && wbio2->bi_end_io) {
2304+
if (wbio2) {
22992305
atomic_inc(&conf->mirrors[d].replacement->nr_pending);
23002306
md_sync_acct(conf->mirrors[d].replacement->bdev,
23012307
bio_sectors(wbio2));

0 commit comments

Comments
 (0)