From patchwork Fri Aug 22 03:42:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4761201 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1AB8DC0338 for ; Fri, 22 Aug 2014 03:42:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 446452018E for ; Fri, 22 Aug 2014 03:42:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B7F02018A for ; Fri, 22 Aug 2014 03:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755772AbaHVDmv (ORCPT ); Thu, 21 Aug 2014 23:42:51 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:15504 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755634AbaHVDmv (ORCPT ); Thu, 21 Aug 2014 23:42:51 -0400 X-IronPort-AV: E=Sophos;i="5.04,377,1406563200"; d="scan'208";a="34927934" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 22 Aug 2014 11:39:55 +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 s7M3gk1Q008074 for ; Fri, 22 Aug 2014 11:42:46 +0800 Received: from adam-work.lan (10.167.226.24) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 22 Aug 2014 11:42:49 +0800 From: Qu Wenruo To: Subject: [PATCH] btrfs-progs: corrupt-block: fix a delete and use bug corrupting extent tree. Date: Fri, 22 Aug 2014 11:42:49 +0800 Message-ID: <1408678969-9218-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.0.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.24] 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 When corrupting extent tree, corrupt-block will iterate each child node/leaf of a node. However, when a node's child is leaf, btrfs_corrupt_extent_leaf() may delete some item in the leaf, which may cause the children number of the parent node decrease. Before this patch, corrupt-block will read out the nritems only *ONCE* and iterate the 'nritems' times. When btrfs_corrupt_extent_leaf() deletes enough item, causing the nritems of btrfs_header decreased, the last few iteration will access non-existed node, which will cause the delete and use bug like the following: --- \# ./btrfs-corrupt-block -E /dev/vdc deleting extent record: key 40714240 168 16384 Couldn't map the block 3459802452797161472 btrfs-corrupt-block: volumes.c:1137: btrfs_num_copies: Assertion `!(!ce)' failed. Aborted --- This patch will update the nritmes in each iteration to avoid the bug. Signed-off-by: Qu Wenruo --- btrfs-corrupt-block.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index 6ecbe47..486ea19 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -264,12 +264,10 @@ static void btrfs_corrupt_extent_tree(struct btrfs_trans_handle *trans, struct extent_buffer *eb) { int i; - u32 nr; if (!eb) return; - nr = btrfs_header_nritems(eb); if (btrfs_is_leaf(eb)) { btrfs_corrupt_extent_leaf(trans, root, eb); return; @@ -280,7 +278,7 @@ static void btrfs_corrupt_extent_tree(struct btrfs_trans_handle *trans, return; } - for (i = 0; i < nr; i++) { + for (i = 0; i < btrfs_header_nritems(eb); i++) { struct extent_buffer *next; next = read_tree_block(root, btrfs_node_blockptr(eb, i),