Re: [PATCH 18/32] mm: consistently check MMF_UNSTABLE when populating in CoW mappings
From: Jose A. Perez de Azpillaga
Date: Sun Nov 29 2026 - 15:58:39 EST
On 11/29/26 11:06 AM, David Hildenbrand (Arm) wrote:
> The OOM reaper and process_mrelease() zap private mappings of a target
> MM, including CoW'ed anonymous folios. Re-populating these page table
> entries is bad: it will look like a memory corruption to anybody still
> accessing the MM. For example, a read fault could map a pagecache folio
> where the process previously mapped a CoW'ed anon folio.
>
> We must consistently disallow populating page table entries in CoW
> mappings if MMF_UNSTABLE is set, and we must check under the page table
> lock.
>
> We are still missing checks when populating empty page table entries
> in CoW mappings in:
> - filemap_map_pages() (fault-around)
> - do_set_pmd() (fault-around, MADV_COLLAPSE)
> - the vmf_insert_*() helpers (fs DAX, drivers)
> - UFFDIO_COPY, UFFDIO_ZEROPAGE, UFFDIO_CONTINUE and UFFDIO_MOVE
>
> Let's fix it by adding these checks. To avoid duplicating code, add
> vma_may_populate_pgtable() and document it properly. Also extend the
> documentation of check_stable_address_space().
>
> Also fix the check in finish_fault(), which must really happen under the
> page table lock to handle races with the OOM reaping correctly.
>
> After reaping, populating page table entries in CoW mappings now
> consistently fails (e.g., with SIGBUS or -EFAULT).
>
> At some point we should probably consistently just use
> vma_may_populate_pgtable() when populating; also, we can think about
> checking for the existence of an anon_vma instead of checking for CoW
> mappings. We should also make __oom_reap_task_mm() check for
> vma_is_cow_mapping() instead.
>
> This has low urgency, as the target MM is about to go away anyway. No
> need to CC stable.
>
> Fixes: aac453635549 ("mm, oom: introduce oom reaper")
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
LGTM:
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>
--
cheers,
jose a. p-a