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=1795919168; b=SfMB0vQAgSckgxqMyKg4wQZV2AwVX+wEL+yIBUAt/nO8OFX04/fg2ol90gTJExr38xo6 lDZx4sLUT/GGeZtaRsRQCJOy+KgpR+qotNOXxFChTQQGVHBe5kDM+fZxXkwjMLihoF2Fv eRhwZ69Lh55/nlIY5dWnfeR0qpZ57C57kPn9j0r/F3vWmtYIbNZRNZCsINmU7UHPuQ9nR ue1j5OKm0SNga3Jyq19nFLWk6MfjRupLENHaxGl9lXqRXS6gTW0ch9variSAMcD1m0mHe zHDaYjFopJ88jFRaDl4ifl16wpDijm4bLfmNY/vu7vN4YNdnXulgnwELzTdXJUN9QQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795919168; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=AYjhmconBTG8LRNqwotJl2ww73EXkeD7o3ipBsj6n9w=; b=RbPxja2pPD/FL+GQG/Ee1Ay23dmf+mI1pUoCzbK977xkDdZojIm9FlrDCHEEzOJL0gZk qmB/BRMrER42hkK+PlhULXfZWwsecvf+Hpc9W+Mbpw5rtxz1kR/QQ/YKHva3hSog7stpv pNkb/QLPnca7ksi8kMSxJJg5gdZ5XTdV6caYoo7TqIi3PyReVRtB+9yuQbMjXT6xTYrFh RWtFRnJ+WXq08D6Z9gTJbupcIthaVsYihDdW4VRgkE1TaxcfYaiOk888tVZb76EE/PXQu ZOyQSV+U8z4e8ImM2tvZ1k0ROaFps2rPkUH59lg9/s229B6oe6rz70G3UuyKlhmSuSg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=zIEcpoyn; 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 543EB606A31C for ; Sun, 29 Nov 2026 02:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=zIEcpoyn Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7E1D1F000C1; Sun, 29 Nov 2026 02:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1795919168; bh=AYjhmconBTG8LRNqwotJl2ww73EXkeD7o3ipBsj6n9w=; h=Date:To:From:In-Reply-To:References:Subject; b=zIEcpoyn0fPigB+NMsRbQDDRYbweybS4wpuxQKqIyMdqR8zBX8W5AZzDm3ccLj/np /N40BEnWpCTBCwwCxA+cuwMA3N47OjxsdbMAGVfA3Uhgsy+lkh/jvHZEIAvROTVQ1F op9DWVcr6daWnnBRyjp1I8DhEYg/+IENWYAyUL4s= Date: Sat, 28 Nov 2026 18:26:07 -0800 To: mm-commits@vger.kernel.org,vbabka@kernel.org,surenb@google.com, stephen.smalley.work@gmail.com,shakeel.butt@linux.dev,rppt@kernel.org, pfalcato@suse.de,peterz@infradead.org,paul@paul-moore.com,oleg@redhat.com, nico@fluxnic.net,namhyung@kernel.org,mingo@redhat.com,mhocko@suse.com, mhiramat@kernel.org,mason@kernel.org,mark.rutland@arm.com,ljs@kernel.org, liam@infradead.org,jolsa@kernel.org,jannh@google.com,james.clark@linaro.org, jack@suse.cz,irogers@google.com,andrii@kernel.org, alexander.shishkin@linux.intel.com,adrian.hunter@intel.com,acme@kernel.org, david@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261128-cow_pfnmap_pgoff-v1-1-ad3733299f24@kernel.org> References: <20261128-cow_pfnmap_pgoff-v1-1-ad3733299f24@kernel.org> Subject: + uprobes-skip-mappings-not-managed-by-core-mm.patch added to mm-new branch Message-Id: <20261129022607.E7E1D1F000C1@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: uprobes: skip mappings not managed by core mm has been added to the -mm mm-new branch. Its filename is uprobes-skip-mappings-not-managed-by-core-mm.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/uprobes-skip-mappings-not-managed-by-core-mm.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: "David Hildenbrand (Arm)" Subject: uprobes: skip mappings not managed by core mm Date: Sat, 28 Nov 2026 23:15:10 +0100 Patch series "mm: don't leak PFNs of CoW PFNMAP mappings to user space". remap_pfn_range() stores the first PFN of CoW mappings in vm_pgoff, which is exposed to user space as the file offset, for example through /proc/pid/maps. Ever since commit 8be71e1ba093 ("selinux: mark status and policy inodes as immutable, drop status mmap write checks"), this exposes the PFN of the selinux status page to any process. Let's store it in the anon page offset instead. In patch #1, we teach uprobes to skip any mappings not managed by core mm. So far, uprobes only skipped CoW PFNMAP mappings by accident, because the lookup by file offset did not find them. This also fixes existing issues with VM_MIXEDMAP mappings, such as cramfs XIP files. In patch #2, we then stop storing the PFN of CoW PFNMAP mappings in vm_pgoff and instead store it in the anon page offset that Lorenzo introduced recently. In contrast to vm_pgoff, the anon page offset is never exposed to user space. As a side effect, such mappings are now found in the i_mmap tree by their file offset, and cramfs direct mappings no longer report the physical address in /proc/pid/maps. In ran targeted tests (PFN leak, CoW behavior, fork, mremap) on x86-64 and 32bit arm (without LPAE -> no pte_special() support) and selftests on x86-64. This patch (of 2): 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. Link: https://lore.kernel.org/20261128-cow_pfnmap_pgoff-v1-0-ad3733299f24@kernel.org Link: https://patch.msgid.link/20261128-cow_pfnmap_pgoff-v1-1-ad3733299f24@kernel.org Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints") Fixes: 83e3dc9a5d4d ("uprobes: simplify find_active_uprobe_rcu() VMA checks") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Reported-by: Chris Mason Cc: Andrii Nakryiko Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Namhyung Kim Cc: Mark Rutland Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Ian Rogers Cc: Adrian Hunter Cc: James Clark Cc: Masami Hiramatsu Cc: Nicolas Pitre Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Michal Hocko Cc: Lorenzo Stoakes Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato Cc: Jann Horn Cc: Jan Kara Cc: Stephen Smalley Cc: Paul Moore kernel/events/uprobes.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) --- a/kernel/events/uprobes.c~uprobes-skip-mappings-not-managed-by-core-mm +++ a/kernel/events/uprobes.c @@ -124,6 +124,22 @@ static void uprobe_warn(struct task_stru 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_stru */ 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 upr 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 * 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 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); _ Patches currently in -mm which might be from david@kernel.org are mm-mprotect-dont-skip-uffd-marker-install-when-racing-with-pte-table-reclaim.patch mm-userfaultfd-prevent-poison-marker-loss.patch mm-hugetlb-compare-against-persistent-count-when-freeing-lowmem-folios.patch mm-hugetlb-preserve-reservations-when-shrinking-on-highmem.patch mm-hugetlb-account-temporary-folios-separately.patch mm-hugetlb-account-temporary-folios-separately-fix.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation-fix.patch mm-memfd-recheck-the-page-cache-before-allocating-a-hugetlb-folio.patch mm-hugetlb-count-again-if-the-reserve-map-shrank.patch mm-hugetlb-account-restored-reservations-before-freeing-folios.patch mm-hugetlb-delay-anon-folio-rmap-removal-until-after-the-tlb-flush.patch mm-userfaultfd-reject-dax-mappings.patch uprobes-skip-mappings-not-managed-by-core-mm.patch mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset.patch