Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1043385ybp; Thu, 17 Oct 2019 07:16:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuLzcoQrV1H/0YmcHq3TUgQySzCIn3xVSijH7gJpgKGUcrByGPLydOrAMYccQGlUvAnH5t X-Received: by 2002:a17:906:8608:: with SMTP id o8mr3729184ejx.179.1571321777339; Thu, 17 Oct 2019 07:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571321777; cv=none; d=google.com; s=arc-20160816; b=oypcvZU+KK22BQKlnBfwsjTOBw6j7DtE22UtUaUjdQbCQPKsJ3b4fAssw8brssCB1S d4bPaPwD7NTdExzGOZQcQmLbSks87TQgVsKo0i/2+u55krzCURq8fWkv5rkcBoK9pCK1 RosaUjnxbvh1a0DcwMQX+oM65mR2a+qv0uemqIrOC7Vakir53zZTVHr0vzCV5c6V4XeD gPcgYj9ee/RYeqcs7BznRzLje5pfir0KWwQvotnprVstimfyX19nEAsdGC2eDdkg2OV7 8yvvAvTeZLuSQMtEVzVhY0E6Eg7BiRVNWuoCAe00Bjr9by4RGw0rrUDPSSfqvAtZLx+d hmUA== 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=2VgplCfMrZb22y22GjLfx4cb/lCGL+S4Exy8s8CN7B4=; b=RXcNRceKG5fIC/HvxgefuoJH/Oau/uGHSw79vT5JmsJoR196+MIMkKffTzGfEYC0oi hyZNpwA+By9XTOjc7VSofdVoTCBZJ6Rb4kZFzVl1T2RW+7RKWz8ucTyTlrjcSgZC3FNq WYT93R64rurK1WITDrTxobLysZGH9OgBQF32paMy8Hs9ouk2FytygmU01Y8vk7ZPXhbO ZTiY/mCI6rSj21CAj0OdPlTXD8OwJkkg/0ZJ14Lx4/JE3cWDf7YVlg++hsKgYvMh9tQZ Qs7NU9MkEM3K/4/6r+0G8VLo+8brbKyUwzgIUDZXcwhjyjDRyhZWr7GEI5XnW6hwUl+d C1Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NSWR96jl; 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 p18si1591731ejn.370.2019.10.17.07.15.53; Thu, 17 Oct 2019 07:16:17 -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=NSWR96jl; 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 S2437655AbfJPVyD (ORCPT + 99 others); Wed, 16 Oct 2019 17:54:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:43378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394931AbfJPVx5 (ORCPT ); Wed, 16 Oct 2019 17:53:57 -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 11CF821925; Wed, 16 Oct 2019 21:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262837; bh=0pRgjxjxcQutTSf8K2BeQpWt/9VHQ1dqxNGgKWkcSAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NSWR96jlQyJm2h6JnIy0YEj0+PuelceXGt5K3Y1YUVwWBfiWpHNL0JcEGIqCVM9RP CNocMGsNBTh8YaUydBNvDB8ANfblYHoWIvQ4SkqtdbFbCBo9oqwt3dB/ExM4AksIjV 92S5EnY+lwhkwm3HggTEmBdqtrmfMqLlFM9aJFP4= 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.4 79/79] xfs: clear sb->s_fs_info on mount failure Date: Wed, 16 Oct 2019 14:50:54 -0700 Message-Id: <20191016214834.705602853@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214729.758892904@linuxfoundation.org> References: <20191016214729.758892904@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 @@ -1572,6 +1572,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: @@ -1589,6 +1590,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); @@ -1598,6 +1603,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); } @@ -1617,6 +1624,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)); }