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=1796221410; b=I5bMyfUBgaoD1hHhNx2Na18yrit2ey/Rz32KszJpxueHoXC+MoUzCPVS1DS9EUbD398F jcIWiXlg4GFH8Qkmvnp1syn/ONGrENGi17Xr04y/Svo+pJvbcpuMDQP9unjwyQJ1JF/Rb GXpYh7H7gpp0400zZGjVxyLsaSZQ2XkB5e59JtNtffsoML5XWrzNIfo8F1F44ExcAXHCh VBbfDRyMIXZY3R0C+3obUM5/LT9aImbvPtIhFFCMVMSRtQu0KyIBfSZjc78jv/44JgYFv QdEWU/RWSXuYnYxOpQNqvteksARfzWhGG94HALS8VXZXhsArLKY5VD4satiDif2MWAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221410; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=nqruE3kbqZ061aQ73H3yqWZmsQcdcAZBh6TquTG60HQ=; b=lV0BlRLRYCuLuidj0eT7HMgLL4/JVTN0VXCaqCebQQKooGpzLIQYLTyCdJWJ8IP1kwGH hQwwCnHFspBaQYUoWn8ki27OQan7z3puKde19zWIMBTadm+umpeMBO6kJgDyAnKQjsByB ve83pDP3BtcVq4Y9mDca9i8ZPOqj0pQkzzM4R9GxpbOrMwBOp/QyR0EBwCuVG8FHn6tbI oTgIYMN7WpRWnCV0/S1hlxMblUzIp8gVE9t/8rogaldvya7v5fA4bYD3Tzu45WAoEd8FF xq0wqKRMyAZZIf4qFya4kCWjGJft9ly0GzWovAWYohDXZW9U+5+mGw88MI7PIvqbwVg== 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=MZdgeBQL; 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 C5095606A31A for ; Wed, 2 Dec 2026 14:23:30 +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=MZdgeBQL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F21B1F000C1; Wed, 2 Dec 2026 14:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221410; bh=nqruE3kbqZ061aQ73H3yqWZmsQcdcAZBh6TquTG60HQ=; h=Subject:To:Cc:From:Date; b=MZdgeBQL62wyQCw2ftepoyRPnueX87VfvzksS3BzyK3uRyNIpDeDWlarsS7eEZFPb 0O1lIlcJBdC6ktBsNlDMwTbOMGybeKBgpq0R36C69YSK7CR03tUpuU2WYRaxuquYhX 4D8p0+A9HcIQfU/CG8vYaAe6yHjNpXFhNC/suGCg= Subject: FAILED: patch "[PATCH] userfaultfd: validate the whole range before changing write" failed to apply to 6.6-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:59 +0100 Message-ID: <2026120259-spry-moonlit-022f@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.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 . 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 # git commit -s git send-email --to '' --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 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);