Skip to content

Commit 9a5a859

Browse files
Colin Ian Kingliu-song-6
authored andcommitted
md: raid0/linear: fix dereference before null check on pointer mddev
Pointer mddev is being dereferenced with a test_bit call before mddev is being null checked, this may cause a null pointer dereference. Fix this by moving the null pointer checks to sanity check mddev before it is dereferenced. Addresses-Coverity: ("Dereference before null check") Fixes: 62f7b19 ("md raid0/linear: Mark array as 'broken' and fail BIOs if a member is gone") Signed-off-by: Colin Ian King <[email protected]> Reviewed-by: Guilherme G. Piccoli <[email protected]> Signed-off-by: Song Liu <[email protected]>
1 parent 2eaac32 commit 9a5a859

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/md/md.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,17 +470,18 @@ static blk_qc_t md_submit_bio(struct bio *bio)
470470
struct mddev *mddev = bio->bi_disk->private_data;
471471
unsigned int sectors;
472472

473-
if (unlikely(test_bit(MD_BROKEN, &mddev->flags)) && (rw == WRITE)) {
473+
if (mddev == NULL || mddev->pers == NULL) {
474474
bio_io_error(bio);
475475
return BLK_QC_T_NONE;
476476
}
477477

478-
blk_queue_split(&bio);
479-
480-
if (mddev == NULL || mddev->pers == NULL) {
478+
if (unlikely(test_bit(MD_BROKEN, &mddev->flags)) && (rw == WRITE)) {
481479
bio_io_error(bio);
482480
return BLK_QC_T_NONE;
483481
}
482+
483+
blk_queue_split(&bio);
484+
484485
if (mddev->ro == 1 && unlikely(rw == WRITE)) {
485486
if (bio_sectors(bio) != 0)
486487
bio->bi_status = BLK_STS_IOERR;

0 commit comments

Comments
 (0)