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=1796301231; b=0CCUa0zQjwclizeTGeemzgmHCkX26tXFCoVRyS7QjV93UTuf9dqvVlJehvWbF453ao4C e3IvP9arOANW3sTBG6ey67fdJNoZgu7ysFQA1rS/I2UAyl1j6KoIJmZANx0h1vx16IsVV x4ZZ3a6st6tTlNHOBGPYGb3a0aYZYs/2FDjybgxarY2DNz0gUX8+wVe7d/QKIV8/otMRz 8e5c6jJzTWjZJ7PONAjmH2Gnn3bTJCYYvqwRV0e7qfc/7p9GcpnTSa7Wn3IDGhY0vXnGs I7apwC2qYUHFOSHqX9eDKkBGepEPrfqmwOqSnQkg7QHnR1KJ1wJSkZQH7KspqC2Y7Zg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796301231; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=4EDuP5Ubb8sbjtgu2o8grImwRwWqCJdky5DdYbQrD0U=; b=Xk1FJUZPxRpnubNPX3JzwN/Ccz3Rv7ZeMzSI8rZjkiV45ux4RCixvNbG7WicYwSUP0Ys VQUmHzMAC6Ep8ARUNsKL/tK/S5SlHA8zg+XFHsvSXjDTgghbtdOZNsQcf4NILSGu30bHK RPrmI39MNncRaISuLkelgaGhFAL+A+evKo19yZo48sTjzIwH8ya0XyEBL1G1C8cUuKcPq SmpJyirjkP4lta1RME2vt59dhGcmjkyX3d3EAw7KBxGCpKwMt5KHorAGCmn0Nql5vfgMt e4caz2EleXk36sMt0PnANW9l5Q0IQoHCHr3N4Yo3N0rNkTZ21DODGpU92E7VV0ddHZw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e5eD4gmw; 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 914B2606A32F; Thu, 3 Dec 2026 12:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e5eD4gmw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E0E81F00898; Thu, 3 Dec 2026 12:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796301231; bh=4EDuP5Ubb8sbjtgu2o8grImwRwWqCJdky5DdYbQrD0U=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=e5eD4gmw1qAAxoiFh2oXl7+Rn20/M4fpUIVIXI+x0ze7Tm6aJSfid0OJ2uWNBH75L FsBdh3iV1n0H04QGs34MXb7cGRrZbouJlRy6crrVYOPnJYX7klV6KMNJUblszyWQmA IrweSgivq3bNboi8tmUmVoJSMbiYy/+J2PKP2DtViAzfGN5/96ENS8VeTJCywVIbVA LRACKwK6isuF79d+XMSkCHf141maFqkQz/g2EQc64+R6gL1o9FZj24CoEoKa6tG+so U4w/d7iHHeezdmNo1VHuVsIgzj5BUS5rhyV57KogV6rVT2KnMtL6ED9reBnbK52Xzw /15uRKFA1d6gQ== From: "David Hildenbrand (Arm)" Date: Thu, 03 Dec 2026 13:33:24 +0100 Subject: [PATCH v2 1/2] uprobes: skip mappings not managed by core mm X-Mailing-List: linux-trace-kernel@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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-cow_pfnmap_pgoff-v2-1-2e06735c100d@kernel.org> References: <20261203-cow_pfnmap_pgoff-v2-0-2e06735c100d@kernel.org> In-Reply-To: <20261203-cow_pfnmap_pgoff-v2-0-2e06735c100d@kernel.org> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Masami Hiramatsu , Oleg Nesterov , Andrii Nakryiko , Nicolas Pitre , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Andrew Morton , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Jan Kara , Stephen Smalley , Paul Moore Cc: Chris Mason , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-mm@kvack.org, selinux@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4948; i=david@kernel.org; h=from:subject:message-id; bh=Vin2xEev290LaxSpHODCLd4xAB9rrJOiLup722908FI=; b=kA0DAAgWx+nLGEVVu3kByyZiAGsRYZyh8WAU7z1MUb8gwsOY6El3AIlTP31NZux96ZbB/VFAt Yh1BAAWCAAdFiEEUlPfMOnprn17Rg4Dx+nLGEVVu3kFAmsRYZwACgkQx+nLGEVVu3lfIgEAnWrM nGhNPEmN74bxDLjZp6oQ/QiEpyikfHYBJ1oolnkA/A4DDOyTeiU2BtixgRRyDFZgyLu8Bs/nL3O AiJfIwGgF X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A Uprobe writes breakpoints and updates the reference counters of SDT markers through GUP, which refuses VM_IO and VM_PFNMAP mappings, and which cannot access the parts of VM_MIXEDMAP mappings that are not backed by "struct page". However, valid_vma() and valid_ref_ctr_vma() never excluded such mappings. For example, cramfs XIP file mappings use either remap_pfn_range() or VM_MIXEDMAP mappings. For such file mappings, enabling a uprobe fails with -EFAULT, and disabling a uprobe that was enabled before such a mapping appeared fails with -EFAULT as well, leaking the uprobe. Further, since commit 83e3dc9a5d4d ("uprobes: simplify find_active_uprobe_rcu() VMA checks"), the uprobe lookups no longer check the VMA flags, assuming that a trap instruction in a VMA implies that we installed a breakpoint there. But we never install breakpoints into some VMAs, such as MAP_SHARED mappings. If the file itself contains a trap instruction at the offset of a uprobe, executing it in such a VMA will find the uprobe, and instead of delivering SIGTRAP, we let the task loop on that trap instruction forever. Let's fix it by only considering VMAs managed by core mm, using vma_is_mm_managed(). Move the existing VMA flag checks in valid_vma() into a new helper valid_vma_flags(), and call vma_is_mm_managed() from there. Then, check valid_vma() also in find_active_uprobe_rcu(), and valid_vma_flags() in find_active_uprobe_speculative(), essentially reverting 83e3dc9a5d4d. In valid_ref_ctr_vma(), only call vma_is_mm_managed(): using valid_vma_flags() would be wrong as we don't need exec permissions. vma_is_mm_managed() refuses VM_PFNMAP and VM_MIXEDMAP mappings, which covers VM_IO mappings as well for anything we would probe. For example, remap_pfn_range() sets VM_IO together with VM_PFNMAP. This has low urgency and is likely not stable-worthy. Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints") Fixes: 83e3dc9a5d4d ("uprobes: simplify find_active_uprobe_rcu() VMA checks") Cc: Andrii Nakryiko Cc: Oleg Nesterov Reported-by: Chris Mason Acked-by: Masami Hiramatsu (Google) Signed-off-by: David Hildenbrand (Arm) --- kernel/events/uprobes.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 6015289fd92c6..a6c178f99ea11 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -124,6 +124,22 @@ static void uprobe_warn(struct task_struct *t, const char *msg) pr_warn("uprobe: %s:%d failed to %s\n", t->comm, t->pid, msg); } +static bool valid_vma_flags(struct vm_area_struct *vma, bool is_register) +{ + vma_flags_t forbidden = mk_vma_flags(VMA_HUGETLB_BIT, + VMA_MAYSHARE_BIT); + + /* We can only write breakpoints to mappings managed by core mm. */ + if (!vma_is_mm_managed(vma)) + return false; + + if (is_register) + vma_flags_set(&forbidden, VMA_WRITE_BIT); + + return vma_test(vma, VMA_MAYEXEC_BIT) && + !vma_test_any_mask(vma, forbidden); +} + /* * valid_vma: Verify if the specified vma is an executable vma * Relax restrictions while unregistering: vm_flags might have @@ -134,14 +150,7 @@ static void uprobe_warn(struct task_struct *t, const char *msg) */ static bool valid_vma(struct vm_area_struct *vma, bool is_register) { - vma_flags_t forbidden = mk_vma_flags(VMA_HUGETLB_BIT, - VMA_MAYSHARE_BIT); - - if (is_register) - vma_flags_set(&forbidden, VMA_WRITE_BIT); - - return vma->vm_file && vma_test(vma, VMA_MAYEXEC_BIT) && - !vma_test_any_mask(vma, forbidden); + return vma->vm_file && valid_vma_flags(vma, is_register); } static unsigned long offset_to_vaddr(struct vm_area_struct *vma, loff_t offset) @@ -287,6 +296,7 @@ static bool valid_ref_ctr_vma(struct uprobe *uprobe, return uprobe->ref_ctr_offset && vma->vm_file && + vma_is_mm_managed(vma) && file_inode(vma->vm_file) == uprobe->inode && vma_test(vma, VMA_WRITE_BIT) && !vma_test(vma, VMA_SHARED_BIT) && vma->vm_start <= vaddr && @@ -2449,7 +2459,7 @@ static struct uprobe *find_active_uprobe_speculative(unsigned long bp_vaddr) * that whatever we speculatively found is correct */ vm_file = READ_ONCE(vma->vm_file); - if (!vm_file) + if (!vm_file || !valid_vma_flags(vma, false)) return NULL; offset = (loff_t)(vma_start_pgoff(vma) << PAGE_SHIFT) + @@ -2479,7 +2489,7 @@ static struct uprobe *find_active_uprobe_rcu(unsigned long bp_vaddr, int *is_swb mmap_read_lock(mm); vma = vma_lookup(mm, bp_vaddr); if (vma) { - if (vma->vm_file) { + if (valid_vma(vma, false)) { struct inode *inode = file_inode(vma->vm_file); loff_t offset = vaddr_to_offset(vma, bp_vaddr); -- 2.56.1