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=1795038213; b=k+/TRcwxUDieo5Zd3yF2CoZEuOqZ9IULkne/rOju+aOOeSblk786exA883iRTtuxpfTA efpqy3q7I4TFSClBeeX3e4ZvKGzKl16wI1fNhuzOxCwZDLk2TeXMIkb+GbrB4BCZnffVj vqBDLRM42zKu/f87EwlqCD0xPtJTH6As4DUE7RfM3uoU6Oy4p6eIFK93RQn9f2gdvl1EG 4knQbDSGEO2u9m4OkBncLuBem5nXPrUtdMVyJIkPpeKvwpwlMyFowPfjD8pj9IbzPf4Xq KnQf/KIK5irGL4Y4msUtHgC1gBXhXBGCVppC03C8JcECPyw5Au9bvAY/pFUPHnR7vRw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795038213; 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=lqE9gx4nWtgcYBRQeql0nFt3G1wG++mTFA0iNzKPCv4=; b=cRKqXgL1MQ+TWJ2D8VjKVz+Z6f+CGW/Q+FJQrqOUx4jWd0ZrNmbterH/ISQijr4xqaYh 5jHB4sny1XIqgGh3hGuIPpfRBUDEiOpMEiFquRhhLgYRWdZqIBH6qwgwEbddPUWSykJhF 1mE0jiK9P6rF3KFEH279Nq88tE975wG/tGIfEpFm9EDVn4gzdRGHEZHoFf3F7TNXQXjg+ lpS6gryj5iFLypd6aiefSYHB0Ub9pqGLkOGPXk4SaH1N2PF+yeSRCZPpiRvuwIF42HW2i 3spDmWYDmwSvURmpXzVSRCN+jv1vAs688KmbH/4Yivd72HAxdY6E7mBjDRvzpbbfHyA== 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="nQNO9/hz"; 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 0B68B606A320; Wed, 18 Nov 2026 21:43:33 +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=nQNO9/hz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CACE1F000C4; Wed, 18 Nov 2026 21:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795038212; bh=lqE9gx4nWtgcYBRQeql0nFt3G1wG++mTFA0iNzKPCv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nQNO9/hzSgfHWz70faNgABp47ZCzgFmMTaECKbqP1Gp1XVcC3LEqeligEcllerXeM zTbx346RviVz0KYgww+3R5mcMLl9aPMdVn8vugp8RWp6NPGlfh8AAT9KxCePFl03Bn TOqv7V8MBY0S40nDacLcHEYNcofqU8Y/qNOXsdeQ= 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.6 1666/3318] mm/shmem: honour F_SEAL_EXEC when an ACL is set Date: Wed, 18 Nov 2026 15:38:08 +0100 Message-ID: <20261118150411.763776995@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@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.6-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: changed shmem_set_acl() to accept a non-const mnt_idmap pointer ] 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 40cc726a8a0ce..a0f022e2a58cb 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); unsigned int *memfd_file_seals_ptr(struct file *file); diff --git a/mm/shmem.c b/mm/shmem.c index e6b39b49caec7..0f7c7ec48837a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -75,6 +75,7 @@ static struct vfsmount *shm_mnt; #include #include #include +#include #include #include #include @@ -1202,10 +1203,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)) { @@ -4524,12 +4526,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