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=1796386115; b=QcrwfTpXcK73SUwzlbfuUY2w2CzbwXlsYaCUeOp1AkCkyWYvbDkqM/gWKA5NGo6prdUu QvYMDmaoHlw3XcLZWh9HZTQgXoUVsi98OF5D407ka3kCcWzq9J0CXur7A1IDGItQonQF/ sHULSaa02EggByzKZwOEiCWiOjIShW31ir65eP4NHO6dM+09Xw2nOfo3hVcqw3paN5yqA wD1LxpfxgMDrhFLqY2uw6gikunc6AJ+QNbKLEdjBUty6kzlZIr2TZ3vXxRAsZAOfOy9Tl sV88jNkOmsZYcGgBDD7Lsz6HGMknRiXbpIkCrbjPNK6KVI5m08Bty9fS7/zw9LzBgrQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386115; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=xT6eM2puUAf133IZXiclCsk7E3kkN21dVfjbOieRZ4g=; b=Qn30ZtzHAexYyDgvLtKs1LgxR9OzFIZeqPeVBE6LRGmawfZE2sxuyxObdyNQuwxMxqOZ H1+FHksiRtWHtd7S8nocwR+ls8IImytmazsaRx4+NnQqD5bNgaADuj4L0xFlrKDwfHQUD FP8syKnFh/chMHQkB0Gmw2K3Y4vnMo+coptrtuNBNztrcDCfK9r6wgOcrYxnk3aRIWuxo RQGQ638l8AQ/KraInoOr37PZJmSgVk42miiJaYajKTJchRxHwWDC//qcLWM4y/GcCOxLD dlUjspF5qqqVXMEb8iscdIELEPb1OzfEb3YRcEaJJpKonLJ0Tg3T749TcOldhQ4MCtw== 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=jku+EXhC; 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 B0438606A322; Fri, 4 Dec 2026 12:08:35 +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=jku+EXhC Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CE931F000C2; Fri, 4 Dec 2026 12:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386115; bh=xT6eM2puUAf133IZXiclCsk7E3kkN21dVfjbOieRZ4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jku+EXhCOaWcv8ovbKBDsj7hXkDBFHMjN8tcjtrxXkdt2p76Y2Kdwtu/pkDZ+b5TU pW9JKauoSshLNUmKig77FYcPJAH7BSbSS+7iLcILUYKNVbIGLKOKkGY803S67gK2SL ChOpwDwcoh9ExLAG6NQEX69HTLSzVHatlbHlGNAQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pu Lehui , Lorenzo Stoakes , David Hildenbrand , Jann Horn , Liam Howlett , "Masami Hiramatsu (Google)" , Oleg Nesterov , Peter Zijlstra , Vlastimil Babka , Andrew Morton , Dickson Wu , Sasha Levin Subject: [PATCH 6.6 0834/1167] mm: fix uprobe pte be overwritten when expanding vma Date: Fri, 4 Dec 2026 19:04:21 +0900 Message-ID: <20261204100723.848776357@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pu Lehui commit 2b12d06c37fd3a394376f42f026a7478d826ed63 upstream. Patch series "Fix uprobe pte be overwritten when expanding vma". This patch (of 4): We encountered a BUG alert triggered by Syzkaller as follows: BUG: Bad rss-counter state mm:00000000b4a60fca type:MM_ANONPAGES val:1 And we can reproduce it with the following steps: 1. register uprobe on file at zero offset 2. mmap the file at zero offset: addr1 = mmap(NULL, 2 * 4096, PROT_NONE, MAP_PRIVATE, fd, 0); 3. mremap part of vma1 to new vma2: addr2 = mremap(addr1, 4096, 2 * 4096, MREMAP_MAYMOVE); 4. mremap back to orig addr1: mremap(addr2, 4096, 4096, MREMAP_MAYMOVE | MREMAP_FIXED, addr1); In step 3, the vma1 range [addr1, addr1 + 4096] will be remap to new vma2 with range [addr2, addr2 + 8192], and remap uprobe anon page from the vma1 to vma2, then unmap the vma1 range [addr1, addr1 + 4096]. In step 4, the vma2 range [addr2, addr2 + 4096] will be remap back to the addr range [addr1, addr1 + 4096]. Since the addr range [addr1 + 4096, addr1 + 8192] still maps the file, it will take vma_merge_new_range to expand the range, and then do uprobe_mmap in vma_complete. Since the merged vma pgoff is also zero offset, it will install uprobe anon page to the merged vma. However, the upcomming move_page_tables step, which use set_pte_at to remap the vma2 uprobe pte to the merged vma, will overwrite the newly uprobe pte in the merged vma, and lead that pte to be orphan. Since the uprobe pte will be remapped to the merged vma, we can remove the unnecessary uprobe_mmap upon merged vma. This problem was first found in linux-6.6.y and also exists in the community syzkaller: https://lore.kernel.org/all/000000000000ada39605a5e71711@google.com/T/ Link: https://lkml.kernel.org/r/20250529155650.4017699-1-pulehui@huaweicloud.com Link: https://lkml.kernel.org/r/20250529155650.4017699-2-pulehui@huaweicloud.com Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints") Signed-off-by: Pu Lehui Suggested-by: Lorenzo Stoakes Reviewed-by: Lorenzo Stoakes Acked-by: David Hildenbrand Cc: Jann Horn Cc: Liam Howlett Cc: "Masami Hiramatsu (Google)" Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Vlastimil Babka Cc: stable@vger.kernel.org Signed-off-by: Andrew Morton [ adapted to 6.6.y: pass skip_vma_uprobe via an internal __vma_merge() ] Signed-off-by: Dickson Wu Signed-off-by: Sasha Levin --- mm/internal.h | 2 ++ mm/mmap.c | 35 ++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 851a9f53da50d..e2ec067fc3369 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1249,6 +1249,8 @@ struct vma_prepare { struct vm_area_struct *insert; struct vm_area_struct *remove; struct vm_area_struct *remove2; + + bool skip_vma_uprobe :1; }; /* pagewalk.c */ diff --git a/mm/mmap.c b/mm/mmap.c index d1cabe718b63f..c50f16c85419f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -542,10 +542,13 @@ static inline void vma_complete(struct vma_prepare *vp, if (vp->file) { i_mmap_unlock_write(vp->mapping); - uprobe_mmap(vp->vma); - if (vp->adj_next) - uprobe_mmap(vp->adj_next); + if (!vp->skip_vma_uprobe) { + uprobe_mmap(vp->vma); + + if (vp->adj_next) + uprobe_mmap(vp->adj_next); + } } if (vp->remove) { @@ -860,13 +863,13 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, * **** is not represented - it will be merged and the vma containing the * area is returned, or the function will return NULL */ -struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, +static struct vm_area_struct *__vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, struct vm_area_struct *prev, unsigned long addr, unsigned long end, unsigned long vm_flags, struct anon_vma *anon_vma, struct file *file, pgoff_t pgoff, struct mempolicy *policy, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) + struct anon_vma_name *anon_name, bool skip_vma_uprobe) { struct vm_area_struct *curr, *next, *res; struct vm_area_struct *vma, *adjust, *remove, *remove2; @@ -1010,6 +1013,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, goto prealloc_fail; init_multi_vma_prep(&vp, vma, adjust, remove, remove2); + vp.skip_vma_uprobe = skip_vma_uprobe; VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && vp.anon_vma != adjust->anon_vma); @@ -1046,6 +1050,18 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, return NULL; } +struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, + struct vm_area_struct *prev, unsigned long addr, + unsigned long end, unsigned long vm_flags, + struct anon_vma *anon_vma, struct file *file, + pgoff_t pgoff, struct mempolicy *policy, + struct vm_userfaultfd_ctx vm_userfaultfd_ctx, + struct anon_vma_name *anon_name) +{ + return __vma_merge(vmi, mm, prev, addr, end, vm_flags, anon_vma, file, + pgoff, policy, vm_userfaultfd_ctx, anon_name, false); +} + /* * Rough compatibility check to quickly see if it's even worth looking * at sharing an anon_vma. @@ -3431,10 +3447,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, /* If not registered for remap, uffd context will be cleared. */ new_vma = NULL; else - new_vma = vma_merge(&vmi, mm, prev, addr, addr + len, - vma->vm_flags, vma->anon_vma, vma->vm_file, - pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); + new_vma = __vma_merge(&vmi, mm, prev, addr, addr + len, + vma->vm_flags, vma->anon_vma, vma->vm_file, + pgoff, vma_policy(vma), + vma->vm_userfaultfd_ctx, anon_vma_name(vma), + vma->vm_file != NULL); if (new_vma) { /* * Source vma may have been merged into new_vma -- 2.53.0