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 63F25C71159 for ; Thu, 19 Jun 2025 05:37:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03FF56B0089; Thu, 19 Jun 2025 01:37:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 017006B008C; Thu, 19 Jun 2025 01:37:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E964B6B0093; Thu, 19 Jun 2025 01:37:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DD6C66B0089 for ; Thu, 19 Jun 2025 01:37:24 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 62838A35DA for ; Thu, 19 Jun 2025 05:37:24 +0000 (UTC) X-FDA: 83571042408.02.6E864F0 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf07.hostedemail.com (Postfix) with ESMTP id BE62440005 for ; Thu, 19 Jun 2025 05:37:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OR4cAjwN; spf=pass (imf07.hostedemail.com: domain of rppt@kernel.org designates 172.105.4.254 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=1750311442; a=rsa-sha256; cv=none; b=M1vFZZMADxt9B9NTZphSdf12Mw1iu0gnFnnFiNF4ZbJg9gQ5+Ljnqg9clm9JCjkp5WzdP7 sf8x61jSn1Xu/0o6i0ZHPsOt8JcmuhA/3/0/7NJ/6B9c0kwSyP4ayWhzZl3mCRZgWNBUk9 8daYSMW+CfW/OdoFg5jDlL7QYGOSGu8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OR4cAjwN; spf=pass (imf07.hostedemail.com: domain of rppt@kernel.org designates 172.105.4.254 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=1750311442; 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=6pFWe0LAYuDT5RfpP8+F4D1uT6VEVV7rVgsChoahHVo=; b=0NPoVGyQNxEwNYvESBaTOAe4e2DA7d11YvMXyKjpy6Qerjp1ECGWxG+4mTRrMBgfxgfPsq zRRp09q1pGF63OBzIsCy+axCbszV3cPHyZKUjW+gqLvB+SbjX4cnTX1UR8SMkEnvZym1GH AR/rqG63zNv6qDTOb1B8hx6JhFyFaJk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id E2C03614B7; Thu, 19 Jun 2025 05:37:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6FBCC4CEEA; Thu, 19 Jun 2025 05:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750311441; bh=CGFYslQlYW28b83jtPiXInTX2NXpIKy71b9x3BZGqSo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OR4cAjwNo5wTYjgFpDC06vgMwWeVUlDkFt6P/PrdIsZc5cizAUV5QN+ZwbHohDycZ HH2zoU0ftohWLkRwMQPyWPT2yndJWQXBzxp/1gZr7g030cH8ZxL0HQ1JHMRBxp6ZjE SQPIypgESqrDheTs8P8q9DJn3McibdDMY2/uUr1gUkLHGsU0FougmgKnk3EfFahcMf 8p7SPvWyq3QrtydLEZxp4Oxsj1UW5n40m7AwrSCbw5w75WS8tfHRMoihWOSxlptPA+ vM9CP6m8PKGUQJqIrLZaK5IzpuhToHZ1dJIGPZLoV6QiyX8K01e1OVQOqDSOb5AXkr GQmKqnw4EifCw== Date: Thu, 19 Jun 2025 08:36:48 +0300 From: Mike Rapoport To: Shivank Garg Cc: Ira Weiny , Paul Moore , 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, 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: <68430497a6fbf_19ff672943@iweiny-mobl.notmuch> <647ab7a4-790f-4858-acf2-0f6bae5b7f99@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <647ab7a4-790f-4858-acf2-0f6bae5b7f99@amd.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BE62440005 X-Stat-Signature: 4x9tactrngeib7rm868ko9frfg7wyy6r X-Rspam-User: X-HE-Tag: 1750311442-67300 X-HE-Meta: U2FsdGVkX1+0qX3ZT6QRBN81zNHM0uIWmCbN95fIk8zPt0sGQGVZWooDX83Uv2Z4G25BkJcA686nI41/Gj/2OJ/TzBEGCsAX3/35n3MjWu9oBGAya9zaaTjvL63poJbuMhKAU0hT67tbI/q88VDO4hxbSM3NbKRVOphv5QyUC3VB3AeM5/f32K/vODg+0XT1KHVZoibl5QYhRTXhheH4HX3pMzMDVGws+8JmOtrKO07Iqg/KVLar4AAMYyLVRnLt7VPhDVRpFXV0qdTyWv2xAkUAyf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-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jun 16, 2025 at 06:30:09PM +0530, Shivank Garg wrote: > > > On 6/6/2025 8:39 PM, Ira Weiny wrote: > > Paul Moore wrote: > >> On Thu, Jun 5, 2025 at 1:50 AM Mike Rapoport wrote: > >>> > >>> secretmem always had S_PRIVATE set because alloc_anon_inode() clears it > >>> anyway and this patch does not change it. > >> > >> Yes, my apologies, I didn't look closely enough at the code. > >> > >>> I'm just thinking that it makes sense to actually allow LSM/SELinux > >>> controls that S_PRIVATE bypasses for both secretmem and guest_memfd. > >> > >> It's been a while since we added the anon_inode hooks so I'd have to > >> go dig through the old thread to understand the logic behind marking > >> secretmem S_PRIVATE, especially when the > >> anon_inode_make_secure_inode() function cleared it. It's entirely > >> possible it may have just been an oversight. anon_inode_make_secure_inode() was introduced when more than 10 versions of secretmem already were posted so it didn't jump at me to replace alloc_anon_inode() with anon_inode_make_secure_inode(). > > I'm jumping in where I don't know what I'm talking about... > > > > But my reading of the S_PRIVATE flag is that the memory can't be mapped by > > user space. So for guest_memfd() we need !S_PRIVATE because it is > > intended to be mapped by user space. So we want the secure checks. > > > > I think secretmem is the same. Agree. > > Do I have that right? > > > Hi Mike, Paul, > > If I understand correctly, > we need to clear the S_PRIVATE flag for all secure inodes. The S_PRIVATE flag was previously > set for secretmem (via alloc_anon_inode()), which caused security checks to be > bypassed - this was unintentional since the original anon_inode_make_secure_inode() > was already clearing it. > > Both secretmem and guest_memfd create file descriptors > (memfd_create/kvm_create_guest_memfd) > so they should be subject to LSM/SELinux security policies rather than bypassing them with S_PRIVATE? > > static struct inode *anon_inode_make_secure_inode(struct super_block *s, > const char *name, const struct inode *context_inode) > { > ... > /* Clear S_PRIVATE for all inodes*/ > inode->i_flags &= ~S_PRIVATE; > ... > } > > Please let me know if this conclusion makes sense? Yes, makes sense to me. > Thanks, > Shivank -- Sincerely yours, Mike.