Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1385005ybp; Thu, 17 Oct 2019 12:00:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzgD7ojk9M255s8R1QhNKz2QAL8VInnEeH2d6X+RxxF+6xXQXu8tLF93y4nw5CFDL4v/XQ X-Received: by 2002:aa7:c2d7:: with SMTP id m23mr5506064edp.206.1571338857876; Thu, 17 Oct 2019 12:00:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571338857; cv=none; d=google.com; s=arc-20160816; b=uE9qyxJCaQlSeikUbI247ENAC85H1NsCyT+L1tyZupgz5sZv1Ym8bbD1npefXhSG5i Y6QJRWH2aRnRqsN0PPJETMcavdcBKu4oF/hBuWd8GEQdY5w48cQEaIU12lGrsMDM4kHP SPLKk2BBalVQREZS2JYMd3NXFqnhuYjbTmvqonOoAEOaO54bGsBIcJnPmws0/L/SnW9S okZuhnQCleriJvluzQpmuCNo5SAtPLUO7wUNw8qMRbTUIqOwIH3KglOsKqS0iOopHVqf 9TBv0b0B9Sox3Mz1sz5zBOXEJlG6iq8CB48pDalVnO4wmplAyyFnKf7MWTSoWrYyrSRR vEsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=i1JH9Y1Iv7WTrY1ll8lHJlHaO+1BBn75FCgkXs56KO8=; b=jeAZ5zyrbIv/OvmHBbalvKpEHefYOZn5mtP+bggosPpIAFp4MvBkOPY7VEzsbwJ4oc vQG7DEx0cBHdD/FvFP9QofFm/vBJ/LHYN+pu1nJgOmXMKQtBZ2KJDrw9+cvvxxnfbW9P Fc2RqZ5XTPUhV5jcJNPm76iyUVAIk/R8sFBgM0U+6zqHdofZI/7kBPMsIPWl/mpYJg/j 99pdJEQ5C6ekH0n4QY/SF3Wf+ZUU2cG6juWwqysITEZbHV0/2eSh3TGRhXUNm7FDrz5L +SpACEpu7vCC+eqira/ZABzDiHisOrzRmhcVH3D4EH9c6cO58ksGqPPYO3KrluwGw1uK VSfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ei9WmJEQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c4si2240854edb.387.2019.10.17.12.00.32; Thu, 17 Oct 2019 12:00:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ei9WmJEQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407328AbfJPWLw (ORCPT + 99 others); Wed, 16 Oct 2019 18:11:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:48498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395387AbfJPV4h (ORCPT ); Wed, 16 Oct 2019 17:56:37 -0400 Received: from localhost (unknown [192.55.54.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3CFD21D7E; Wed, 16 Oct 2019 21:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262997; bh=LA6KR0c28eo+/gwg1dpmIVId20Zt7vqtc46BEbBLHF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ei9WmJEQXc2Ekz7ggbd5h8YMQCP3EWqTFq1FnKXfWzF3HTUTyvT4eMPWwMcemuGq4 gfkA/y6raidPMYVxYqRRTKm72Ph9FgPK1jl0qvpB5ZjY7iZyi1DUszouObb1Uy/+al vNv3nktPqDSrWOWoLyPfD1L99IXUB8MG0xFeMMPs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Chinner , "Darrick J. Wong" , Ajay Kaher Subject: [PATCH 4.14 65/65] xfs: clear sb->s_fs_info on mount failure Date: Wed, 16 Oct 2019 14:51:19 -0700 Message-Id: <20191016214840.649307743@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214756.457746573@linuxfoundation.org> References: <20191016214756.457746573@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Chinner commit c9fbd7bbc23dbdd73364be4d045e5d3612cf6e82 upstream. We recently had an oops reported on a 4.14 kernel in xfs_reclaim_inodes_count() where sb->s_fs_info pointed to garbage and so the m_perag_tree lookup walked into lala land. Essentially, the machine was under memory pressure when the mount was being run, xfs_fs_fill_super() failed after allocating the xfs_mount and attaching it to sb->s_fs_info. It then cleaned up and freed the xfs_mount, but the sb->s_fs_info field still pointed to the freed memory. Hence when the superblock shrinker then ran it fell off the bad pointer. With the superblock shrinker problem fixed at teh VFS level, this stale s_fs_info pointer is still a problem - we use it unconditionally in ->put_super when the superblock is being torn down, and hence we can still trip over it after a ->fill_super call failure. Hence we need to clear s_fs_info if xfs-fs_fill_super() fails, and we need to check if it's valid in the places it can potentially be dereferenced after a ->fill_super failure. Signed-Off-By: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Ajay Kaher Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_super.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1715,6 +1715,7 @@ xfs_fs_fill_super( out_close_devices: xfs_close_devices(mp); out_free_fsname: + sb->s_fs_info = NULL; xfs_free_fsname(mp); kfree(mp); out: @@ -1732,6 +1733,10 @@ xfs_fs_put_super( { struct xfs_mount *mp = XFS_M(sb); + /* if ->fill_super failed, we have no mount to tear down */ + if (!sb->s_fs_info) + return; + xfs_notice(mp, "Unmounting Filesystem"); xfs_filestream_unmount(mp); xfs_unmountfs(mp); @@ -1741,6 +1746,8 @@ xfs_fs_put_super( xfs_destroy_percpu_counters(mp); xfs_destroy_mount_workqueues(mp); xfs_close_devices(mp); + + sb->s_fs_info = NULL; xfs_free_fsname(mp); kfree(mp); } @@ -1760,6 +1767,9 @@ xfs_fs_nr_cached_objects( struct super_block *sb, struct shrink_control *sc) { + /* Paranoia: catch incorrect calls during mount setup or teardown */ + if (WARN_ON_ONCE(!sb->s_fs_info)) + return 0; return xfs_reclaim_inodes_count(XFS_M(sb)); }