Re: [PATCH v3] btrfs: free-space-tree: reject mismatched extent and bitmap items
From: Qu Wenruo
Date: Tue May 12 2026 - 18:01:11 EST
在 2026/5/13 00:48, David Sterba 写道:
On Sun, May 10, 2026 at 11:03:22PM +0800, Zhang Cen wrote:I have already submitted tree-checker enhancement to address this:
+static int validate_free_space_key(struct btrfs_block_group *block_group,
+ const struct btrfs_key *key,
+ u8 expected_type)
+{
+ const u64 end = btrfs_block_group_end(block_group);
+
+ if (unlikely(key->type != expected_type)) {
+ btrfs_err(block_group->fs_info,
+ "block group %llu has unexpected free space key type %u, expected %u",
+ block_group->start, key->type, expected_type);
+ return -EUCLEAN;
+ }
+
+ if (unlikely(key->objectid + key->offset > end)) {
This has a review comment https://sashiko.dev/#/patchset/20260510152848.3844894-1-rollkingzzc%40gmail.com
that the expression can overflow. I did a light check if it is valid at
all (we're still evaluating the quality of AI reviews) but I think in
this case more checks to the key.offset and key.objectid could be added.
As this would is in checker it's meant to be extensive so partially
overlapping conditions are not a problem.
https://lore.kernel.org/linux-btrfs/cover.1778460959.git.wqu@xxxxxxxx/T/
Which adds extra overflow and overlap checks for fst.
Thanks,
Qu