Message ID | 1466724765-27364-1-git-send-email-bo.li.liu@oracle.com (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
On Thu, Jun 23, 2016 at 04:32:45PM -0700, Liu Bo wrote: > 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 <bo.li.liu@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index c49a500..915d224 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1770,6 +1770,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;
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 <bo.li.liu@oracle.com> --- v2: fix typo of in printed message. fs/btrfs/ctree.c | 8 ++++++++ 1 file changed, 8 insertions(+)