aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/print-tree.c
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2018-03-28 21:08:11 -0400
committerDavid Sterba <dsterba@suse.com>2018-03-30 20:01:06 -0400
commit581c1760415c48cca9349b198bba52dd38750765 (patch)
tree90e5aa035bfcab9a05fdec79eaa4ce90dc7aa267 /fs/btrfs/print-tree.c
parent3c0efdf03b2d127f0e40e30db4e7aa0429b1b79a (diff)
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>
Diffstat (limited to 'fs/btrfs/print-tree.c')
-rw-r--r--fs/btrfs/print-tree.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 569205e651c7..4a8770485f77 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -365,9 +365,13 @@ void btrfs_print_tree(struct extent_buffer *c)
365 btrfs_node_blockptr(c, i)); 365 btrfs_node_blockptr(c, i));
366 } 366 }
367 for (i = 0; i < nr; i++) { 367 for (i = 0; i < nr; i++) {
368 struct extent_buffer *next = read_tree_block(fs_info, 368 struct btrfs_key first_key;
369 btrfs_node_blockptr(c, i), 369 struct extent_buffer *next;
370 btrfs_node_ptr_generation(c, i)); 370
371 btrfs_node_key_to_cpu(c, &first_key, i);
372 next = read_tree_block(fs_info, btrfs_node_blockptr(c, i),
373 btrfs_node_ptr_generation(c, i),
374 level - 1, &first_key);
371 if (IS_ERR(next)) { 375 if (IS_ERR(next)) {
372 continue; 376 continue;
373 } else if (!extent_buffer_uptodate(next)) { 377 } else if (!extent_buffer_uptodate(next)) {