btrfs-progs: check: lowmem: Fix several bugs related to afterward search
Since btrfs_search_slot() can point to the slot which is beyond the
leaves' capacity, we should pay extra attention when doing afterward
search.
While for lowmem check, several places uses afterward search:
1) Block group item used space check
2) Device item used space check
3) Data extent backref check.
In the following case for block group item check, btrfs lowmem mode
check will skip the block group and report false alert:
leaf
29405184 items 37 free space 1273 generation 11 owner 2
...
item 36 key (
77594624 EXTENT_ITEM
2097152)
extent refs 1 gen 8 flags DATA
extent data backref root 5 objectid 265 offset 0 count 1
leaf
29409280 items 43 free space 670 generation 11 owner 2
item 0 key (
96468992 EXTENT_ITEM
2097152)
extent refs 1 gen 8 flags DATA
extent data backref root 5 objectid 274 offset 0 count 1
item 1 key (
96468992 BLOCK_GROUP_ITEM
33554432)
block group used
2265088 chunk_objectid 256 flags DATA
When checking block group item, we will search key (
96468992 0 0) to
start from the first item in the block group.
While search_slot() will point to leaf
29405184, slot 37 which is beyond
leaf capacity.
And when reading key from slot 37, uninitialized data can be read out
and cause us to exit block group item check, leading to false alert.
Fix it by checking path.slot[0] before reading out the key.
Reported-by: Christoph Anton Mitterer <calestyo@scientia.net>
Reported-by: Chris Murphy <chris@colorremedies.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>