Re: [PATCH v2 18/35] hugetlbfs: don't overflow the end of the unmap range on 32-bit
From: Andrew Morton
Date: Fri Dec 04 2026 - 02:13:23 EST
On Fri, 4 Dec 2026 14:44:20 +0800 Muchun Song <muchun.song@xxxxxxxxx> wrote:
>
>
> > On Dec 3, 2026, at 19:37, David Hildenbrand (Arm) <david@xxxxxxxxxx> wrote:
> >
> > When truncating a file or punching a hole, hugetlb_vmdelete_list() uses
> > vma_offset_end() to translate the end of the range in the file to an
> > address in the VMA, limited to the end of the VMA.
> >
> > However, the end of the range can lie far beyond the end of the VMA, and
> > on 32-bit, calculating the address can overflow before we limit it.
> >
> > Consequently, we might unmap only part of the VMA, or nothing at all. For
> > example, when punching a hole covering the first 4.5 GiB of a file that
> > is mapped by a 1 GiB VMA, we only unmap the first 512 MiB of that VMA.
> > hugetlb_unmap_file_folio() later unmaps the page cache folios, but
> > anonymous folios in private mappings, and for example poison markers,
> > stay in the hole.
> >
> > Let's fix it by checking whether the range ends beyond the VMA before
> > calculating the address, which also simplifies the code.
> >
> > This has low urgency, as it requires 32-bit and punching a hole that
> > extends 4 GiB or more past the start of a mapping. No need to CC stable.
> >
> > Fixes: 1bfad99ab425 ("hugetlbfs: hugetlb_vmtruncate_list() needs to take a range to delete")
> > Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> With Sashiko's comment resolved:
This?
--- a/fs/hugetlbfs/inode.c~hugetlbfs-dont-overflow-the-end-of-the-unmap-range-on-32-bit-fix
+++ a/fs/hugetlbfs/inode.c
@@ -346,10 +346,10 @@ static bool hugetlb_vma_maps_pfn(struct
}
/*
- * Can vma_offset_start/vma_offset_end overflow on 32-bit arches?
- * No, because the interval tree returns us only those vmas
- * which overlap the truncated area starting at pgoff,
- * and no vma on a 32-bit arch can span beyond the 4GB.
+ * The interval tree returns only VMAs that overlap the range starting at
+ * start, so vma_offset_start() stays within the VMA on 32-bit.
+ * The end can lie far beyond the VMA. vma_offset_end() must check the
+ * page offset before converting it to an address.
*/
static unsigned long vma_offset_start(struct vm_area_struct *vma, pgoff_t start)
{
_