Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 (24afd80d99) and can cause an
oops, so fix is suitable for any -stable since then.

Cc: stable@vger.kernel.org (3.3+)
Signed-off-by: NeilBrown <neilb@suse.de>

NeilBrown 0eb25bb0 30bc9b53

+7 -1
+7 -1
drivers/md/raid10.c
··· 2290 2290 d = r10_bio->devs[1].devnum; 2291 2291 wbio = r10_bio->devs[1].bio; 2292 2292 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; 2293 2299 if (wbio->bi_end_io) { 2294 2300 atomic_inc(&conf->mirrors[d].rdev->nr_pending); 2295 2301 md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(wbio)); 2296 2302 generic_make_request(wbio); 2297 2303 } 2298 - if (wbio2 && wbio2->bi_end_io) { 2304 + if (wbio2) { 2299 2305 atomic_inc(&conf->mirrors[d].replacement->nr_pending); 2300 2306 md_sync_acct(conf->mirrors[d].replacement->bdev, 2301 2307 bio_sectors(wbio2));