btrfs: check-integrity: Fix NULL pointer dereference for degraded mount
PATCH 1/1 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 how we index device state hash.
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.
---
Please note there are still quite some problem about check-integrity, including:
1) Warning for degraded mount
2) Meaningless empty lines output
This patch will only fix the obvious NULL pointer dereference exposed by btrfs/027 with "check_int" mount option.
--- fs/btrfs/check-integrity.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/btrfs/check-integrity.c +6 -1
@@ -1539,7 +1539,12 @@ static int btrfsic_map_block(struct btrfsic_state *state, u64 bytenr, u32 len, } device = multi->stripes[0 ].dev; - block_ctx_out->dev =btrfsic_dev_state_lookup (device->bdev->bd_dev); +if (test_bit (BTRFS_DEV_STATE_MISSING , &device->dev_state) || + !device->bdev || !device->name) + block_ctx_out->dev =NULL ; +else + block_ctx_out->dev =btrfsic_dev_state_lookup ( + device->bdev->bd_dev); block_ctx_out->dev_bytenr = multi->stripes[0 ].physical; block_ctx_out->start = bytenr; block_ctx_out->len = len;
Signature · 1 line
2.17.1
Quoted 10 lines · Qu Wenruo
Commit
f8f84b2dfda5("btrfs: index check-integrity state hash by adev_t") changed how btrfsic how we index device state hash.Now we need to access
device->bdev->bd_dev, while for degraded mount it's completely possible to havedevice->bdevas 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.
Quoted 6 lines
There are a lot of other places accessing
device->bdev->bd_dev, however the other call sites have either checkeddevice->bdev, or thedevice->bdevis passed frombtrfsic_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 <[email protected]>
Added to misc-next. As it is a fix it could go to 4.18 but I'd rather have a good reason for that because it's in a debugging feature.
Quoted 8 lines
---
Please note there are still quite some problem about check-integrity, including:
1) Warning for degraded mount
2) Meaningless empty lines outputThis patch will only fix the obvious NULL pointer dereference exposed by btrfs/027 with "
check_int" mount option.
Ok.
Quoted 15 lines · David Sterba
Quoted 14 lines · Qu Wenruo
Commit
f8f84b2dfda5("btrfs: index check-integrity state hash by adev_t") changed how btrfsic how we index device state hash.Now we need to access
device->bdev->bd_dev, while for degraded mount it's completely possible to havedevice->bdevas 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 checkeddevice->bdev, or thedevice->bdevis passed frombtrfsic_map_block(), so it won't cause harm.
Quoted 5 lines
Quoted 2 lines
Fixes f8f84b2dfda5 ("btrfs: index check-integrity state hash by a dev_t")Signed-off-by Qu Wenruo <[email protected]>Added to misc-next. As it is a fix it could go to 4.18 but I'd rather have a good reason for that because it's in a debugging feature.
No need to push it to 4.18.
Indeed it's a debug feature, and furthermore, there are tons of bugs exposed by fstests, so it's better to fix it as a large serious patchset.
Thanks,
Qu
Quoted 16 lines
Quoted 9 lines
---
Please note there are still quite some problem about check-integrity, including:
1) Warning for degraded mount
2) Meaningless empty lines outputThis patch will only fix the obvious NULL pointer dereference exposed by btrfs/027 with "
check_int" mount option.Ok.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 21 lines · Qu Wenruo
Quoted 18 lines · David Sterba
Quoted 16 lines · Qu Wenruo
Commit
f8f84b2dfda5("btrfs: index check-integrity state hash by adev_t") changed how btrfsic how we index device state hash.Now we need to access
device->bdev->bd_dev, while for degraded mount it's completely possible to havedevice->bdevas 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 checkeddevice->bdev, or thedevice->bdevis passed frombtrfsic_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 <[email protected]>
Quoted 8 lines
Quoted 2 lines
Added to misc-next. As it is a fix it could go to 4.18 but I'd rather have a good reason for that because it's in a debugging feature.
No need to push it to 4.18.
Indeed it's a debug feature, and furthermore, there are tons of bugs exposed by fstests, so it's better to fix it as a large serious patchset.
If buffer heads are eliminated from btrfs then we can remove a substantial portion of the integrity checking code.