From patchwork Tue Aug 30 07:22:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9304947 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 5DB2D608A0 for ; Tue, 30 Aug 2016 07:22:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 458102853B for ; Tue, 30 Aug 2016 07:22:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33D0A28A9D; Tue, 30 Aug 2016 07:22:36 +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 BF7BB28ABC for ; Tue, 30 Aug 2016 07:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752746AbcH3HWe (ORCPT ); Tue, 30 Aug 2016 03:22:34 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:2467 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751629AbcH3HW3 (ORCPT ); Tue, 30 Aug 2016 03:22:29 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="10418857" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Aug 2016 15:22:23 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 46AE44334C75 for ; Tue, 30 Aug 2016 15:22:21 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Tue, 30 Aug 2016 15:22:20 +0800 From: Qu Wenruo To: Subject: [PATCH 3/5] btrfs-progs: fsck: Check bytenr alignment for extent item Date: Tue, 30 Aug 2016 15:22:15 +0800 Message-ID: <20160830072217.8599-4-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160830072217.8599-1-quwenruo@cn.fujitsu.com> References: <20160830072217.8599-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 46AE44334C75.AC9A2 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@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 Check bytenr alignment for extent item to filter invalid items early. Signed-off-by: Qu Wenruo --- cmds-check.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 2aa0a7b..c56b176 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -5422,6 +5422,11 @@ static int process_extent_item(struct btrfs_root *root, num_bytes = key.offset; } + if (!IS_ALIGNED(key.objectid, root->sectorsize)) { + error("ignoring invalid extent, bytenr %llu is not aligned to %u", + key.objectid, root->sectorsize); + return -EIO; + } if (item_size < sizeof(*ei)) { #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 struct btrfs_extent_item_v0 *ei0; @@ -5448,6 +5453,16 @@ static int process_extent_item(struct btrfs_root *root, metadata = 1; else metadata = 0; + if (metadata && num_bytes != root->nodesize) { + error("ignore invalid metadata extent, length %llu does not equal to %u", + num_bytes, root->nodesize); + return -EIO; + } + if (!metadata && !IS_ALIGNED(num_bytes, root->sectorsize)) { + error("ignore invalid data extent, length %llu is not aligned to %u", + num_bytes, root->sectorsize); + return -EIO; + } memset(&tmpl, 0, sizeof(tmpl)); tmpl.start = key.objectid;