hugetlbfs_fallocate() allocates folios through a pseudo VMA that starts at address 0 and file offset 0. It passes the file offset of the folio as the address. The reservation code then derives the reserve map index of the folio from that address. Confusing. However, on 32-bit, that address overflows for file offsets at or above 4 GiB, while we still add the folio to the page cache at the real index. Consequently, fallocate() of a single hugetlb folio at offset 4 GiB consumes or restores the reservation at index 0, messing up the reservation accounting on truncation and eviction. Let's fix it by setting the file offset of the folio in the pseudo VMA instead, and passing address 0. This has low urgency, as it only affects 32-bit kernels with hugetlb. No need to CC stable. Fixes: 70c3547e36f5 ("hugetlbfs: add hugetlbfs_fallocate()") Reported-by: Sashiko Signed-off-by: David Hildenbrand (Arm) --- fs/hugetlbfs/inode.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 4290e88f23c5b..81c5a3efdc4dc 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -727,7 +727,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, struct hstate *h = hstate_inode(inode); struct vm_area_struct pseudo_vma; struct mm_struct *mm = current->mm; - loff_t hpage_size = huge_page_size(h); unsigned long hpage_shift = huge_page_shift(h); pgoff_t start, index, end; int error; @@ -774,10 +773,11 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, for (index = start; index < end; index++) { /* * This is supposed to be the vaddr where the page is being - * faulted in, but we have no vaddr here. + * faulted in, but we have no vaddr here. Let the pseudo VMA + * map the folio at address 0 to avoid overflows. */ + const unsigned long addr = 0; struct folio *folio; - unsigned long addr; cond_resched(); @@ -790,8 +790,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, break; } - /* addr is the offset within the file (zero based) */ - addr = index * hpage_size; + pseudo_vma.vm_pgoff = index << huge_page_order(h); /* mutex taken here, fault path and hole punch */ hash = hugetlb_fault_mutex_hash(mapping, index); -- 2.56.1