btrfs: tree-checker: Check level for leaves and nodes
authorQu Wenruo <wqu@suse.com>
Thu, 27 Sep 2018 23:59:34 +0000 (07:59 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Dec 2018 18:41:13 +0000 (19:41 +0100)
commitcf968bbccba9860eef9480ae560711fbc5cbc1b5
tree8db7985d1fd84b59cb2c39f5a40e7d095e6bf4a9
parent34407a175a59b668a1a2bbf0d0e495d87a7777d8
btrfs: tree-checker: Check level for leaves and nodes

commit f556faa46eb4e96d0d0772e74ecf66781e132f72 upstream.

Although we have tree level check at tree read runtime, it's completely
based on its parent level.
We still need to do accurate level check to avoid invalid tree blocks
sneak into kernel space.

The check itself is simple, for leaf its level should always be 0.
For nodes its level should be in range [1, BTRFS_MAX_LEVEL - 1].

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
[bwh: Backported to 4.14:
 - Pass root instead of fs_info to generic_err()
 - Adjust context]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/tree-checker.c