btrfs-progs: lowmem check: Fix NULL pointer access caused by large tree reloc tree
authorQu Wenruo <wqu@suse.com>
Wed, 22 Nov 2017 09:03:16 +0000 (17:03 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 3 Jan 2018 16:09:09 +0000 (17:09 +0100)
commit702298b2d9eed782c30d85a207006731ebdfc78a
treecf19f71e02ced0e9e28e0785b8241d5907958b5e
parentbeb06b63cc9a54f0d33dae43c3c6ff956ccc885a
btrfs-progs: lowmem check: Fix NULL pointer access caused by large tree reloc tree

[BUG]
v4.14 btrfs-progs can't pass new self test image with large tree reloc
trees.  It will fail with later "shared_block_ref_only.raw.xz" test
image with NULL pointer access.

[CAUSE]
For image with higher (level >= 2) tree reloc tree, for function
need_check() its ulist will be empty as tree reloc tree won't be
accounted in btrfs_find_all_roots().  Then accessing ulist->roots with
rb_first() will return NULL pointer.

[FIX]
For need_check() function, if @roots is empty, meaning it's a tree reloc
tree, always check them.  Although this can be slow, but at least it's
safe that we won't skip any possible wrong tree block.

Fixes: 5e2dc770471b ("btrfs-progs: check: skip shared node or leaf check for low_memory mode")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c