From patchwork Thu Sep 7 02:28:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 9941549 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 0D33D60350 for ; Thu, 7 Sep 2017 02:25:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F307727FC0 for ; Thu, 7 Sep 2017 02:25:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7343280CF; Thu, 7 Sep 2017 02:25: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 9F82B27FC0 for ; Thu, 7 Sep 2017 02:25:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752315AbdIGCZq (ORCPT ); Wed, 6 Sep 2017 22:25:46 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:27327 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752142AbdIGCZp (ORCPT ); Wed, 6 Sep 2017 22:25:45 -0400 X-IronPort-AV: E=Sophos;i="5.42,356,1500912000"; d="scan'208";a="25354658" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Sep 2017 10:25:43 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 299124727AA4 for ; Thu, 7 Sep 2017 10:25:40 +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; Thu, 7 Sep 2017 10:25:39 +0800 From: Su Yue To: CC: , Subject: [PATCH v2] btrfs-progs: print: Check on num_stripes in print_chunk Date: Thu, 7 Sep 2017 10:28:25 +0800 Message-ID: <20170907022825.19334-1-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.129] X-yoursite-MailScanner-ID: 299124727AA4.A701A 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 From: Zhang Yu In fuzz-tests/004-simple-dump-tree: Since there is one wrong item(DATA_RELOC_TREE CHUNK_ITEM 0) in root tree. It fails as follow: ctree.h:317: btrfs_chunk_item_size: BUG_ON `num_stripes == 0` triggered, value 1 btrfs-progs/btrfs(+0x2496f)[0x564a031e996f] btrfs-progs/btrfs(print_chunk+0x20f)[0x564a031ea091] btrfs-progs/btrfs(btrfs_print_leaf+0xfcb)[0x564a031ebaea] btrfs-progs/btrfs(btrfs_print_tree+0x3d)[0x564a031ec311] btrfs-progs/btrfs(cmd_inspect_dump_tree+0x4e6)[0x564a0323a6e1] btrfs-progs/btrfs(handle_command_group+0x44)[0x564a031d6414] btrfs-progs/btrfs(cmd_inspect+0x15)[0x564a03211b98] btrfs-progs/btrfs(main+0x88)[0x564a031d65d0] /usr/lib/libc.so.6(__libc_start_main+0xea)[0x7f2c7fa584ca] btrfs-progs/btrfs(_start+0x2a)[0x564a031d616a] item 8 key (DATA_RELOC_TREE CHUNK_ITEM 0) itemoff 1574 itemsize 439 failed (ignored, ret=134): btrfs-progs/btrfs inspect-internal dump-tree btrfs-progs/tes\ ts/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.restored mayfail: returned code 134 (SIGABRT), not ignored test failed for case 004-simple-dump-tree Solve it by checking on num_stripes in print_chunk(). Signed-off-by: Zhang Yu --- change log: v2: Move statements after the declaration block in print_chunk(). --- print-tree.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/print-tree.c b/print-tree.c index 5927ed35..ca7b3aa1 100644 --- a/print-tree.c +++ b/print-tree.c @@ -199,9 +199,19 @@ void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk) { u16 num_stripes = btrfs_chunk_num_stripes(eb, chunk); int i; - u32 chunk_item_size = btrfs_chunk_item_size(num_stripes); + u32 chunk_item_size; char chunk_flags_str[32] = {0}; + /* + * check on num_stripes + * Btrfs_chunk contains at least one stripes + */ + if (num_stripes < 1) { + printf("\t\tinvalid num_stripes: %u\n", num_stripes); + return; + } + + chunk_item_size = btrfs_chunk_item_size(num_stripes); if ((unsigned long)chunk + chunk_item_size > eb->len) { printf("\t\tchunk item invalid\n"); return;