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) --- fs/hugetlbfs/inode.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 81c5a3efdc4dc..9b2c61339f830 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -363,15 +363,12 @@ static unsigned long vma_offset_start(struct vm_area_struct *vma, pgoff_t start) static unsigned long vma_offset_end(struct vm_area_struct *vma, pgoff_t end) { - unsigned long t_end; + const pgoff_t nr_pages = end - vma->vm_pgoff; - if (!end) + if (!end || nr_pages >= vma_pages(vma)) return vma->vm_end; - t_end = ((end - vma->vm_pgoff) << PAGE_SHIFT) + vma->vm_start; - if (t_end > vma->vm_end) - t_end = vma->vm_end; - return t_end; + return vma->vm_start + (nr_pages << PAGE_SHIFT); } /* -- 2.56.1