Re: [PATCH] userfaultfd: preserve write protection across UFFDIO_MOVE

From: Andrew Morton

Date: Sun Apr 12 2026 - 14:18:37 EST


On Thu, 9 Apr 2026 11:28:22 -0400 Gregory Price <gourry@xxxxxxxxxx> wrote:

> move_present_ptes() unconditionally makes the destination PTE writable,
> dropping uffd-wp write-protection from the source PTE.
>
> The original intent was to follow mremap() behavior, but mremap()'s
> move_ptes() preserves the source write state unconditionally.
>
> Modify uffd to preserve the source write state and check the uffd-wp
> condition of the source before setting writable on the destination.

Please can we have a description of the userspace-visible impact of the
bug.

> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> Cc: stable@xxxxxxxxxxxxxxx

especially when cc:stable, thanks.

> Signed-off-by: Gregory Price <gourry@xxxxxxxxxx>
>
> ...
>
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -1123,7 +1123,10 @@ static long move_present_ptes(struct mm_struct *mm,
> orig_dst_pte = pte_mksoft_dirty(orig_dst_pte);
> if (pte_dirty(orig_src_pte))
> orig_dst_pte = pte_mkdirty(orig_dst_pte);
> - orig_dst_pte = pte_mkwrite(orig_dst_pte, dst_vma);
> + if (pte_write(orig_src_pte))
> + orig_dst_pte = pte_mkwrite(orig_dst_pte, dst_vma);
> + if (pte_uffd_wp(orig_src_pte))
> + orig_dst_pte = pte_mkuffd_wp(orig_dst_pte);
> set_pte_at(mm, dst_addr, dst_pte, orig_dst_pte);
>

(presently wondering if this is backward compatible)