From patchwork Tue Aug 4 14:43:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 6940661 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DBA23C05AC for ; Tue, 4 Aug 2015 14:44:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 56E0920481 for ; Tue, 4 Aug 2015 14:44:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2183F20270 for ; Tue, 4 Aug 2015 14:44:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756885AbbHDOo2 (ORCPT ); Tue, 4 Aug 2015 10:44:28 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:31533 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756882AbbHDOo1 (ORCPT ); Tue, 4 Aug 2015 10:44:27 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t74EiQp3018197 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 4 Aug 2015 14:44:26 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t74EiPsJ026379 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 4 Aug 2015 14:44:26 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t74EiFIq029449 for ; Tue, 4 Aug 2015 14:44:25 GMT Received: from localhost.localdomain (/42.60.17.47) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Aug 2015 07:44:14 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: Anand Jain Subject: [PATCH 2/3] Btrfs: fix null pointer dereference when extent buffer is already freed Date: Tue, 4 Aug 2015 22:43:52 +0800 Message-Id: <1438699433-1581-3-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1438699433-1581-1-git-send-email-anand.jain@oracle.com> References: <1438699433-1581-1-git-send-email-anand.jain@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] 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.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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, read_tree_block() returns error it has already freed the extent_buffer read_tree_block(..) { :: ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid); <== fails if (ret) { free_extent_buffer(buf); <=== its freed already return ERR_PTR(ret); } :: } open_ctree() { :: chunk_root->node = read_tree_block(..); :: BTRFS: failed to read chunk root on sdf BUG: unable to handle kernel NULL pointer dereference at 000000000000001f IP: [] free_extent_buffer+0x1e/0xb0 [btrfs] :: [] ? free_root_extent_buffers+0x1e/0x40 [btrfs] [] free_root_pointers+0x56/0x60 [btrfs] [] open_ctree+0x19e0/0x2360 [btrfs] [] btrfs_mount+0x9e6/0xb10 [btrfs] [] ? find_next_zero_bit+0x1a/0x30 [] ? find_next_bit+0x15/0x30 [] ? pcpu_alloc+0x35a/0x680 [] mount_fs+0x38/0x190 [] ? __alloc_percpu+0x15/0x20 [] vfs_kern_mount+0x6b/0x120 [] btrfs_mount+0x1f8/0xb10 [btrfs] [] ? pcpu_alloc+0x35a/0x680 [] mount_fs+0x38/0x190 [] ? __alloc_percpu+0x15/0x20 [] vfs_kern_mount+0x6b/0x120 [] do_mount+0x224/0xb80 [] SyS_mount+0x7e/0xe0 [] system_call_fastpath+0x12/0x71 this patch avoids calling it again Signed-off-by: Anand Jain --- fs/btrfs/disk-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index da7b7bf..e8901ac 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2081,7 +2081,8 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) static void free_root_extent_buffers(struct btrfs_root *root) { if (root) { - free_extent_buffer(root->node); + if (!IS_ERR(root->node)) + free_extent_buffer(root->node); free_extent_buffer(root->commit_root); root->node = NULL; root->commit_root = NULL;