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=1794590612; b=yp7lBod2yEH+Q7nUdLlyj22SyVUwQ4uqFUJkmlxZPxve6Xlt8UUFOwfAN5FBdsq2m/bt BxvFTZnHv3RrgflHXC1qV9t0fAt6ZUY5glr+QpvG3mInIPpuaURbEzmYf1h6fbT2rqBbk 6KfkexYpwIxn+v3jLeOn3pH6Q+8zQAlFLoz79IAxpwqx4gSPx7vtNxSBY1/ImiiKwY0+m 4mtAE8Dz1G0+c3KXyYNgFPp1f80dedg2faxkf3I6j2iGLpEP/iKMIAAkZsk96SVFuluoh v7JQvhsY/RvuQYPWhkb0WNk71+Alm/+S+OxWia/3c/XQsElLcWoZK6faAyBleXA4S1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794590612; 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=JYGqic5Hq8w9r+VjkQnFFDZDmOgepekyndxpw9jbj2I=; b=IGw4BN7+31cq8Gr6SdNiUdHQ0RVAepw2aKfu+2R+doU2HwEEEuAv01Fvd6AE4IoF8i65 Hu/N1Hl5ZETuYxYe9oFR/ZyR4PSrbjLlRZk4u1G6xbtkf83LOhYBl9YMaEhqcp7GKOw2U qqVCBr8v9ie2h47QnhKpezewhOliUsoeIqmleJTnM8sS0L6WsWoTkOsUXYgiBy2SlwV5Z OOXFsMpTDcZ7TEF20VAUdWqwmsX151PEys7Tzb45X682osWd8VVURzpzFWXeTaMZQeUGw yZAIhRTifdaK7sCQjTKba0HORvG9eb9N/JxUDI9iodNw87QAVqCp7gKV/rnBUml586g== 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="iM2/7ZSw"; 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 8E6A66075862; Fri, 13 Nov 2026 17:23:32 +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=iM2/7ZSw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F64A1F000C4; Fri, 13 Nov 2026 17:23:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794590612; bh=JYGqic5Hq8w9r+VjkQnFFDZDmOgepekyndxpw9jbj2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iM2/7ZSwhP8o1+M9kWbcVYc8IsVc0gAUpZq1EbUoPzj5jD2/k/msszcLWrgSzVTQT yB/h2s21PX4/5NSQ2AJ7wpjIErjhen4xJzylumKqwEmbJFp5pe+ctwBFTT3YqWGq7K HIK7fOACqiU85HR6NdJY5Yq6aH71BNMrlxPQ/f0Y= 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.18 538/686] mm/shmem: honour F_SEAL_EXEC when an ACL is set Date: Fri, 13 Nov 2026 10:51:11 -0500 Message-ID: <20261113153839.489534031@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 shmem_set_acl()'s mnt_idmap parameter to match the existing callback and simple_set_acl() interfaces ] 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 6f606d9573c38..97b8a94cd0b31 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 5efde9fcc3057..6f4c85a3f6410 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -76,6 +76,7 @@ static struct vfsmount *shm_mnt __ro_after_init; #include #include #include +#include #include #include #include @@ -1321,10 +1322,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)) { @@ -5295,12 +5297,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