btrfs: tree-checker: Don't check device size as we can have valid 0 total_bytes
PATCH 1/1 btrfs: tree-checker: Don't check device size as we can have valid 0 total_bytes
Under the following call traces, btrfs can commit device with 0 total_bytes onto disk:btrfs_rm_device()
|- btrfs_shrink_device() | |- btrfs_device_set_total_bytes(device, 0) | |- btrfs_update_device() | |- btrfs_commit_transaction() #1 |- btrfs_rm_dev_item()
This will trigger write time tree checker warning.
And further more, this can create valid btrfs with device->total_bytes == 0 and triggering read time tree-checker if power loss happens after above transaction #1 but before next transaction.
So this dev item check is too restrict.
Please fold this patch into commit 87d87c6dcbbe ("btrfs: tree-checker:
Verify dev item") in misc-next branch.
The fuzzed image can be already addressed by commit 1b3922a8bc74 ("btrfs: Use real device structure to verify dev extent") thus we don't need that strict check anymore.
--- fs/btrfs/tree-checker.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
fs/btrfs/tree-checker.c +4 -9
@@ -657,16 +657,11 @@ static int check_dev_item(struct extent_buffer *leaf, }/* -* Since btrfs device add doesn't check device size at all, we could -* have device item whose size is smaller than 1M which is useless, but -* still valid. -* So here we can only check the obviously wrong case. +* For device total_bytes, we don't have solid way to check it, as it can +* be 0 for device removal. +* device size check can only be done by dev extents check. */ -if (btrfs_device_total_bytes (leaf, ditem) ==0 ) { -dev_item_err (leaf, slot, -"invalid total bytes: have 0" ); -return -EUCLEAN ; - } +if (btrfs_device_bytes_used (leaf, ditem) >btrfs_device_total_bytes (leaf, ditem)) { dev_item_err(leaf, slot,
Signature · 1 line
2.21.0
Quoted 14 lines · Qu Wenruo
Under the following call traces, btrfs can commit device with 0
total_bytesonto disk:btrfs_rm_device()|- btrfs_shrink_device() | |- btrfs_device_set_total_bytes(device, 0) | |- btrfs_update_device() | |- btrfs_commit_transaction() #1 |- btrfs_rm_dev_item()This will trigger write time tree checker warning.
And further more, this can create valid btrfs withdevice->total_bytes== 0 and triggering read time tree-checker if power loss happens after above transaction #1 but before next transaction.
Quoted 8 lines
So this dev item check is too restrict.
Please fold this patch into commit
87d87c6dcbbe("btrfs: tree-checker:
Verify dev item") in misc-next branch.The fuzzed image can be already addressed by commit
1b3922a8bc74("btrfs: Use real device structure to verify dev extent") thus we don't need that strict check anymore.
Just a kind reminder, folding the patch will be much easier than my original purpose to discard that patch completely.
Discarding causes at least 4 conflicts, and will be a pain in the ass.
Thanks,
Qu
Quoted 32 lines
Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/tree-checker.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)fs/btrfs/tree-checker.c +4
-9@@ -657,16 +657,11 @@ static int check_dev_item(struct extent_buffer *leaf, }/* -* Since btrfs device add doesn't check device size at all, we could -* have device item whose size is smaller than 1M which is useless, but -* still valid. -* So here we can only check the obviously wrong case. +* For device total_bytes, we don't have solid way to check it, as it can +* be 0 for device removal. +* device size check can only be done by dev extents check. */ -if (btrfs_device_total_bytes (leaf, ditem) ==0 ) { -dev_item_err (leaf, slot, -"invalid total bytes: have 0" ); -return -EUCLEAN ; - } +if (btrfs_device_bytes_used (leaf, ditem) >btrfs_device_total_bytes (leaf, ditem)) { dev_item_err(leaf, slot,
Quoted 22 lines · Qu Wenruo
Quoted 19 lines · Qu Wenruo
Under the following call traces, btrfs can commit device with 0
total_bytesonto disk:btrfs_rm_device()|- btrfs_shrink_device() | |- btrfs_device_set_total_bytes(device, 0) | |- btrfs_update_device() | |- btrfs_commit_transaction() #1 |- btrfs_rm_dev_item()This will trigger write time tree checker warning.
And further more, this can create valid btrfs withdevice->total_bytes== 0 and triggering read time tree-checker if power loss happens after above transaction #1 but before next transaction.So this dev item check is too restrict.
Please fold this patch into commit
87d87c6dcbbe("btrfs: tree-checker:
Verify dev item") in misc-next branch.
Quoted 6 lines
Quoted 3 lines
The fuzzed image can be already addressed by commit
1b3922a8bc74("btrfs: Use real device structure to verify dev extent") thus we don't need that strict check anymore.Just a kind reminder, folding the patch will be much easier than my original purpose to discard that patch completely.
Agreed and patch folded, thanks.