[PATCH v2 11/15] hugetlbfs: do not grow a sealed file in mmap()
From: David Hildenbrand (Arm)
Date: Mon Nov 16 2026 - 13:31:34 EST
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 ]
Acked-by: Muchun Song <muchun.song@xxxxxxxxx>
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
fs/hugetlbfs/inode.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 7f64bdc07aa80..68761e1ed4d2e 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -157,7 +157,8 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
goto out;
ret = 0;
- if (vma_test(vma, VMA_WRITE_BIT) && inode->i_size < len)
+ if (vma_test(vma, VMA_WRITE_BIT) && inode->i_size < len &&
+ !(HUGETLBFS_I(inode)->seals & F_SEAL_GROW))
i_size_write(inode, len);
out:
inode_unlock(inode);
--
2.56.1