Re: [PATCH 02/21] mm/hugetlb: fix truncated copy result in UFFDIO_COPY

From: Oscar Salvador (SUSE)

Date: Thu Nov 26 2026 - 04:57:12 EST


On Wed, Nov 25, 2026 at 11:33:00PM +0100, David Hildenbrand (Arm) wrote:
> 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 ]
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

Reviewed-by: Oscar Salvador (SUSE) <osalvador@xxxxxxxxxx>



--
Oscar Salvador
SUSE Labs