From patchwork Tue Sep 30 08:52:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5001211 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5C1469F349 for ; Tue, 30 Sep 2014 08:52:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9107A2017D for ; Tue, 30 Sep 2014 08:52:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A45C120166 for ; Tue, 30 Sep 2014 08:52:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751591AbaI3IwR (ORCPT ); Tue, 30 Sep 2014 04:52:17 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:34115 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750780AbaI3IwQ (ORCPT ); Tue, 30 Sep 2014 04:52:16 -0400 X-IronPort-AV: E=Sophos;i="5.04,625,1406563200"; d="scan'208";a="36667106" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Sep 2014 16:49:12 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s8U8qEwt000636 for ; Tue, 30 Sep 2014 16:52:14 +0800 Received: from adam-work.lan (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 30 Sep 2014 16:52:15 +0800 From: Qu Wenruo To: Subject: [PATCH] btrfs-progs: Check the csum tree node before go through the csum tree Date: Tue, 30 Sep 2014 16:52:10 +0800 Message-ID: <1412067130-11504-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.1.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP [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 --- cmds-check.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 9471709..537376a 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -3905,6 +3905,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;