Skip to content

Commit 5e24e9a

Browse files
Liu Bokdave
authored andcommitted
Btrfs: error out if generic_bin_search get invalid arguments
With btrfs-corrupt-block, one can set btree node/leaf's field, if we assign a negative value to node/leaf, we can get various hangs, eg. if extent_root's nritems is -2ULL, then we get stuck in btrfs_read_block_groups() because it has a while loop and btrfs_search_slot() on extent_root will always return the first child. This lets us know what's happening and returns a EINVAL to callers instead of returning the first item. Signed-off-by: Liu Bo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 6fb37b7 commit 5e24e9a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/btrfs/ctree.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,14 @@ static noinline int generic_bin_search(struct extent_buffer *eb,
17711771
unsigned long map_len = 0;
17721772
int err;
17731773

1774+
if (low > high) {
1775+
btrfs_err(eb->fs_info,
1776+
"%s: low (%d) > high (%d) eb %llu owner %llu level %d",
1777+
__func__, low, high, eb->start,
1778+
btrfs_header_owner(eb), btrfs_header_level(eb));
1779+
return -EINVAL;
1780+
}
1781+
17741782
while (low < high) {
17751783
mid = (low + high) / 2;
17761784
offset = p + mid * item_size;

0 commit comments

Comments
 (0)