[PATCH v2 12/35] mm/hugetlb: fix truncated copy result in UFFDIO_COPY
From: David Hildenbrand (Arm)
Date: Thu Dec 03 2026 - 06:41:20 EST
From: Chris Mason <mason@xxxxxxxxxx>
Folios that span more bytes than can fit into an unsigned integer (e.g.,
16 GiB folios on arm64) are problematic with UFFDIO_COPY: the result
from copy_folio_from_user() can be truncated, possibly indicating
success instead of an error.
We will then continue with the folio that has stale data, and make it
accessible to user space.
For example, if copy_folio_from_user() fails such that the number of
bytes not copied is a multiple of 4 GiB, we'll get an effective ret ==
0.
Let's fix it by simply testing the return value directly.
This has medium urgency, as it's an information leak.
Fixes: 8fb5debc5fcd ("userfaultfd: hugetlbfs: add hugetlb_mcopy_atomic_pte for userfaultfd support")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
[ david: cleanup code and description ]
Reviewed-by: Muchun Song (ByteDance) <muchun.song@xxxxxxxxx>
Reviewed-by: Oscar Salvador (SUSE) <osalvador@xxxxxxxxxx>
Reviewed-by: Hongfu Li <lihongfu@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
mm/hugetlb.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index d7ced61b4d2d4..0d242ebfb07d2 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6606,11 +6606,8 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
goto out;
}
- ret = copy_folio_from_user(folio, (const void __user *) src_addr,
- false);
-
/* fallback to copy_from_user outside mmap_lock */
- if (unlikely(ret)) {
+ if (unlikely(copy_folio_from_user(folio, (const void __user *)src_addr, false))) {
ret = -ENOENT;
/* Free the allocated folio which may have
* consumed a reservation.
--
2.56.1