From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793106236; b=Nhh3VbKiewsUB01Cc7d+CLyz9hpxq79FbgOJZYiqRum4xRSTQSNeKMe7KKZUr5w3w/lj oLwCC6nqfxPlfNPLd7A9HrJMfiVLbwNucXpThb+jxMYxR6sO7TruXU1UOHWfXqlY5eJHL TSCEorW81z1tIRCYXEK+RESbHYgqmQIAo+kbXZnHVantipCsOLA10vavpajBojt0Mgd2p 1X6ZQp061igfuV+KASKr4/cI+vN9Dk8PzkNWLs1PqBAjwoGMpe5Aj39Ln2s9TYGZFnPZr 5grZOR/6DCYCl24Zkk3p+AvDA+LVBWCKbiEyfqZNKysbMJ7hB+2urwq9mXUcoBjI/HQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793106236; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=hC55Qi4eXuQIoCZ99pSQo79BaI1KHhCtzc4eGRsCBL0=; b=pKtLU7kQqG9gB9a7F35KoLqMI9ifS17MpSyfhPF2xUXM7h4UTwX+V2wD6NLREtcQ1WKd vHHfI02viyJzNCxvCxX+rMrzxWvtgX3uZwbVB7c/ZDcTdjpMhhD7R5/w2Tw9OwYpiGP9E JKlAXvyFc4ogBKUUyYliU5NpbI8ldN1MDDOE9EoKT8otYIIcpNe4hK0VG2Ych7eoEPaTW FjANacndITaN21V2Peve78976SAvBrLkV5bQ7EBCy4nZSXGT055DjT0kaBsRQYzkqt9Ou gV0eTeMmCYHZxRUb0gmNTrzufL+p1R9hQSyrtf2fI4+CpR/R+dKNDMXp26g+dQPx5GA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=n7yoXSGq; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA227606A31D; Tue, 27 Oct 2026 13:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=n7yoXSGq Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E4A01F031E2; Tue, 27 Oct 2026 13:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793106235; bh=hC55Qi4eXuQIoCZ99pSQo79BaI1KHhCtzc4eGRsCBL0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=n7yoXSGqMdjXayonbQf+7G66wu69moojGkJmCrjbkYB0pO+QxUBvF57OvURz5rv3p nHTiU93jJ1BnhgCYUkly6l9+tlIM+PLAP8dDeR9ZqCoVNsL84QvUoxYTMsDszHlJwH dUMkAfzX/DTqL1b/xY1Kv3f9kKdT8fRUlq32w8pbVVNZ24mbcqRy6CeB2GlZ3twejy OLFEzynVlJHijihZ3jr52JMWgRC1Lvb3vp/Dicn+U68YTVGBE9ZttSpq5i8PoUAhTp X+vdsK6OKw0KlwgnLE9nHuvZswe7C6JlO2S7+Kbporx9/q24oK273oNnXpmiZutPKm oL5dsN8eezsfg== From: "David Hildenbrand (Arm)" Date: Tue, 27 Oct 2026 14:03:09 +0100 Subject: [PATCH v2 04/14] mm/shmem: honour F_SEAL_EXEC when an ACL is set X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261027-fixes_shmem-v2-4-86a00952acb9@kernel.org> References: <20261027-fixes_shmem-v2-0-86a00952acb9@kernel.org> In-Reply-To: <20261027-fixes_shmem-v2-0-86a00952acb9@kernel.org> To: Andrew Morton , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Johannes Weiner , Vladimir Davydov , Michal Hocko , Hugh Dickins , Baolin Wang , Lukas Czerner , Carlos Maiolino , Christian Brauner , Jan Kara , Daniel Verkamp , Jeff Xu , Muchun Song , Oscar Salvador , David Stevens , "Matthew Wilcox (Oracle)" , William Kucharski , Chris Li , Kairui Song , Nhat Pham , Miaohe Lin , Naoya Horiguchi Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "David Hildenbrand (Arm)" , Chris Mason , stable@vger.kernel.org, Pedro Falcato , "Kiryl Shutsemau (Meta)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3836; i=david@kernel.org; h=from:subject:message-id; bh=Un47mrAj2u61w09m+y/7O22VTuewKSP6t/UBvELblto=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIeLBR4dGjF0q1Tr8z/fH3Lq5BkqVo5G+6J6+S2hzxT+ y0Y9rhTqaOUhUGMg0FWTJElKPi+wcuX62qr3fiYYeawMoEMYeDiFICJeJ5j+O9kL5Sikbv6oQ3D /evTs5LepuTUm7zfKpQZ92VXzfns83cYGe6a77jqsuKCsnul+SvRNkWerJNczRF8S+K9fCa9jqg T5AQA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A From: Chris Mason The owner of a memfd sealed with F_SEAL_EXEC can still change its execute bits by setting a POSIX access ACL. With CONFIG_TMPFS_POSIX_ACL, this lets an unprivileged owner make a non-executable memfd executable, bypassing vm.memfd_noexec=2. simple_set_acl() updates i_mode directly, bypassing the seal check in shmem_setattr(). Add shmem_set_acl() to check the resulting mode. Share the F_SEAL_EXEC check with shmem_setattr() using memfd_check_seals_mode() in include/linux/memfd.h. Fix generated by an LLM and sent by Chris Mason in private. Fixes: 6fd7353829ca ("mm/memfd: add F_SEAL_EXEC") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason Acked-by: Pedro Falcato Acked-by: Kiryl Shutsemau (Meta) Acked-by: Zi Yan Reviewed-by: Baolin Wang Tested-by: Gregory Price (Meta) [ david: use common helper; simplify description ] Signed-off-by: David Hildenbrand (Arm) --- include/linux/memfd.h | 9 +++++++++ mm/shmem.c | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/include/linux/memfd.h b/include/linux/memfd.h index c159e40e3f34a..272479317cf10 100644 --- a/include/linux/memfd.h +++ b/include/linux/memfd.h @@ -2,10 +2,19 @@ #ifndef __LINUX_MEMFD_H #define __LINUX_MEMFD_H +#include #include #define MEMFD_ANON_NAME "[memfd]" +static inline int memfd_check_seals_mode(unsigned int seals, umode_t old_mode, + umode_t new_mode) +{ + if ((seals & F_SEAL_EXEC) && ((old_mode ^ new_mode) & 0111)) + return -EPERM; + return 0; +} + #ifdef CONFIG_MEMFD_CREATE extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg); struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx); diff --git a/mm/shmem.c b/mm/shmem.c index fadf23f9e21ed..ad644a268c0d2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -77,6 +77,7 @@ static struct vfsmount *shm_mnt __ro_after_init; #include #include #include +#include #include #include #include @@ -1546,10 +1547,11 @@ static int shmem_setattr(struct mnt_idmap *idmap, if (error) return error; - if ((info->seals & F_SEAL_EXEC) && (attr->ia_valid & ATTR_MODE)) { - if ((inode->i_mode ^ attr->ia_mode) & 0111) { - return -EPERM; - } + if (attr->ia_valid & ATTR_MODE) { + error = memfd_check_seals_mode(info->seals, inode->i_mode, + attr->ia_mode); + if (error) + return error; } if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { @@ -5397,12 +5399,35 @@ static const struct file_operations shmem_file_operations = { #endif }; +#ifdef CONFIG_TMPFS_POSIX_ACL +static int shmem_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, + struct posix_acl *acl, int type) +{ + struct inode *inode = d_inode(dentry); + umode_t mode = inode->i_mode; + int error; + + if (type == ACL_TYPE_ACCESS) { + error = posix_acl_equiv_mode(acl, &mode); + if (error < 0) + return error; + error = memfd_check_seals_mode(SHMEM_I(inode)->seals, + inode->i_mode, mode); + if (error) + return error; + } + return simple_set_acl(idmap, dentry, acl, type); +} +#else +#define shmem_set_acl NULL +#endif + static const struct inode_operations shmem_inode_operations = { .getattr = shmem_getattr, .setattr = shmem_setattr, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, - .set_acl = simple_set_acl, + .set_acl = shmem_set_acl, .fileattr_get = shmem_fileattr_get, .fileattr_set = shmem_fileattr_set, #endif -- 2.43.0