From: Liu Bo Date: Thu, 23 Jun 2016 23:32:45 +0000 (-0700) Subject: Btrfs: error out if generic_bin_search get invalid arguments X-Git-Tag: v4.8-rc1~38^2~1^2~36 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=5e24e9af01abcb151173bb133f1a72b94239c670;p=karo-tx-linux.git 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 Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index a85cf7d23309..362879da4f0d 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1771,6 +1771,14 @@ static noinline int generic_bin_search(struct extent_buffer *eb, unsigned long map_len = 0; int err; + if (low > high) { + btrfs_err(eb->fs_info, + "%s: low (%d) > high (%d) eb %llu owner %llu level %d", + __func__, low, high, eb->start, + btrfs_header_owner(eb), btrfs_header_level(eb)); + return -EINVAL; + } + while (low < high) { mid = (low + high) / 2; offset = p + mid * item_size;