From patchwork Wed Sep 27 06:34:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 9973191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3C1F260375 for ; Wed, 27 Sep 2017 06:32:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30970290B1 for ; Wed, 27 Sep 2017 06:32:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24F93290C5; Wed, 27 Sep 2017 06:32:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 083D1290CA for ; Wed, 27 Sep 2017 06:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751987AbdI0Gb7 (ORCPT ); Wed, 27 Sep 2017 02:31:59 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:41592 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751883AbdI0Gbx (ORCPT ); Wed, 27 Sep 2017 02:31:53 -0400 X-IronPort-AV: E=Sophos;i="5.42,443,1500912000"; d="scan'208";a="28475930" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Sep 2017 14:31:43 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 2146847CAAD5 for ; Wed, 27 Sep 2017 14:31:42 +0800 (CST) Received: from archlinux.g08.fujitsu.local (10.167.226.129) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 27 Sep 2017 14:31:41 +0800 From: Su Yue To: Subject: [PATCH 4/5] btrfs-progs: check: check extent_inline_ref in lowmem Date: Wed, 27 Sep 2017 14:34:39 +0800 Message-ID: <20170927063440.25961-5-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170927063440.25961-1-suy.fnst@cn.fujitsu.com> References: <20170927063440.25961-1-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.129] X-yoursite-MailScanner-ID: 2146847CAAD5.AA953 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suy.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Lowmem check does not skip invalid type in extent_inline_ref then calls btrfs_extent_inline_ref_size(type) which causes crash. Error: $ btrfs check --mode=lowmem /tmp/data_small Checking filesystem on /tmp/data_small UUID: ee205d69-8724-4aa2-a4f5-bc8558a62169 checking extents ERROR: extent[20971520 16384] backref type mismatch, missing bit: 2 ERROR: extent[20971520 16384] backref generation mismatch, wanted: 7, have: 0 ERROR: extent[20971520 16384] is referred by other roots than 3 ctree.h:1754: btrfs_extent_inline_ref_size: BUG_ON `1` triggered, value 1 btrfs(+0x543db)[0x55fabc2ab3db] btrfs(+0x587f7)[0x55fabc2af7f7] btrfs(+0x5fa44)[0x55fabc2b6a44] btrfs(cmd_check+0x194a)[0x55fabc2bd717] btrfs(main+0x88)[0x55fabc2682e0] /usr/lib/libc.so.6(__libc_start_main+0xea)[0x7f021c3824ca] btrfs(_start+0x2a)[0x55fabc267e7a] [1] 5188 abort (core dumped) btrfs check --mode=lowmem /tmp/data_small Solve it by introducing check_extent_inline_ref() to check type. If the checker returns a nonzero value, we should not check the corrupted extent item anymore. Suggested-by: Qu Wenruo Signed-off-by: Su Yue --- cmds-check.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index adc4a934..aa054a19 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -11415,6 +11415,29 @@ loop: goto again; } +static int check_extent_inline_ref(struct extent_buffer *eb, + struct btrfs_key *key, struct btrfs_extent_inline_ref *iref) +{ + int ret; + u8 type = btrfs_extent_inline_ref_type(eb, iref); + + switch (type) { + case BTRFS_TREE_BLOCK_REF_KEY: + case BTRFS_EXTENT_DATA_REF_KEY: + case BTRFS_SHARED_BLOCK_REF_KEY: + case BTRFS_SHARED_DATA_REF_KEY: + ret = 0; + break; + default: + error("extent[%llu %u %llu] has unknown ref type: %d", + key->objectid, key->type, key->offset, type); + ret = UNKNOWN_TYPE; + break; + } + + return ret; +} + /* * Check backrefs of a tree block given by @bytenr or @eb. * @@ -11549,6 +11572,11 @@ static int check_tree_block_ref(struct btrfs_root *root, type = btrfs_extent_inline_ref_type(leaf, iref); offset = btrfs_extent_inline_ref_offset(leaf, iref); + ret = check_extent_inline_ref(leaf, &key, iref); + if (ret) { + err |= ret; + break; + } if (type == BTRFS_TREE_BLOCK_REF_KEY) { if (offset == root->objectid) found_ref = 1; @@ -11826,6 +11854,11 @@ static int check_extent_data_item(struct btrfs_root *root, type = btrfs_extent_inline_ref_type(leaf, iref); dref = (struct btrfs_extent_data_ref *)(&iref->offset); + ret = check_extent_inline_ref(leaf, &dbref_key, iref); + if (ret) { + err |= ret; + break; + } if (type == BTRFS_EXTENT_DATA_REF_KEY) { ref_root = btrfs_extent_data_ref_root(leaf, dref); if (ref_root == root->objectid)