btrfs-progs: ctree: Add extra level check for read_node_slot()
authorQu Wenruo <wqu@suse.com>
Thu, 8 Feb 2018 00:59:40 +0000 (08:59 +0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Mar 2018 20:15:54 +0000 (22:15 +0200)
commit2615aca92c628457fe76131a5f810720349dc4c5
treee9721cd7e3a23903e625219a41b3df6975c01896
parente875cd98e38f9fdc7f812a7575a3a2afd6b6094b
btrfs-progs: ctree: Add extra level check for read_node_slot()

Strangely, we have level check in btrfs_print_tree() while we don't have
the same check in read_node_slot().

That's to say, for the following corruption, btrfs_search_slot() or
btrfs_next_leaf() can return invalid leaf:

Parent eb:
  node XXXXXX level 1
              ^^^^^^^
              Child should be leaf (level 0)
  ...
  key (XXX XXX XXX) block YYYYYY

Child eb:
  leaf YYYYYY level 1
              ^^^^^^^
              Something went wrong now

And for the corrupted leaf returned, later caller can be screwed up
easily.

Reported-by: Ralph Gauges <ralphgauges@googlemail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
ctree.c