From patchwork Fri Nov 24 10:41:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Jinxiang X-Patchwork-Id: 10073945 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 592396037F for ; Fri, 24 Nov 2017 10:41:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 561172A27C for ; Fri, 24 Nov 2017 10:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B0E62A283; Fri, 24 Nov 2017 10:41:50 +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 EFB4F2A27C for ; Fri, 24 Nov 2017 10:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753382AbdKXKlr (ORCPT ); Fri, 24 Nov 2017 05:41:47 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:30742 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753100AbdKXKlj (ORCPT ); Fri, 24 Nov 2017 05:41:39 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="30431333" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Nov 2017 18:41:36 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 390B1487F16B; Fri, 24 Nov 2017 18:41:35 +0800 (CST) Received: from localhost.localdomain (10.167.226.132) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 24 Nov 2017 18:41:35 +0800 From: Gu Jinxiang To: CC: Subject: [PATCH 4/5] btrfs-progs: check null pointer before use it Date: Fri, 24 Nov 2017 18:41:31 +0800 Message-ID: <1511520092-37101-4-git-send-email-gujx@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1511520092-37101-1-git-send-email-gujx@cn.fujitsu.com> References: <1511520092-37101-1-git-send-email-gujx@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.132] X-yoursite-MailScanner-ID: 390B1487F16B.A3773 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: gujx@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 The following test failed when trying to check tree below. item 9 key (TREE_RELOC ROOT_ITEM 0) itemoff 1135 itemsize 439 Since it has a inconsistent level in root and root->node, Segment fault accures when use btrfs_node_key after btrfs_search_slot. So add null pointer check before use btrfs_node_key. Here comes the error message: $ sudo TEST=003\* make test-fuzz failed (ignored, ret=139): /home/adam/btrfs/btrfs-progs/btrfs check --init-csum-tree /home/adam/btrfs/btrfs-progs/tests/fuzz-tests/images/bko-172811.raw.restored mayfail: returned code 139 (SEGFAULT), not ignored test failed for case 003-multi-check-unmounted Signed-off-by: Gu Jinxiang --- cmds-check.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 49b0792b..3f4244a2 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -4070,6 +4070,8 @@ static int check_fs_root(struct btrfs_root *root, wret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); if (wret < 0) goto skip_walking; + if (!path.nodes[level]) + goto skip_walking; btrfs_node_key(path.nodes[level], &found_key, path.slots[level]); WARN_ON(memcmp(&found_key, &root_item->drop_progress,