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=1794591390; b=D3oIfilCpMFC3UsEC+w6GiZKES/b2GqhU4fQSv2qpfhvkjdJUmNooxzFJyCY0zMNdHBu 5b3Svv3hELDhsHph+hjsXsXKvv09WfJt4bjwkEso8NAgKEzQORqSvc8/hUO6ZNr1Ej6x7 kBDOXNR9rbMH3t7lf7MulWV1gln1+BAZszMeG9GTCCJoUUT+2gZdn9uIMqRPL5tjW1ZGK muy0ssC5AuZxA6j2wTgptQelN8wkkwg0cNCmmkfPZXXT19fckQ008INxZMzwwVedFRhaO SbSaHkFz4LfUC03/oYfh53qdfLmWXwgSdlnawC8s6ZJqsqrG8fojfcwB7YJCtGXtTaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794591390; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=JwN85pOFPytDgI7ePoh1pLvgsifdUy+ViNx55jw2Y3k=; b=ZN2qiBoSYTY0SbEFtAT4vDk2MM+09yvO9seAfhBMztqPFDbyb9VzWn/1TbQFZIg1PzKh NgsQgSJivtGbkL2ef4KdenMor1QFlm3Z1D4rix3YIcDQo5UqSASKJzVbGxbPKlxbU01Uw W3d1kOPtaIM8YEwXbq/mMOwacIvfURPr1LD/mCLb7RhiPmDqex4C8dhK5yu30emLF84Xs cBq9MWFnidAd2nDAbf702ef3p52ubwjie0BKGdVr6z7MJO+/KVkfd/t8sZIzlcrC+HpxC LFWSLh7D1AMKD1pd5/1uihd5a+vKCsLfCQMfsaMWpZPtVC+UeB+xxkSx5qTy8Ub+DXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=NOnjveZM; 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 ABA92606A882; Fri, 13 Nov 2026 17:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=NOnjveZM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D3741F000C4; Fri, 13 Nov 2026 17:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794591390; bh=JwN85pOFPytDgI7ePoh1pLvgsifdUy+ViNx55jw2Y3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NOnjveZMDXl7pu+0ay5gnXlhkMbLMFjftiPi08ws/ZUeVVRvqbGyc6K36essB700t N7yqB35g43BaVXh5WRDB2C6kj0qN9r+0+JMt6J4q9cG6HBFkEYHVsU+Nn00tcwxfIP Oske8egzoNkDXJXmT8oAmL7h4V1mb9s8dPSdVE+M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Pedro Falcato , "Kiryl Shutsemau (Meta)" , Zi Yan , Baolin Wang , "Pratyush Yadav (Google)" , "Gregory Price (Meta)" , "David Hildenbrand (Arm)" , Sasha Levin Subject: [PATCH 6.12 490/670] mm/shmem: honour F_SEAL_EXEC when an ACL is set Date: Fri, 13 Nov 2026 10:50:54 -0500 Message-ID: <20261113153828.541490982@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153811.177190860@linuxfoundation.org> References: <20261113153811.177190860@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 0237c47ca17005ea41b510c6116f0257dbf84eab ] 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 Reviewed-by: Pratyush Yadav (Google) Tested-by: Gregory Price (Meta) [ david: use common helper; simplify description ] Link: https://patch.msgid.link/20261029-fixes_shmem-v4-4-392fc715d8f6@kernel.org Signed-off-by: David Hildenbrand (Arm) [ sashal: removed const from the mnt_idmap parameter of shmem_set_acl() to match the existing ACL interface ] Signed-off-by: Sasha Levin --- 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 246daadbfde82..bb07ba2992908 100644 --- a/include/linux/memfd.h +++ b/include/linux/memfd.h @@ -2,8 +2,17 @@ #ifndef __LINUX_MEMFD_H #define __LINUX_MEMFD_H +#include #include +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 881cbeaf3f747..8de38d7a98f92 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -75,6 +75,7 @@ static struct vfsmount *shm_mnt __ro_after_init; #include #include #include +#include #include #include #include @@ -1255,10 +1256,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)) { @@ -4939,12 +4941,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 simple_set_acl +#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.53.0