From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221407; b=052sjj6f+5vdSO3blHXG3QlL+2CWbmUCdd4K7hgTAiS4najYjqULsYhkROsnJPkcumIw FzeF3E4MR9ocn6Q+FOEYIt0FA+1kPWDxyMPFzZQGLc2FyWoPNBe++/ZLm0cIEEqqoPTdU EEYvQLf2+3XoRtA716ufJw7E97EnHQ47Hn6oYpcoPoSFv7HS8UxZWr6fXCP5s2mFr0EJj PvuHqYz7vVSLuWBvn83aVQwMHgcD+6Ivm6txLaFptBkTrLFNU2Gr83XZny+Gc853tHwj4 Aw4jqSg1sDNo5HEz/WhNRNoI/ReCKqWXjczNrEt+LQjSUtQ40tzxN4hm/bsaWaIXfmA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221407; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=MThAAYlLjOPUkeA1d+0uIeBr7sEP9u+I1iY7ZI/dKQA=; b=BeoRwLDkKM8SUXnIbpZ7cegRgc2CrkPMhEeG0VLWkkkb4Jxej+vSZBBL+yhUd5UlG54P O/wTB0e6ETRrFrP1hXM+ync9Q7X6ZP4UmrXvVLegE5LUvJDnZ+vxxbe4eHLR3sJ8TYuJ6 d8RTDcSARO2dSs8ChUPN3KAY9McuhUsSHT/N3nobem/dfHS56iEFhCNsehb0+kNzXlyfr f19CgZgbXYQ5rY6TwEQiipgfCNA+uUpv50ktbLIwnKwe1fb/3nMgJRbx4ydcJJ+cWndHD nFos+ioIN+rpT9LGsqrCkGLhcrJCmmTrZ3NOk8LBynmPnH2LKsfLm89peMIUD6msCBw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wB5qKbIB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDFCD606A322 for ; Wed, 2 Dec 2026 14:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wB5qKbIB Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFE7D1F000C1; Wed, 2 Dec 2026 14:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221407; bh=MThAAYlLjOPUkeA1d+0uIeBr7sEP9u+I1iY7ZI/dKQA=; h=Subject:To:Cc:From:Date; b=wB5qKbIBUmjHsO8o0R7DfeujYYGpy0JOdnHjgeoPu7eqjfhv5nLBiqfS6UbZjCT6q ADoY/M225ZASoRzKb+lsi9DLAVEgB7ieQ8nO9+GalwEw1NqR1x3brn8xb0Hfb7E+WW W3CGX/N7l6w/yFGzcjl36fEhA5FHZPDE+JhrGHqc= Subject: FAILED: patch "[PATCH] userfaultfd: validate the whole range before changing write" failed to apply to 6.18-stable tree To: umangpokhriyall@gmail.com,akpm@linux-foundation.org,david@kernel.org,liam@infradead.org,ljs@kernel.org,mhocko@suse.com,peterx@redhat.com,rppt@kernel.org,stable@vger.kernel.org,surenb@google.com,vbabka@kernel.org Cc: From: Date: Wed, 02 Dec 2026 14:45:58 +0100 Message-ID: <2026120258-corrosive-quail-beba@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.18-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 . 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.18.y git checkout FETCH_HEAD git cherry-pick -x 28ae0385b638f095109d282b927ac1a51f75c530 # git commit -s git send-email --to '' --in-reply-to '2026120258-corrosive-quail-beba@gregkh' --subject-prefix 'PATCH 6.18.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 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 Signed-off-by: Andrew Morton Reviewed-by: Mike Rapoport (Microsoft) Cc: Peter Xu Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Suren Baghdasaryan Cc: Michal Hocko Cc: 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);