From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Samiullah Khawaja <skhawaja@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>
Cc: Jeff Xu <jeffxu@google.com>,
Daniel Verkamp <dverkamp@chromium.org>,
David Matlack <dmatlack@google.com>,
Pasha Tatashin <tatashin@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] hugetlbfs: enforce F_SEAL_EXEC on chmod
Date: Mon, 26 Oct 2026 22:08:16 +0100 [thread overview]
Message-ID: <5d441cff-ef78-4bdf-b727-9eb697ca7478@kernel.org> (raw)
In-Reply-To: <20261026205555.2918396-1-skhawaja@google.com>
On 10/26/26 21:55, Samiullah Khawaja wrote:
> F_SEAL_EXEC prevents the exec bits of a memfd from being changed once
> the seal has been set. F_SEAL_EXEC is included in F_ALL_SEALS, so
> userspace can set it with F_ADD_SEALS on hugetlbfs memfds just like on
> shmem memfds, and F_GET_SEALS then reports it as set. However, the check
> that rejects the mode change was only added to shmem_setattr().
> hugetlbfs_setattr() never looks at the seal, so the owner of a sealed
> hugetlbfs memfd can still make it executable with chmod(). For the same
> reason, MFD_NOEXEC_SEAL provides no guarantee when it is combined with
> MFD_HUGETLB.
>
> The memfd selftest already covers this, but only the shmem run passes.
> When run as "memfd_test hugetlbfs", the test aborts in SEAL-EXEC because
> fchmod() succeeds on a sealed file, and none of the remaining tests are
> executed.
>
> Add the same check to hugetlbfs_setattr() that shmem_setattr() has, so
> that a mode change touching the exec bits fails with -EPERM while
> F_SEAL_EXEC is set.
>
> Fixes: 6fd7353829ca ("mm/memfd: add F_SEAL_EXEC")
> Cc: stable@vger.kernel.org
> Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
> ---
> fs/hugetlbfs/inode.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 01c4d6f44ebe..56e0588d295d 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -842,6 +842,10 @@ static int hugetlbfs_setattr(const struct mnt_idmap *idmap,
>
> trace_hugetlbfs_setattr(inode, dentry, attr);
>
> + if ((info->seals & F_SEAL_EXEC) && (ia_valid & ATTR_MODE) &&
> + ((inode->i_mode ^ attr->ia_mode) & 0111))
> + return -EPERM;
> +
> if (ia_valid & ATTR_SIZE) {
> loff_t oldsize = inode->i_size;
> loff_t newsize = attr->ia_size;
>
> base-commit: f1ac44c32cba88ad65dcecd4a279661d14e93651
https://lore.kernel.org/r/20261026-fixes_shmem-v1-5-703206d5fa0c@kernel.org
--
Cheers,
David
next prev parent reply other threads:[~2026-10-26 21:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 20:55 [PATCH] hugetlbfs: enforce F_SEAL_EXEC on chmod Samiullah Khawaja
2026-10-26 21:08 ` David Hildenbrand (Arm) [this message]
2026-10-27 20:56 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5d441cff-ef78-4bdf-b727-9eb697ca7478@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dmatlack@google.com \
--cc=dverkamp@chromium.org \
--cc=jeffxu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=skhawaja@google.com \
--cc=stable@vger.kernel.org \
--cc=tatashin@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox