From 2c1b155988a9263bb5e4dc81c6a48c699f649789 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 30 Sep 2014 16:52:10 +0800 Subject: [PATCH] btrfs-progs: Check the csum tree node before go through the csum tree [BUG] Some fsfuzzed btrfs image will cause btrfsck segfault. [REPRODUCER] Run btrfsck on a csum tree block corrupted image. [REASON] check_csums() function call btrfs_search_slot() on csum_tree but doesn't check whether the csum_tree contains a valid extent_buffer, which causes the segfault. [FIX] Check the csum_root->node before any search. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- cmds-check.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 4c013303..23dbd0a0 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -3867,6 +3867,10 @@ static int check_csums(struct btrfs_root *root) unsigned long leaf_offset; root = root->fs_info->csum_root; + if (!extent_buffer_uptodate(root->node)) { + fprintf(stderr, "No valid csum tree found\n"); + return -ENOENT; + } key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; key.type = BTRFS_EXTENT_CSUM_KEY;