All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@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: "David Hildenbrand" <david@kernel.org>,
	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 19:22:38 +0000	[thread overview]
Message-ID: <sashiko-outbox-225922@kernel.org> (raw)
In-Reply-To: <20261119192209.2651562-1-dmnk@google.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] hugetlbfs: non-fatal inode_newsize_ok() in
  hugetlbfs_file_mmap() sends SIGXFSZ
- [Medium] hugetlbfs: missing write-seal check in hugetlbfs_file_mmap()
  shared branch
- [Low] hugetlbfs: inaccurate Fixes trailer 045c7a3f53d9 for MAP_PRIVATE
  i_size growth
--

commit 9d1ca8a773e4ed12af22f0ee1ea69a706da80ecd
Author: Dominik Maier <dmnk@google.com>

> hugetlbfs: respect F_SEAL_GROW and FMODE_WRITE before growing i_size in mmap
>
> 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>

[Severity: Low]
045c7a3f53d9 ("hugetlbfs: fix offset overflow in hugetlbfs mmap") only
converted inode->i_size = len to i_size_write(inode, len).  The commit
that allowed MAP_PRIVATE | PROT_WRITE mappings on O_RDONLY descriptors to
reach the i_size expansion was 1e8f889b10d8 ("[PATCH] Hugetlb: Copy on
Write support"), which removed the early check rejecting writable private
mappings.

> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index ca63a530a26a1..c75f9ea4c9043 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -100,10 +100,12 @@ static const struct fs_parameter_spec hugetlb_fs_parameters[] = {
>  static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
>  {
>  	struct inode *inode = file_inode(file);
> +	struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
>  	loff_t len, vma_len;
>  	int ret;
>  	struct hstate *h = hstate_file(file);
>  	vma_flags_t vma_flags;
> +	bool grow_inode = false;
>  
>  	/*
>  	 * vma address alignment (but not the pgoff alignment) has
> @@ -139,6 +141,24 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
>  	inode_lock(inode);
>  	file_accessed(file);
>  
> +	if (vma_test(vma, VMA_WRITE_BIT) && inode->i_size < len) {
> +		if (vma_test(vma, VMA_SHARED_BIT)) {
> +			if (info->seals & F_SEAL_GROW) {
> +				ret = -EPERM;
> +				goto out;
> +			}

[Severity: Medium]
Should the VMA_SHARED_BIT check also reject F_SEAL_WRITE and
F_SEAL_FUTURE_WRITE under inode_lock(inode), like the MAP_PRIVATE branch
below?

memfd_check_seals_mmap() in do_mmap() checks seals without holding
inode_lock(inode), and memfd_add_seals() only calls
mapping_deny_writable() for F_SEAL_WRITE, not F_SEAL_FUTURE_WRITE:

CPU0                                  CPU1
do_mmap()
  memfd_check_seals_mmap()
                                      memfd_add_seals(..., F_SEAL_FUTURE_WRITE)
                                        inode_lock(inode)
                                        *file_seals |= F_SEAL_FUTURE_WRITE
                                        inode_unlock(inode)
  ...
  hugetlbfs_file_mmap()
    inode_lock(inode)
    if (info->seals & F_SEAL_GROW)
    ...
    i_size_write(inode, len)  <-- bypasses F_SEAL_FUTURE_WRITE

A concurrent MAP_SHARED | PROT_WRITE mmap() can therefore bypass
F_SEAL_FUTURE_WRITE after the seal has been committed, growing
inode->i_size and creating a writable shared mapping.

> +			ret = inode_newsize_ok(inode, len);
> +			if (ret)
> +				goto out;
> +			grow_inode = true;
> +		} else if ((file->f_mode & FMODE_WRITE) &&
> +			   !(info->seals & (F_SEAL_GROW | F_SEAL_WRITE |
> +					    F_SEAL_FUTURE_WRITE)) &&
> +			   !inode_newsize_ok(inode, len)) {
> +			grow_inode = true;
> +		}
> +	}

[Severity: Medium]
Does calling inode_newsize_ok(inode, len) as a non-fatal condition in the
MAP_PRIVATE branch send SIGXFSZ to current while still succeeding?

When len exceeds rlimit(RLIMIT_FSIZE), inode_newsize_ok() calls
send_sig(SIGXFSZ, current, 0) before returning -EFBIG.  Because this
branch ignores the error and continues, a MAP_PRIVATE | PROT_WRITE mmap()
on a writable, unsealed file delivers a fatal-by-default SIGXFSZ even
though mmap() returns 0.  If SIGXFSZ is caught or ignored,
hugetlb_reserve_pages() still reserves private huge pages for the full
range up to len without growing inode->i_size, and faulting those pages
later fails with VM_FAULT_SIGBUS in hugetlb_no_page() because vmf->pgoff
is past i_size.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119192209.2651562-1-dmnk@google.com?part=1


      parent reply	other threads:[~2026-11-20 19:22 UTC|newest]

Thread overview: 4+ 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)
2026-11-20 19:22 ` sashiko-bot [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=sashiko-outbox-225922@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=dmnk+artist@google.com \
    --cc=dmnk@google.com \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.