From: Chris Mason 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: Signed-off-by: Chris Mason [ david: cleanup code and description ] Signed-off-by: David Hildenbrand (Arm) --- mm/hugetlb.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f46c85fc0cd0b..d57964914e18a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6568,11 +6568,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