From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Dominik Maier <dmnk@google.com>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, dmnk+artist@google.com
Subject: Re: [PATCH] hugetlbfs: respect F_SEAL_GROW and FMODE_WRITE before growing i_size in mmap
Date: Fri, 20 Nov 2026 10:21:34 +0100 [thread overview]
Message-ID: <b644bcc7-0c3b-4001-89e7-3e558fbb5d76@kernel.org> (raw)
In-Reply-To: <ac761e74-b38a-4daf-b855-55d5790504e1@kernel.org>
On 11/20/26 10:15, David Hildenbrand (Arm) wrote:
> On 11/19/26 20:22, Dominik Maier wrote:
>> hugetlbfs_file_mmap() expands inode->i_size whenever VMA_WRITE_BIT is set
>> and len > inode->i_size, without checking whether a shared mapping
>> violates F_SEAL_GROW or inode_newsize_ok(), or whether a private mapping
>> holds write access to the underlying file and has no active write/growth
>> seals.
>>
>> Because do_mmap() and memfd_check_seals_mmap() allow PROT_WRITE with
>> MAP_PRIVATE | MAP_NORESERVE on O_RDONLY descriptors and sealed
>> MFD_HUGETLB memfds, an untrusted IPC recipient holding a read-only or
>> F_SEAL_GROW-sealed hugetlb descriptor can inflate the shared
>> inode->i_size to multi-terabyte values even when vm.nr_hugepages is 0,
>> causing trusted peers relying on F_SEAL_GROW to hit SIGBUS past the
>> allocated pages. Similarly, MAP_SHARED | PROT_WRITE beyond i_size on an
>> F_SEAL_GROW memfd (without F_SEAL_WRITE) bypasses the growth seal.
>>
>> For MAP_SHARED | PROT_WRITE mappings with len > inode->i_size, reject
>> F_SEAL_GROW with -EPERM and enforce inode_newsize_ok() before reserving
>> huge pages. For MAP_PRIVATE | PROT_WRITE mappings, keep allowing the
>> private VMA itself while only expanding inode->i_size when FMODE_WRITE
>> is set, no growth/write seals are active, and inode_newsize_ok()
>> succeeds.
>>
>> This issue was discovered with an AI-assisted code review tool (ARTIST)
>> and reproduced in QEMU/KVM on an unmodified v7.4-rc3 kernel without
>> kernel modifications or error injection; a standalone reproducer is
>> available upon maintainers' request. The fix was verified against the
>> reproducer in QEMU/KVM, compile-tested with -Werror, and checked with
>> checkpatch.pl --strict.
>>
>> Fixes: ff62a3421044 ("hugetlb: implement memfd sealing")
>> Fixes: 045c7a3f53d9 ("hugetlbfs: fix offset overflow in hugetlbfs mmap")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Dominik Maier <dmnk@google.com>
>
> Thanks for your report.
>
> Your patch does various things, and I had AI fixes for all of these issues
> already. I accepted some, I rejected some.
>
> Take a look at:
>
> https://lore.kernel.org/all/20261028-fixes_hugetlb-v1-11-a0a033db180f@kernel.org/
>
> That was already merged, and, in particular, my description in it.
>
>
> "We currently also allow CoW mappings to grow a file. Disallowing this,
> maybe even only for read-only file descriptors, could break existing
> userspace, so we have to be more careful. QEMU's file backend is an
> example user that might rely on such things, and would suddenly start
> getting SIGBUS when faulting in memory outside EOF.
>
> So be careful and focus on F_SEAL_GROW for now."
>
>
> And in my private notes I have to a bug fix called "hugetlbfs: grow a file in
> mmap() only if open for write"
>
> "There is a real chance to break user-space: for example, supply an empty
> hugetlb file to QEMU, which might open it read-only and then SIGBUS on access.
> It would only warn that fallocate() fails and continue. This is long-standing
> behavior. Read-only users can already fill hugetlb files holes through
> read-faults ..."
>
> So I don't think there is anything left to fix here that would be worth changing
> long-standing behavior and possibly breaking user space.
Thinking again, I assume we could also let F_SEAL_GROW stop reserving beyond
EOF. But everything else just has the chance to break user-space.
--
Cheers,
David
prev parent reply other threads:[~2026-11-20 9:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 19:22 [PATCH] hugetlbfs: respect F_SEAL_GROW and FMODE_WRITE before growing i_size in mmap Dominik Maier
2026-11-20 9:15 ` David Hildenbrand (Arm)
2026-11-20 9:21 ` David Hildenbrand (Arm) [this message]
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=b644bcc7-0c3b-4001-89e7-3e558fbb5d76@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dmnk+artist@google.com \
--cc=dmnk@google.com \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
/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