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=1796301222; b=tI+IUFgPG86o3ivTcrCn/M6WnQGHiopb9BfOWbsStg5Fghy2v7KeyfAxmNeWAwappcAs DBezxw/bn1E9mkdlr+AUlBoQ3omatzG1WGiIrvqNAkQ17Cm/CAN4oi0BNEnQRnyEtbufx auZLpLvek8r6Mr4jAVcPUaur1HnWILtesinGFdl9mWS+GTyXRi9JYsrNmUKRZmsCSzild DvylpblgcsOG5+Umj9jD6/305vXc0LnF+cfXiw4Rhw6EqXF9ndeWS4MUuFpE5Id+tDJ+z 8izK5TALkfFjQ9bSrQYkyBZF99HI9TtrzPTxjywZc7XMvWTCRvoVgDnbvCQSxx6fRGA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796301222; h=Received:DKIM-Signature:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key; bh=6rXaJdNc2Gn1PIpi/28z2sUpycJUQ8TV7uArlqLAWjk=; b=aYF7eqOr/0LCcXwg6Tuv6UMDjadWW+vA89WqEFfIJ6p1File9flxFRE/LL5W3AcnSdFJ y0FHq+MwnEZWlZmhox2Mr09reJSFIEwyt6UXOLZyjWJow/KSFKrUCXWgg+eKiKG4q8CKa UePhMNNb2ga/pH0/yOX662V4DTo0BUj3jm5yGiAjqHapKbp2GxTELhoyDCgKy/J1baZKa XDK9nZVwGaOo4+XypsN/rXZbQdgv3raRPPpMTNjYU09iByUK9zcAjy/e7d8+p1Itf2eI6 LcQWII4pW1hPQbk4J1Zk4UXXPu7SfTIYAntp5yMEXpjQhLQbgDO2g52xZ9ZhN5sM55A== 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=H2Ovq8jx; 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 F2410606A32F; Thu, 3 Dec 2026 12:33:41 +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=H2Ovq8jx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B5D01F000C1; Thu, 3 Dec 2026 12:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796301221; bh=6rXaJdNc2Gn1PIpi/28z2sUpycJUQ8TV7uArlqLAWjk=; h=From:Subject:Date:To:Cc; b=H2Ovq8jx5S6bc2X2v+9BHnqzDhPF6dfgzSvfavnWtCb6s2VnKvBeI4MzePFGNIIQd e7kvCFf94z5kVW3BK2VyLgz4KxkhAv251HmzeE5DGShiM+ylcs6XTBwNkPvHVGjRqK IUfrvXs59jjYpmOMlxW75R69ihmHCoD0YBRxXKjYC3Tz5xE3zjMTq4lTwWZtNeyk9T msdVC7bWS+LhkUrCyk6WCpyM/hDc2rWe4iq/KrlzRvaAMpU+0YalatmqEkcsVjnISg EN0tc2i4xGArv6bOnj4C216uBRxVxWajgamzfEInBHpJfK9O7Vhp1p3qRJE5OHzNVw s8k1umpKz9mig== From: "David Hildenbrand (Arm)" Subject: [PATCH v2 0/2] mm: don't leak PFNs of CoW PFNMAP mappings to user space Date: Thu, 03 Dec 2026 13:33:23 +0100 Message-Id: <20261203-cow_pfnmap_pgoff-v2-0-2e06735c100d@kernel.org> 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 X-B4-Tracking: v=1; b=H4sIAAAAAAAA/33Nyw6CMBCF4VdpZm0NHQwCK9/DEILtDNRL27SIG sK7G3Dv8iR/vjNDomgpQS1miDTZZL2DWuBOgB4615O0BmoBmGGhFJZS+1cb2D260IbeM0s0XFS 6VGwyDTsBIRLb90aem99Oz8uV9Lg6azHYNPr42T4ntXZ/+EnJTHYmP+Y5VhXj4XSj6Oi+97GHZ lmWL5MY1YTDAAAA X-Change-ID: 20261128-cow_pfnmap_pgoff-2df69c81fd0c 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=2548; i=david@kernel.org; h=from:subject:message-id; bh=bWvceL/4/HtrwUrIBUZ4+CLySuGksXaySzNT/ryAMHM=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLIFE6ct3WbFs7jVbGLYwg+9kbLLlJ5bG8yeyS33dc40F 7VtPTZzOkpZGMQ4GGTFFFmCgu8bvHy5rrbajY8ZZg4rE8gQBi5OAZhIryUjQ5utmNn2O/+k1a+f ObUnwKvzr1HBh0NsGcHGjzsOnxM+/5vhv4fuxEuWU95nLHFKD/wRf5LxyO0mvoZJS5gfMFUoyu5 05QAA X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A 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. I 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. I'll route this through my tree, likely after the next merge window. --- Changes in v2: - Collected tag (thanks!). - "mm/memory: store the PFN of CoW PFNMAP mappings in the anon page offset" - Use vma_is_mm_managed() instead of vma_can_merge() in copy_vma(). - Add vma_set_cow_pfnmap_pfn() and vma_cow_pfnmap_pfn(). - Drop "unmergeable VMAs" comment from the vma_start_anon_pgoff() doc. - Adjust comments and the patch description. - Link to v1: https://patch.msgid.link/20261128-cow_pfnmap_pgoff-v1-0-ad3733299f24@kernel.org --- David Hildenbrand (Arm) (2): uprobes: skip mappings not managed by core mm mm/memory: store the PFN of CoW PFNMAP mappings in the anon page offset fs/cramfs/inode.c | 7 +--- include/linux/mm.h | 9 +++-- kernel/events/uprobes.c | 30 ++++++++++----- mm/memory.c | 81 +++++++++++++++++++++++++---------------- mm/vma.c | 6 +-- mm/vma.h | 3 +- tools/testing/vma/include/dup.h | 3 +- 7 files changed, 83 insertions(+), 56 deletions(-) --- base-commit: c5941b1abeffba401f7f9cbc8c4f0c5da75dcba5 change-id: 20261128-cow_pfnmap_pgoff-2df69c81fd0c Best regards, -- David Hildenbrand (Arm)