Re: [PATCH 11/15] hugetlbfs: do not grow a sealed file in mmap()

From: Gregory Price (Meta)

Date: Fri Nov 13 2026 - 16:52:39 EST


On 2026-10-28 21:13 +0100, David Hildenbrand (Arm) wrote:
> From: Chris Mason <mason@xxxxxxxxxx>
>
> hugetlbfs_file_mmap() grows a file when a writable mapping extends beyond
> EOF. We are missing seal checks similar to hugetlbfs_setattr() and
> hugetlbfs_fallocate(), allowing a user to grow a file that has F_SEAL_GROW
> set.
>
> To fix it, skip the resize when F_SEAL_GROW is set; mmap() still succeeds
> without growing the file.
>
> 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.
>
> Fix generated by an LLM and sent by Chris Mason in private.
>
> Fixes: ff62a3421044 ("hugetlb: implement memfd sealing")
> Cc: stable@xxxxxxxxxx
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> [ david: drop comment; simplify+extend description ]
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

Reproduced by growing a sealed memfd length from 0 to 2MB.
With the patch, we stay at length 0.

Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>

--
~Gregory