[PATCH v3 20/47] mm/gup: fix clearing folios in memfd_pin_folios()

Lance Yang lance.yang at linux.dev
Mon Nov 2 03:22:27 PST 2026


On Sat, Oct 31, 2026 at 10:39:49AM +0100, David Hildenbrand (Arm) wrote:
>From: Chris Mason <mason at kernel.org>
>
>memfd_pin_folios() pins folios obtained directly from the page cache
>without checking whether they are uptodate. However, shmem fallocate()
>can leave newly allocated folios uncleared and not uptodate. Callers
>such as udmabuf can then expose uninitialized memory to userspace.

Right, just make sure the folios are initialized before handing them to
callers. They shouldn't have to care whether shmem deferred the clearing ;)

>Clear non-uptodate folios and mark them uptodate under the folio lock
>before returning them to the caller.
>
>Fix generated by an LLM and sent by Chris Mason in private.
>
>Fixes: 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios")
>Cc: stable at vger.kernel.org
>Signed-off-by: Chris Mason <mason at kernel.org>
>[ david: simplify description and comment ]
>Reviewed-by: Pratyush Yadav (Google) <pratyush at kernel.org>
>Reviewed-by: Samiullah Khawaja <skhawaja at google.com>
>Tested-by: Samiullah Khawaja <skhawaja at google.com>
>Tested-by: Muhammad Usama Anjum <usama.anjum at arm.com>
>Signed-off-by: David Hildenbrand (Arm) <david at kernel.org>
>---

LGTM!

Reviewed-by: Lance Yang <lance.yang at linux.dev>



More information about the kexec mailing list