Re: [PATCH 02/21] mm/hugetlb: fix truncated copy result in UFFDIO_COPY
From: Muchun Song
Date: Wed Nov 25 2026 - 21:03:33 EST
> On Nov 26, 2026, at 06:33, David Hildenbrand (Arm) <david@xxxxxxxxxx> 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: Muchun Song (ByteDance) <muchun.song@xxxxxxxxx>