]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: Validate child tree block's level and first key
authorQu Wenruo <wqu@suse.com>
Thu, 29 Mar 2018 01:08:11 +0000 (09:08 +0800)
committerDavid Sterba <dsterba@suse.com>
Sat, 31 Mar 2018 00:01:06 +0000 (02:01 +0200)
commit22b458c595c4fb7a63f8939cb63010adcde03c44
tree90e5aa035bfcab9a05fdec79eaa4ce90dc7aa267
parent8b22dec81bd8800166778dba6953550732d680b2
btrfs: Validate child tree block's level and first key

We have several reports about node pointer points to incorrect child
tree blocks, which could have even wrong owner and level but still with
valid generation and checksum.

Although btrfs check could handle it and print error message like:
leaf parent key incorrect 60670574592

Kernel doesn't have enough check on this type of corruption correctly.
At least add such check to read_tree_block() and btrfs_read_buffer(),
where we need two new parameters @level and @first_key to verify the
child tree block.

The new @level check is mandatory and all call sites are already
modified to extract expected level from its call chain.

While @first_key is optional, the following call sites are skipping such
check:
1) Root node/leaf
   As ROOT_ITEM doesn't contain the first key, skip @first_key check.
2) Direct backref
   Only parent bytenr and level is known and we need to resolve the key
   all by ourselves, skip @first_key check.

Another note of this verification is, it needs extra info from nodeptr
or ROOT_ITEM, so it can't fit into current tree-checker framework, which
is limited to node/leaf boundary.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/backref.c
fs/btrfs/ctree.c
fs/btrfs/disk-io.c
fs/btrfs/disk-io.h
fs/btrfs/extent-tree.c
fs/btrfs/print-tree.c
fs/btrfs/qgroup.c
fs/btrfs/ref-verify.c
fs/btrfs/relocation.c
fs/btrfs/tree-log.c