btrfs: deal with missing root in sample_block_group_extent_item()

In case the root does not exists, which is unexpected, btrfs_extent_root()
returns NULL, but we ignore that and so if it happens we can trigger a
NULL pointer dereference later. So verify if we found the root and log an
error message in case it's missing.

Reviewed-by: Boris Burkov <boris@bur.io>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Filipe Manana
2026-01-21 20:48:35 +00:00
committed by David Sterba
parent 79d51b5c7a
commit a8bec25e01

View File

@@ -607,6 +607,12 @@ static int sample_block_group_extent_item(struct btrfs_caching_control *caching_
lockdep_assert_held_read(&fs_info->commit_root_sem);
extent_root = btrfs_extent_root(fs_info, block_group->start);
if (unlikely(!extent_root)) {
btrfs_err(fs_info,
"missing extent root for block group at offset %llu",
block_group->start);
return -EUCLEAN;
}
search_offset = index * div_u64(block_group->length, max_index);
search_key.objectid = block_group->start + search_offset;