btrfs: check-integrity: Fix NULL pointer dereference for degraded mount
authorQu Wenruo <wqu@suse.com>
Wed, 20 Jun 2018 07:38:58 +0000 (15:38 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 6 Aug 2018 11:12:38 +0000 (13:12 +0200)
commit9912bbf6440ba0555e91d3306520da01872c7c1d
tree861abacfd17adf6fba9e9483bcdee438e45da725
parent43a7e99db6788110fb2bd97bdad5aa5c0c004aff
btrfs: check-integrity: Fix NULL pointer dereference for degraded mount

Commit f8f84b2dfda5 ("btrfs: index check-integrity state hash by a dev_t")
changed how btrfsic indexes device state.

Now we need to access device->bdev->bd_dev, while for degraded mount
it's completely possible to have device->bdev as NULL, thus it will
trigger a NULL pointer dereference at mount time.

Fix it by checking if the device is degraded before accessing
device->bdev->bd_dev.

There are a lot of other places accessing device->bdev->bd_dev, however
the other call sites have either checked device->bdev, or the
device->bdev is passed from btrfsic_map_block(), so it won't cause harm.

Fixes: f8f84b2dfda5 ("btrfs: index check-integrity state hash by a dev_t")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/check-integrity.c