[PATCH 0/2] userfaultfd: validate the whole range before changing write protection
From: Umang Pokhriyal
Date: Mon Nov 02 2026 - 05:41:16 EST
A UFFDIO_WRITEPROTECT range that spans an unregistered VMA fails, but
the VMAs before it are already (un)protected, and on unprotect no waiter
is woken. Patch 1 validates the whole range first, as
mrwprotect_range() does; it is open-coded rather than shared with it so
that it applies to stable kernels without RWP. Patch 2 adds a uffd
selftest.
The problem was found while reviewing the userfaultfd range ioctls with
an LLM, which also helped write the patches. Tested on mm-new in a VM:
the new selftest and a standalone reproducer (both directions, and a
misaligned hugetlb range) fail without patch 1 and pass with it, and the
rest of uffd-unit-tests gives the same results with and without it.
Umang Pokhriyal (2):
userfaultfd: validate the whole range before changing write protection
selftests/mm: test a uffd write-protect range with an unregistered
page
mm/userfaultfd.c | 20 +++++--
tools/testing/selftests/mm/uffd-unit-tests.c | 56 ++++++++++++++++++++
2 files changed, 71 insertions(+), 5 deletions(-)
base-commit: d42dfde37af766d1c272467352c0a56d3169ee58
--
2.53.0