From patchwork Thu Sep 18 04:01:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4928841 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C04009F4D5 for ; Thu, 18 Sep 2014 04:00:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD71D2017D for ; Thu, 18 Sep 2014 04:01:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9B76E20142 for ; Thu, 18 Sep 2014 04:01:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750738AbaIREBf (ORCPT ); Thu, 18 Sep 2014 00:01:35 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:43107 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750705AbaIREBe (ORCPT ); Thu, 18 Sep 2014 00:01:34 -0400 X-IronPort-AV: E=Sophos;i="5.04,544,1406563200"; d="scan'208";a="36112494" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 18 Sep 2014 11:58:33 +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 s8I41dE4012276 for ; Thu, 18 Sep 2014 12:01:39 +0800 Received: from adam-work.lan (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 18 Sep 2014 12:01:32 +0800 From: Qu Wenruo To: Subject: [PATCH 1/2] btrfs: Add more check before read_extent_buffer() to avoid read overflow. Date: Thu, 18 Sep 2014 12:01:31 +0800 Message-ID: <1411012892-17481-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] 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 Before this patch, when replay_one_extent() find an existing file extent item, btrfs will call read_extent_buffer() to read out the file extent. However it lacks enough check, and may read out the inline file extent using the wrong size(currently it always uses sizeof(btrfs_file_extent_item)) If a inline file extent's size is smaller than normal file extent size(53 bytes) and unfortunately the inline file extent lies at the end of a full leaf, WARN_ON in read_extent_buffer() will be triggered. This patch will check the file extent type before calling read_extent_buffer(), since the if the logged one and the existing one are all preallocated/regular file extent item, their size must be sizeof(struct btrfs_file_extent_item) and will avoid the read overflow. Signed-off-by: Qu Wenruo --- fs/btrfs/tree-log.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 7e0e6e3..1ea2b10 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -620,6 +620,8 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, existing = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); + if (btrfs_file_extent_type(leaf, existing) != found_type) + goto no_compare; read_extent_buffer(eb, &cmp1, (unsigned long)item, sizeof(cmp1)); read_extent_buffer(leaf, &cmp2, (unsigned long)existing, @@ -634,6 +636,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, goto out; } } +no_compare: btrfs_release_path(path); /* drop any overlapping extents */