From patchwork Fri Apr 22 09:41:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 727021 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3MBTQd3008298 for ; Fri, 22 Apr 2011 11:29:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755160Ab1DVL3U (ORCPT ); Fri, 22 Apr 2011 07:29:20 -0400 Received: from twin.jikos.cz ([89.185.236.188]:47232 "EHLO twin.jikos.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755192Ab1DVL3M (ORCPT ); Fri, 22 Apr 2011 07:29:12 -0400 Received: from twin.jikos.cz (dave@localhost [127.0.0.1]) by twin.jikos.cz (8.13.6/8.13.6) with ESMTP id p3MBTANB008605 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 22 Apr 2011 13:29:11 +0200 Received: (from dave@localhost) by twin.jikos.cz (8.13.6/8.13.6/Submit) id p3MBTAfH008604 for linux-btrfs@vger.kernel.org; Fri, 22 Apr 2011 13:29:10 +0200 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on twin.jikos.cz X-Spam-Status: No, score=-9.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI autolearn=ham version=3.2.5 X-Spam-Level: Received: from mx1.suse.de (cantor.suse.de [195.135.220.2]) by twin.jikos.cz (8.13.6/8.13.6) with ESMTP id p3M9fRf3030343 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 22 Apr 2011 11:41:28 +0200 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id B280B94430; Fri, 22 Apr 2011 11:41:27 +0200 (CEST) Received: by ds.suse.cz (Postfix, from userid 10065) id 792E07472F; Fri, 22 Apr 2011 11:41:27 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 03/12] btrfs: fix dereference before check Date: Fri, 22 Apr 2011 11:41:24 +0200 Message-Id: <8927a99072750c65ba0c3379d6663913cae8d258.1303398927.git.dsterba@suse.cz> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 22 Apr 2011 11:29:27 +0000 (UTC) The superblock's ->s_fs_info is properly set in btrfs_fill_super, after a call to open_ctree, which derefereces it before check. Although tree_root is set via btrfs_set_super, let's be defensive and leave the check in place. Signed-off-by: David Sterba --- fs/btrfs/disk-io.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8f07c86..5e5d07c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1611,7 +1611,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); struct btrfs_root *tree_root = btrfs_sb(sb); - struct btrfs_fs_info *fs_info = tree_root->fs_info; + struct btrfs_fs_info *fs_info = NULL; struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS); struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), @@ -1623,11 +1623,12 @@ struct btrfs_root *open_ctree(struct super_block *sb, struct btrfs_super_block *disk_super; - if (!extent_root || !tree_root || !fs_info || + if (!extent_root || !tree_root || !tree_root->fs_info || !chunk_root || !dev_root || !csum_root) { err = -ENOMEM; goto fail; } + fs_info = tree_root->fs_info; ret = init_srcu_struct(&fs_info->subvol_srcu); if (ret) {