Re: [PATCH] mm/mprotect: don't skip uffd marker install when racing with PTE table reclaim

From: David Hildenbrand (Arm)

Date: Thu Nov 19 2026 - 11:46:57 EST


On 11/19/26 15:24, Lorenzo Stoakes (ARM) wrote:
> On Sat, Nov 07, 2026 at 12:28:55AM +0100, David Hildenbrand (Arm) wrote:
>> change_pmd_range() populates PTE tables before installing uffd-wp
>> markers. An empty PTE table can be removed after change_pmd_prepare()
>> returns but before the pmd_none() check.
>
> These *** wp markers man :)

Tell me about it ...

>
>>
>> That check then skips the range, allowing UFFDIO_WRITEPROTECT to report
>> success without installing the required markers. Subsequent writes by
>> userspace to these areas will not trigger uffd events.
>>
>> PTE table reclaim during MADV_DONTNEED and page table retraction during
>> khugepaged can trigger this.
>>
>> Retry page-table allocation in that case. Simplify the code, getting
>> rid of change_pmd_prepare() by routing all code through the "again" label.
>>
>> It's a small race though, so likely this is not very urgent.
>>
>> Fixes: fe2567eb5521 ("mm/shmem: allow uffd wr-protect none pte for file-backed mem")
>> Fixes: 6375e95f381e ("mm: pgtable: reclaim empty PTE page in madvise(MADV_DONTNEED)")
>> Cc: stable@xxxxxxxxxxxxxxx
>> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> LGTM, so:
>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>

Thanks

--
Cheers,

David