[PATCH v2 14/35] hugetlbfs: fix integer overflow when punching holes

From: David Hildenbrand (Arm)

Date: Thu Dec 03 2026 - 06:41:37 EST


hugetlbfs_punch_hole() rounds up the offset to find the first full huge
page in the hole, and zeroes the partial huge page before it, starting at
the offset.

However, if the offset falls into the last possible huge page below
LLONG_MAX, but not at its start, rounding up overflows and hole_start
becomes LLONG_MIN.

Consequently, we will zero from the start of that huge page, not from the
offset.

Reproduced by allocating that huge page with fallocate(), placing data in
it through udmabuf, and punching a hole starting inside it: the data
before the hole gets zeroed.

Let's fix it by clamping hole_start to offset + len on overflow, as
there are no full huge pages in the hole in that case.

This has low urgency: hugetlbfs supports neither write() nor mmap() of
that last huge page, so only something like udmabuf could place data
there, which no reasonable use case does. No need to CC stable.

Fixes: 68d32527d340 ("hugetlbfs: zero partial pages during fallocate hole punch")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
fs/hugetlbfs/inode.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 4a92f31c88e1a..8ac8925d7ad8b 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -672,8 +672,12 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)

/*
* hole_start and hole_end indicate the full pages within the hole.
+ * If rounding up overflows, there are no full pages in the hole.
*/
- hole_start = round_up(offset, hpage_size);
+ if (check_add_overflow(offset, hpage_size - 1, &hole_start))
+ hole_start = offset + len;
+ else
+ hole_start = round_down(hole_start, hpage_size);
hole_end = round_down(offset + len, hpage_size);

inode_lock(inode);

--
2.56.1