From patchwork Thu Aug 31 05:31:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13370920 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01FB6C83F2F for ; Thu, 31 Aug 2023 05:32:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245416AbjHaFcP (ORCPT ); Thu, 31 Aug 2023 01:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242275AbjHaFcL (ORCPT ); Thu, 31 Aug 2023 01:32:11 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28CDCEA; Wed, 30 Aug 2023 22:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=6ZUj32/PTbxNw9fN09aB0Fs8C0WjT/MBpy99lMcm6/0=; b=yzV37OHPCzxMFnuDnoUqS8QumA IxO19XW/q9voEFo2pX/TJRlTe1RS7UDaJlgVDTOum4afo1MSJsv3mekBxlrJFbXWCLriUPXAz3WmD 4+2h5ESKDySXMClmV4CxwdsBLoR/dLuJUBwd6jajvhJMHsKfNnXbMwQ/ZTB4Hs5w0iiEyHhIycN2p cAcLzJQ4gGWA9ozx/8grn8SBUZgaDkHRGpld51okHyqMQ8pDBHsiTVMj/fhGhl8ogBh7Xbq20y7O+ BAL4mObaJr/d7M/2VORadnQMcLitFKkkbtEq6ShqF0m1GymAo9OPsMiiRYrm/cVBPaDo2TItw6mTa VqY+IBPA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qbaHk-00EglC-1e; Thu, 31 Aug 2023 05:32:05 +0000 From: Christoph Hellwig To: Alexander Viro , Christian Brauner Cc: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Paul Moore , Stephen Smalley , Eric Paris , linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH 1/4] ramfs: free sb->s_fs_info after shutting down the super block Date: Thu, 31 Aug 2023 07:31:54 +0200 Message-Id: <20230831053157.256319-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831053157.256319-1-hch@lst.de> References: <20230831053157.256319-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org sb->s_fs_info can only be safely freed after generic_shutdown_super was called and all access to the super_block has stopped. Thus only free the private data after calling kill_litter_super, which calls generic_shutdown_super internally. Signed-off-by: Christoph Hellwig --- fs/ramfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c index 18e8387cab4148..0f37ecbae59dad 100644 --- a/fs/ramfs/inode.c +++ b/fs/ramfs/inode.c @@ -280,8 +280,8 @@ int ramfs_init_fs_context(struct fs_context *fc) void ramfs_kill_sb(struct super_block *sb) { - kfree(sb->s_fs_info); kill_litter_super(sb); + kfree(sb->s_fs_info); } static struct file_system_type ramfs_fs_type = { From patchwork Thu Aug 31 05:31:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13370921 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E630C83F30 for ; Thu, 31 Aug 2023 05:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244845AbjHaFcQ (ORCPT ); Thu, 31 Aug 2023 01:32:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244800AbjHaFcO (ORCPT ); Thu, 31 Aug 2023 01:32:14 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2815EA; Wed, 30 Aug 2023 22:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=onojrvo/4J+rr41hNOyQoa+Ghh8TsydVpI3xPRsi118=; b=toc1Q8HEVJiy3fD1KHJPR2pG2g AZqJDRtIXxiVn5ZCGXmTyWhgq0PZ9mEkFCgE788OttmLNc0j4/cqtzRGw/oJQEE9+hQYkF54d7ifY oRdCYKsdayrOYO4ThcedMZyGw5+bxM4PrDpEhg1NQpZUjnE46W2CPLPvDRCVCDwPv84QcFR+ucp0f PcTCU2g49IykihM3lBmJDhbGJLJde/9tEv4jswz/IMljzhT3dhfOkznuuDIfNdS55+zgB0uilfrqs GMZVjkQJP66y6Lhex4GZ654TPleoblO+Y1KUkF0Q3JW+ckPUXwRQmTVRRxtNs+oZAT3MBK6mrcf9R UNlc9UvA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qbaHn-00EglZ-28; Thu, 31 Aug 2023 05:32:08 +0000 From: Christoph Hellwig To: Alexander Viro , Christian Brauner Cc: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Paul Moore , Stephen Smalley , Eric Paris , linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH 2/4] devpts: free sb->s_fs_info after shutting down the super block Date: Thu, 31 Aug 2023 07:31:55 +0200 Message-Id: <20230831053157.256319-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831053157.256319-1-hch@lst.de> References: <20230831053157.256319-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org sb->s_fs_info can only be safely freed after generic_shutdown_super was called and all access to the super_block has stopped. Thus only free the private data after calling kill_litter_super, which calls generic_shutdown_super internally. Signed-off-by: Christoph Hellwig --- fs/devpts/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 299c295a27a03e..d46cea36c026ad 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -491,10 +491,10 @@ static void devpts_kill_sb(struct super_block *sb) { struct pts_fs_info *fsi = DEVPTS_SB(sb); + kill_litter_super(sb); if (fsi) ida_destroy(&fsi->allocated_ptys); kfree(fsi); - kill_litter_super(sb); } static struct file_system_type devpts_fs_type = { From patchwork Thu Aug 31 05:31:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13370922 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B1F5C83F2B for ; Thu, 31 Aug 2023 05:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242275AbjHaFcU (ORCPT ); Thu, 31 Aug 2023 01:32:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245458AbjHaFcT (ORCPT ); Thu, 31 Aug 2023 01:32:19 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40971CD6; Wed, 30 Aug 2023 22:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=uGghW2I13jI1s6iCzfvyY6VFo2KuSrw5mx3MS02ZxdA=; b=UOuGFtVdc4LyLWQQgplDozXLY+ D5qVUJ5Ocj6dI7tE1CQZZfZJxWSt0NBz3ZjqBraP9GxkW2aPqNI+GrYA6yQ8f25W0NW4AWF3kmsgX Xwjtti0FD3v0Pmubqu5DqlI2sZl4aQV9b1awL7Njenugw49DaH76pgqG/rZcRW9kcmw+hVps2qrq/ nUgmUqSVUMsy34OhQNOjxkTq4eQ9RACqgQyK19s+OWT03Ohtvghoj5EyvUmv6hc2AoRHfyIQ8fEdo 5rZttcWQCJmQLnkprYZkEq93wKHA49HYV6HztAHAO/oedD60dPSvHkAK1tOo9Zq8jfNqwk3L8jSwl iP83Di4g==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qbaHr-00EgmO-07; Thu, 31 Aug 2023 05:32:11 +0000 From: Christoph Hellwig To: Alexander Viro , Christian Brauner Cc: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Paul Moore , Stephen Smalley , Eric Paris , linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH 3/4] selinuxfs: free sb->s_fs_info after shutting down the super block Date: Thu, 31 Aug 2023 07:31:56 +0200 Message-Id: <20230831053157.256319-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831053157.256319-1-hch@lst.de> References: <20230831053157.256319-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org sb->s_fs_info can only be safely freed after generic_shutdown_super was called and all access to the super_block has stopped. Thus only free the private data after calling kill_litter_super, which calls generic_shutdown_super internally. Also remove the duplicate freeing in the sel_fill_super error path given that ->kіll_sb is also called on ->fill_super failure. Signed-off-by: Christoph Hellwig --- security/selinux/selinuxfs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index 9dafb6ff110d26..8a8a532be8e767 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -2100,9 +2100,6 @@ static int sel_fill_super(struct super_block *sb, struct fs_context *fc) err: pr_err("SELinux: %s: failed while creating inodes\n", __func__); - - selinux_fs_info_free(sb); - return ret; } @@ -2123,8 +2120,8 @@ static int sel_init_fs_context(struct fs_context *fc) static void sel_kill_sb(struct super_block *sb) { - selinux_fs_info_free(sb); kill_litter_super(sb); + selinux_fs_info_free(sb); } static struct file_system_type sel_fs_type = { From patchwork Thu Aug 31 05:31:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "hch@lst.de" X-Patchwork-Id: 13370923 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDABCC83F10 for ; Thu, 31 Aug 2023 05:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343986AbjHaFcw (ORCPT ); Thu, 31 Aug 2023 01:32:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344994AbjHaFc0 (ORCPT ); Thu, 31 Aug 2023 01:32:26 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 322A01BF; Wed, 30 Aug 2023 22:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=1wL1JM1HUMzrMrz40L6bCEfG239qdJ5Q6Ey+HfdYI1Q=; b=JQvJbRv4KyDhMDvCqvEAQ2lwoi Qp7eD++OVr4T2+slQ6JORF8P6gvE768tNszNKWxC+pNOlg9eoQiskZaOs/dJuzZj8ducNWwTwH9Dh 7t70YPM+4bZQ/d4gZXQM5OMy4lmkFNxwNRq9MmSBIEJ797CmgS3Vc9uVZxnVfCxgVF9VDfgyw9Llu Pdqucvkjzm2CQSYDxZcrTiNhQQmhEqx1rkIwN3RfOqHEmCmbvL6HM2U5p1OkAIurAbQOQ+U3iDFZk YDscrjUpx3qoayo7zfDLxB9XFanppPWq7Hw7JGKktxoi38aGSpJTAkvgB+8Moko6VqzDDVqDzB+vv TcoYUG2Q==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qbaHu-00Egmo-1b; Thu, 31 Aug 2023 05:32:15 +0000 From: Christoph Hellwig To: Alexander Viro , Christian Brauner Cc: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Paul Moore , Stephen Smalley , Eric Paris , linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH 4/4] hypfs: free sb->s_fs_info after shutting down the super block Date: Thu, 31 Aug 2023 07:31:57 +0200 Message-Id: <20230831053157.256319-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831053157.256319-1-hch@lst.de> References: <20230831053157.256319-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org sb->s_fs_info can only be safely freed after generic_shutdown_super was called and all access to the super_block has stopped. Thus only free the private data after calling kill_litter_super, which calls generic_shutdown_super internally. Also remove the pointless clearing of sb->s_fs_info as the super_block can't be accessed at this point and will be freed immediately. Signed-off-by: Christoph Hellwig --- arch/s390/hypfs/inode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c index ada83149932fec..dbe8a7dcafa922 100644 --- a/arch/s390/hypfs/inode.c +++ b/arch/s390/hypfs/inode.c @@ -329,9 +329,8 @@ static void hypfs_kill_super(struct super_block *sb) hypfs_delete_tree(sb->s_root); if (sb_info && sb_info->update_file) hypfs_remove(sb_info->update_file); - kfree(sb->s_fs_info); - sb->s_fs_info = NULL; kill_litter_super(sb); + kfree(sb->s_fs_info); } static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,