Skip to content

Commit

Permalink
md: raid0/linear: fix dereference before null check on pointer mddev
Browse files Browse the repository at this point in the history
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 <colin.king@canonical.com>
Reviewed-by: Guilherme G. Piccoli <gpiccoli@canonical.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
  • Loading branch information
Colin Ian King authored and Song Liu committed Jul 14, 2020
1 parent 2eaac32 commit 9a5a859
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,18 @@ static blk_qc_t md_submit_bio(struct bio *bio)
struct mddev *mddev = bio->bi_disk->private_data;
unsigned int sectors;

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

blk_queue_split(&bio);

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

blk_queue_split(&bio);

if (mddev->ro == 1 && unlikely(rw == WRITE)) {
if (bio_sectors(bio) != 0)
bio->bi_status = BLK_STS_IOERR;
Expand Down

0 comments on commit 9a5a859

Please sign in to comment.