From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A63EC5B543 for ; Thu, 5 Jun 2025 05:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89F2E6B0297; Thu, 5 Jun 2025 01:50:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 828076B0299; Thu, 5 Jun 2025 01:50:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C8626B029B; Thu, 5 Jun 2025 01:50:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4761A6B0297 for ; Thu, 5 Jun 2025 01:50:17 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BF9D381893 for ; Thu, 5 Jun 2025 05:50:16 +0000 (UTC) X-FDA: 83520271632.26.50ADBDB Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf22.hostedemail.com (Postfix) with ESMTP id 17EEAC0002 for ; Thu, 5 Jun 2025 05:50:14 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PjGhekro; spf=pass (imf22.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749102615; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i1k6LwACn537b37vOR8lsV0IJYsBwMNmCoPsvjHfv64=; b=2uy4XPZMmnb7qUMHfn/INMhWHwmOejoBj69NGcAn3BVokNyBhY2Y7DOSw5F+Vh+E/DywtN Tw02Id23O2FHM9qrWumPb9m/pesM8T/XW5h+SqSpzSyd6mBMqMxgL4rVAiXFZtKIHGTELB IuK3dSGngmCFc2gO/z9hKOf1E77/z+Y= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PjGhekro; spf=pass (imf22.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749102615; a=rsa-sha256; cv=none; b=YbztCm7nLCHxFDotDNYyUU/1E/6whd64i9Mp8oOmgo3L4PNoIG23csCrKh17SA72CU+w9v 31EGEyAH+WekuhWEDN/Zzo6VxHVxh/tew5hXQP94L5jxo0HP7P5IyuLvnEWlbHXgmmaq0c Pg6FUlTRLz3a66nIXkQAdcv8jv19CGE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 43DA5A4C6E9; Thu, 5 Jun 2025 05:50:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4845C4CEE7; Thu, 5 Jun 2025 05:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749102613; bh=qs0L8RWOQrfH+BuAGm8VA2+QF4D9DsqgbCCykmbS7hM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PjGhekro9i0u1SPcGCom4gAb48wNARMXn6A6gaDblDsaK7HYDJf/JD6QaWG46YBs6 TCAPUsLofAma+mUXCkwb73LupFQtXJzt34OSmd8fIufYmJCjDqolgHV3SH+yI3jfR/ rfPzn9UpcUjNklg9SPRqagfw4CpXPB+HkhG9+/MutkpU+GDNoNDUD8/THQScpcRrzc Q2kLuCyIGvZGf7ihWVGZYPtxALsBLwknrrnVz7RjvqGlsVanzWbK7euwEhqJQV0BR7 fp+Tw4rT0h6FMLbUayWl5q2On0P85sraYAKGvGLSjoc6iiV68atTmA+L5Vnv4Htlnr TCKTY7u+facQw== Date: Thu, 5 Jun 2025 08:49:44 +0300 From: Mike Rapoport To: Paul Moore Cc: Ackerley Tng , linux-security-module@vger.kernel.org, selinux@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, aik@amd.com, ajones@ventanamicro.com, akpm@linux-foundation.org, amoorthy@google.com, anthony.yznaga@oracle.com, anup@brainfault.org, aou@eecs.berkeley.edu, bfoster@redhat.com, binbin.wu@linux.intel.com, brauner@kernel.org, catalin.marinas@arm.com, chao.p.peng@intel.com, chenhuacai@kernel.org, dave.hansen@intel.com, david@redhat.com, dmatlack@google.com, dwmw@amazon.co.uk, erdemaktas@google.com, fan.du@intel.com, fvdl@google.com, graf@amazon.com, haibo1.xu@intel.com, hch@infradead.org, hughd@google.com, ira.weiny@intel.com, isaku.yamahata@intel.com, jack@suse.cz, james.morse@arm.com, jarkko@kernel.org, jgg@ziepe.ca, jgowans@amazon.com, jhubbard@nvidia.com, jroedel@suse.de, jthoughton@google.com, jun.miao@intel.com, kai.huang@intel.com, keirf@google.com, kent.overstreet@linux.dev, kirill.shutemov@intel.com, liam.merwick@oracle.com, maciej.wieczor-retman@intel.com, mail@maciej.szmigiero.name, maz@kernel.org, mic@digikod.net, michael.roth@amd.com, mpe@ellerman.id.au, muchun.song@linux.dev, nikunj@amd.com, nsaenz@amazon.es, oliver.upton@linux.dev, palmer@dabbelt.com, pankaj.gupta@amd.com, paul.walmsley@sifive.com, pbonzini@redhat.com, pdurrant@amazon.co.uk, peterx@redhat.com, pgonda@google.com, pvorel@suse.cz, qperret@google.com, quic_cvanscha@quicinc.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, quic_svaddagi@quicinc.com, quic_tsoni@quicinc.com, richard.weiyang@gmail.com, rick.p.edgecombe@intel.com, rientjes@google.com, roypat@amazon.co.uk, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, steven.sistare@oracle.com, suzuki.poulose@arm.com, tabba@google.com, thomas.lendacky@amd.com, vannapurve@google.com, vbabka@suse.cz, viro@zeniv.linux.org.uk, vkuznets@redhat.com, wei.w.wang@intel.com, will@kernel.org, willy@infradead.org, xiaoyao.li@intel.com, yan.y.zhao@intel.com, yilun.xu@intel.com, yuzenghui@huawei.com, zhiquan1.li@intel.com Subject: Re: [PATCH 1/2] fs: Provide function that allocates a secure anonymous inode Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 17EEAC0002 X-Rspamd-Server: rspam09 X-Stat-Signature: trm87s1fe8w1xwea6rmareqwa5w8q376 X-HE-Tag: 1749102614-174137 X-HE-Meta: U2FsdGVkX1/9X/qIWy/GtkfJVxHy7oB1If0PMm4hYs6pPFl+6ha2FUzeLV3yDRj8a7DUPefJ7jQOqqWGWwIa2YbiyzxRtdFCJzaLVyyul2QRsq4ePKLeN+KQE7Gw1m5UuN9R8jlojveBrGnlQPsw7OfJPQPGwzM0f00lCFJXw8KkcdliJJVi/XWzPflZ6FuBDpdLH3I1weRq6lacrDTtohWC+AsXEB0J4MEKDx4c1s1NC8uJqLmZsWffTYG+lBscWB7JDWdK3v+Yq0dGAFVUVFG4rwG6X1IYWoO6hIU1czOg0Na4BGDNutIYun4n0PE1w8mx5XVPr4RyxlJTEBuGhDGTdZJ5+T7cFLQufdnp8lfLp8JavHJZYw1gde/YDbPNKRJpSPBU9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linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Jun 04, 2025 at 05:13:35PM -0400, Paul Moore wrote: > On Wed, Jun 4, 2025 at 3:59 AM Mike Rapoport wrote: > > > > (added Paul Moore for selinux bits) > > Thanks Mike. > > I'm adding the LSM and SELinux lists too since there are others that > will be interested as well. > > > On Mon, Jun 02, 2025 at 12:17:54PM -0700, Ackerley Tng wrote: > > > The new function, alloc_anon_secure_inode(), returns an inode after > > > running checks in security_inode_init_security_anon(). > > > > > > Also refactor secretmem's file creation process to use the new > > > function. > > > > > > Suggested-by: David Hildenbrand > > > Signed-off-by: Ackerley Tng > > > --- > > > fs/anon_inodes.c | 22 ++++++++++++++++------ > > > include/linux/fs.h | 1 + > > > mm/secretmem.c | 9 +-------- > > > 3 files changed, 18 insertions(+), 14 deletions(-) > > > > > > diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c > > > index 583ac81669c2..4c3110378647 100644 > > > --- a/fs/anon_inodes.c > > > +++ b/fs/anon_inodes.c > > > @@ -55,17 +55,20 @@ static struct file_system_type anon_inode_fs_type = { > > > .kill_sb = kill_anon_super, > > > }; > > > > > > -static struct inode *anon_inode_make_secure_inode( > > > - const char *name, > > > - const struct inode *context_inode) > > > +static struct inode *anon_inode_make_secure_inode(struct super_block *s, > > > + const char *name, const struct inode *context_inode, > > > + bool fs_internal) > > > { > > > struct inode *inode; > > > int error; > > > > > > - inode = alloc_anon_inode(anon_inode_mnt->mnt_sb); > > > + inode = alloc_anon_inode(s); > > > if (IS_ERR(inode)) > > > return inode; > > > - inode->i_flags &= ~S_PRIVATE; > > > + > > > + if (!fs_internal) > > > + inode->i_flags &= ~S_PRIVATE; > > > + > > > error = security_inode_init_security_anon(inode, &QSTR(name), > > > context_inode); > > > if (error) { > > > @@ -75,6 +78,12 @@ static struct inode *anon_inode_make_secure_inode( > > > return inode; > > > } > > > > > > +struct inode *alloc_anon_secure_inode(struct super_block *s, const char *name) > > > +{ > > > + return anon_inode_make_secure_inode(s, name, NULL, true); > > > +} > > > +EXPORT_SYMBOL_GPL(alloc_anon_secure_inode); > > > + > > > static struct file *__anon_inode_getfile(const char *name, > > > const struct file_operations *fops, > > > void *priv, int flags, > > > @@ -88,7 +97,8 @@ static struct file *__anon_inode_getfile(const char *name, > > > return ERR_PTR(-ENOENT); > > > > > > if (make_inode) { > > > - inode = anon_inode_make_secure_inode(name, context_inode); > > > + inode = anon_inode_make_secure_inode(anon_inode_mnt->mnt_sb, > > > + name, context_inode, false); > > > if (IS_ERR(inode)) { > > > file = ERR_CAST(inode); > > > goto err; > > > diff --git a/include/linux/fs.h b/include/linux/fs.h > > > index 016b0fe1536e..0fded2e3c661 100644 > > > --- a/include/linux/fs.h > > > +++ b/include/linux/fs.h > > > @@ -3550,6 +3550,7 @@ extern int simple_write_begin(struct file *file, struct address_space *mapping, > > > extern const struct address_space_operations ram_aops; > > > extern int always_delete_dentry(const struct dentry *); > > > extern struct inode *alloc_anon_inode(struct super_block *); > > > +extern struct inode *alloc_anon_secure_inode(struct super_block *, const char *); > > > extern int simple_nosetlease(struct file *, int, struct file_lease **, void **); > > > extern const struct dentry_operations simple_dentry_operations; > > > > > > diff --git a/mm/secretmem.c b/mm/secretmem.c > > > index 1b0a214ee558..c0e459e58cb6 100644 > > > --- a/mm/secretmem.c > > > +++ b/mm/secretmem.c > > > @@ -195,18 +195,11 @@ static struct file *secretmem_file_create(unsigned long flags) > > > struct file *file; > > > struct inode *inode; > > > const char *anon_name = "[secretmem]"; > > > - int err; > > > > > > - inode = alloc_anon_inode(secretmem_mnt->mnt_sb); > > > + inode = alloc_anon_secure_inode(secretmem_mnt->mnt_sb, anon_name); > > > if (IS_ERR(inode)) > > > return ERR_CAST(inode); > > > > I don't think we should not hide secretmem and guest_memfd inodes from > > selinux, so clearing S_PRIVATE for them is not needed and you can just drop > > fs_internal parameter in anon_inode_make_secure_inode() > > It's especially odd since I don't see any comments or descriptions > about why this is being done. The secretmem change is concerning as > this is user accessible and marking the inode with S_PRIVATE will > bypass a number of LSM/SELinux access controls, possibly resulting in > a security regression (one would need to dig a bit deeper to see what > is possible with secretmem and which LSM/SELinux code paths would be > affected). secretmem always had S_PRIVATE set because alloc_anon_inode() clears it anyway and this patch does not change it. I'm just thinking that it makes sense to actually allow LSM/SELinux controls that S_PRIVATE bypasses for both secretmem and guest_memfd. -- Sincerely yours, Mike.