All of lore.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] userfaultfd: validate the whole range before changing write" failed to apply to 6.6-stable tree
@ 2026-12-02 13:45 gregkh
  2026-12-04  5:04 ` [PATCH 6.6.y] userfaultfd: validate the whole range before changing write protection Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: gregkh @ 2026-12-02 13:45 UTC (permalink / raw)
  To: umangpokhriyall, akpm, david, liam, ljs, mhocko, peterx, rppt,
	stable, surenb, vbabka
  Cc: stable


The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 28ae0385b638f095109d282b927ac1a51f75c530
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120259-spry-moonlit-022f@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 28ae0385b638f095109d282b927ac1a51f75c530 Mon Sep 17 00:00:00 2001
From: Umang Pokhriyal <umangpokhriyall@gmail.com>
Date: Wed, 4 Nov 2026 15:04:57 +0530
Subject: [PATCH] userfaultfd: validate the whole range before changing write
 protection

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.

Link: https://lore.kernel.org/20261104093457.152245-1-umangpokhriyall@gmail.com
Fixes: a1b92a3f1498 ("mm/userfaultfd: support WP on multiple VMAs")
Signed-off-by: Umang Pokhriyal <umangpokhriyall@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: <stable@vger.kernel.org>

diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index a50dd8b3971e..08fcc9d01746 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -1105,21 +1105,26 @@ static int mwriteprotect_range(struct userfaultfd_ctx *ctx, unsigned long start,
 	if (atomic_read(&ctx->mmap_changing))
 		goto out_unlock;
 
+	/*
+	 * Validate every spanned VMA before changing any of them, so an
+	 * invalid range is rejected without changing part of it.
+	 */
 	err = -ENOENT;
 	for_each_vma_range(vmi, dst_vma, end) {
-
-		if (!userfaultfd_wp(dst_vma)) {
-			err = -ENOENT;
-			break;
-		}
+		if (!userfaultfd_wp(dst_vma))
+			goto out_unlock;
 
 		if (vma_is_hugetlb(dst_vma)) {
-			err = -EINVAL;
 			page_mask = vma_kernel_pagesize(dst_vma) - 1;
-			if ((start & page_mask) || (len & page_mask))
-				break;
+			if ((start & page_mask) || (len & page_mask)) {
+				err = -EINVAL;
+				goto out_unlock;
+			}
 		}
+	}
 
+	vma_iter_set(&vmi, start);
+	for_each_vma_range(vmi, dst_vma, end) {
 		_start = max(dst_vma->vm_start, start);
 		_end = min(dst_vma->vm_end, end);
 


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 6.6.y] userfaultfd: validate the whole range before changing write protection
  2026-12-02 13:45 FAILED: patch "[PATCH] userfaultfd: validate the whole range before changing write" failed to apply to 6.6-stable tree gregkh
@ 2026-12-04  5:04 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-12-04  5:04 UTC (permalink / raw)
  To: stable
  Cc: Umang Pokhriyal, Andrew Morton, Mike Rapoport (Microsoft),
	Peter Xu, David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett,
	Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, Sasha Levin

From: Umang Pokhriyal <umangpokhriyall@gmail.com>

[ Upstream commit 28ae0385b638f095109d282b927ac1a51f75c530 ]

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.

Link: https://lore.kernel.org/20261104093457.152245-1-umangpokhriyall@gmail.com
Fixes: a1b92a3f1498 ("mm/userfaultfd: support WP on multiple VMAs")
Signed-off-by: Umang Pokhriyal <umangpokhriyall@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: <stable@vger.kernel.org>
[ sashal: adapted the hugetlb check to use is_vm_hugetlb_page() and the mmap_changing pointer check in the older mwriteprotect_range() signature. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 mm/userfaultfd.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 99438f0950e3c..0a5c1dc97f62a 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -862,21 +862,26 @@ int mwriteprotect_range(struct mm_struct *dst_mm, unsigned long start,
 	if (mmap_changing && atomic_read(mmap_changing))
 		goto out_unlock;
 
+	/*
+	 * Validate every spanned VMA before changing any of them, so an
+	 * invalid range is rejected without changing part of it.
+	 */
 	err = -ENOENT;
 	for_each_vma_range(vmi, dst_vma, end) {
-
-		if (!userfaultfd_wp(dst_vma)) {
-			err = -ENOENT;
-			break;
-		}
+		if (!userfaultfd_wp(dst_vma))
+			goto out_unlock;
 
 		if (is_vm_hugetlb_page(dst_vma)) {
-			err = -EINVAL;
 			page_mask = vma_kernel_pagesize(dst_vma) - 1;
-			if ((start & page_mask) || (len & page_mask))
-				break;
+			if ((start & page_mask) || (len & page_mask)) {
+				err = -EINVAL;
+				goto out_unlock;
+			}
 		}
+	}
 
+	vma_iter_set(&vmi, start);
+	for_each_vma_range(vmi, dst_vma, end) {
 		_start = max(dst_vma->vm_start, start);
 		_end = min(dst_vma->vm_end, end);
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  5:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:45 FAILED: patch "[PATCH] userfaultfd: validate the whole range before changing write" failed to apply to 6.6-stable tree gregkh
2026-12-04  5:04 ` [PATCH 6.6.y] userfaultfd: validate the whole range before changing write protection Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.