Re: [PATCH v2] userfaultfd: validate the whole range before changing write protection
From: Mike Rapoport
Date: Wed Nov 04 2026 - 10:03:50 EST
On Wed, Nov 04, 2026 at 03:04:57PM +0530, Umang Pokhriyal wrote:
> mwriteprotect_range() checks each VMA as it walks the range. When a later
> VMA is not registered for write protection, or is a hugetlb VMA the range
> is not aligned to, the call fails after the earlier VMAs were already
> changed. When unprotecting, userfaultfd_writeprotect() then skips
> wake_userfault(), so threads blocked on those pages are not woken although
> the pages are writable again.
>
> An unprivileged process can trigger this with a range that spans an
> unregistered VMA. It hasn't been seen in practice; it was found while
> reviewing the userfaultfd range ioctls with an LLM.
>
> Validate the whole range first, as mrwprotect_range() already does.
>
> Fixes: a1b92a3f1498 ("mm/userfaultfd: support WP on multiple VMAs")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Umang Pokhriyal <umangpokhriyall@xxxxxxxxx>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
> ---
> v2:
> - drop the redundant error assignments in the validation loop (Mike)
> - drop the selftest (Mike)
>
> v1: https://lore.kernel.org/all/20261102103621.156928-1-umangpokhriyall@xxxxxxxxx/
>
> mm/userfaultfd.c | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
--
Sincerely yours,
Mike.