Re: [PATCH 3/3] mm/memory: don't upgrade non-present PTEs in insert_page_into_pte_locked()
From: David Hildenbrand (Arm)
Date: Wed Nov 18 2026 - 05:05:26 EST
On 11/17/26 16:58, Mike Rapoport (Microsoft) wrote:
> On a write fault insert_page_into_pte_locked() assumes that a non-empty PTE
> maps a page, compares its PFN with the page being inserted and upgrades
> the PTE to writable.
>
> Since guard regions are allowed in file-backed mappings,
> MADV_GUARD_INSTALL can put a guard marker into a PTE of a DAX mapping
> after the DAX fault handler found that PTE empty and before it inserts
> the page.
>
> vmf_insert_page_mkwrite() then extracts a PFN from the marker, hits the
> WARN_ON_ONCE() and fails the fault with SIGBUS instead of the SIGSEGV
> expected on access to a guard region:
>
> WARNING: mm/memory.c:2489 at insert_page_into_pte_locked+0x47e/0x490, CPU#3: guard-race/157
> RIP: 0010:insert_page_into_pte_locked+0x47e/0x490
> Call Trace:
> <TASK>
> insert_page+0x6f/0xc0
> vmf_insert_page_mkwrite+0x31/0x60
> dax_fault_iter+0x3be/0x5f0
> dax_iomap_pte_fault+0x1b8/0x390
> ext4_dax_huge_fault+0x1a4/0x2f0
> __do_fault+0x34/0xc0
> do_fault+0x179/0x610
> __handle_mm_fault+0x8ca/0x1250
> handle_mm_fault+0xb4/0x290
> do_user_addr_fault+0x15f/0x730
> exc_page_fault+0x83/0x190
> asm_exc_page_fault+0x26/0x30
>
> Return -EBUSY for non-present PTEs on write faults like it's done for read
> faults, so that the fault is retried and handle_pte_marker() deals with
> the marker.
>
> Fixes: f807123d578d ("mm: allow guard regions in file-backed and read-only mappings")
>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
> ---
> mm/memory.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 66ad58429967..a80925c61706 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2474,7 +2474,7 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte,
> return 0;
> }
>
> - if (!mkwrite)
> + if (!mkwrite || !pte_present(pteval))
> return -EBUSY;
>
> /*
>
Should we CC stable?
Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
I'll pick this up.
--
Cheers,
David