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=1796155313; b=nKyjsOV6/xvuIyE+kC3FFRtC70XO1yFnxjb1vMOFk5920h7lnFfuvbKXgMz4EYHAsaJ8 3mnduYrbZBltpD0H/SyWx/X3PKwYDsfgqqok/AYxXCDo2rhCaWphSuQuI8l0PFR/fPgsV UfPY5zK5/XUnXw+duU2QSYck28AAormcCwSmngWUlt1lhW6ycsoc3flrPBbQs/gqqUSap yPIo9CmbRPwzoZKR3KccuoWoLeV4QWI3c7SmU99FLh9lWiI4abm0gheIrbwziPKh7GlZC yKeeUXe1Cn0RykaIyE5MN029kfPTRYmTLNfSi2sAL5G0PvJbJ690ovXrvlsWTj82JFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796155313; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=hdEVrK0irnikd4rsbWr0VQ62LPzk0o87IbQM3G3yeoE=; b=uLaSVYJFL/uhBCLhvuKXe+G/GwgVmsgxj+fnDCdarWorT7lUBFkSbgCKLrX3wsGJI12V IhkpxixTGtH912bcCcR+A6jQ0Jn/jk7PPYEWwsxFv+pymhmlpgU8wpImD5YWtaEpcHexv lXCCJ5kjeSa98ZSwWb6xUWnth7SdlIsmyAGCFTki/+XL7lINCCn/Vr+YdaJZYD9hsdAE5 3ZxNjHPzbmgRBGRuUeMN1rRgSr5S8PbtVldU2GIMmlD6CI2CAhQaVJZ89AXrtm2x06rG2 PuGgdes4NDWwGBc79+DzrCPfduq22v35dBv1RILZ1v+/n4mjm8jGP13LMNF3dBakoNw== 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=1yVElObl; 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 266A4606A31A for ; Tue, 1 Dec 2026 20:01:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=1yVElObl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 812891F000C1; Tue, 1 Dec 2026 20:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796155312; bh=hdEVrK0irnikd4rsbWr0VQ62LPzk0o87IbQM3G3yeoE=; h=Date:To:From:In-Reply-To:References:Subject; b=1yVElOblfv4SXX3ZuXJeMHCRg+5qcczL85isR2af0z0VkSvnVRxwNiUZbgAiEJ9hA pGier0+1PGy3A81iK08pFRaVsURFFQgXHbZPZ1+ExUWiBFqs7zTQ5EFgzILxX1p+Wf jKsALJRawIvklv5NvMy8R8Fr/xDVcTUXGic8XaJY= Date: Tue, 01 Dec 2026 12:01:52 -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-2-ad3733299f24@kernel.org> References: <20261128-cow_pfnmap_pgoff-v1-2-ad3733299f24@kernel.org> Subject: [-] mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset.patch removed from -mm tree Message-Id: <20261201200152.812891F000C1@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 quilt patch titled Subject: mm/memory: store the PFN of CoW PFNMAP mappings in the anon page offset has been removed from the -mm tree. Its filename was mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset.patch This patch was dropped because David is taking it ------------------------------------------------------ From: "David Hildenbrand (Arm)" Subject: mm/memory: store the PFN of CoW PFNMAP mappings in the anon page offset Date: Sat, 28 Nov 2026 23:15:11 +0100 remap_pfn_range() and its mmap_prepare variant overwrite vm_pgoff with the first PFN of the range in CoW mappings, such that __vm_normal_page() can reliably identify CoW'ed anon folios without arch support for pte_special. However, vm_pgoff is also exposed to user space as the file offset, through /proc/pid/maps, /proc/pid/smaps, PROCMAP_QUERY, PERF_RECORD_MMAP and the NT_FILE note of core dumps, whereas /proc/pid/pagemap only reports PFNs to CAP_SYS_ADMIN. Consequently, such mappings can leak physical addresses to user space. In particular, since commit 8be71e1ba093 ("selinux: mark status and policy inodes as immutable, drop status mmap write checks"), a MAP_PRIVATE mapping of /sys/fs/selinux/status can leak PFNs that way. We don't want to expose the PFNs of mapped pages to user space. Now that we have the anon page offset per VMA, let's fix it by storing the PFN in there instead. That value is never exported to user space. We already handle the anon page offset properly during VMA splits etc. Only copy_vma() must be taught to not reset it for unmergeable VMAs, which includes any PFNMAP mappings. This has medium urgency. Do not CC stable, as backports would be tricky either way and not worth it. Link: https://patch.msgid.link/20261128-cow_pfnmap_pgoff-v1-2-ad3733299f24@kernel.org Fixes: 8be71e1ba093 ("selinux: mark status and policy inodes as immutable, drop status mmap write checks") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Reported-by: Chris Mason 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: Oleg Nesterov Cc: Andrii Nakryiko 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 fs/cramfs/inode.c | 7 --- include/linux/mm.h | 10 +++-- mm/memory.c | 55 ++++++++++++++---------------- mm/vma.c | 6 +-- mm/vma.h | 3 - tools/testing/vma/include/dup.h | 3 + 6 files changed, 41 insertions(+), 43 deletions(-) --- a/fs/cramfs/inode.c~mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset +++ a/fs/cramfs/inode.c @@ -402,12 +402,7 @@ static int cramfs_physmem_mmap(struct fi } if (pages == vma_pages(vma)) { - /* - * The entire vma is mappable. remap_pfn_range() will - * make it distinguishable from a non-direct mapping - * in /proc//maps by substituting the file offset - * with the actual physical address. - */ + /* The entire vma is mappable. */ ret = remap_pfn_range(vma, vma->vm_start, address >> PAGE_SHIFT, pages * PAGE_SIZE, vma->vm_page_prot); } else { --- a/include/linux/mm.h~mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset +++ a/include/linux/mm.h @@ -1766,7 +1766,8 @@ static inline bool vma_flags_can_merge(c * mapping not embodied in any attribute of the VMA. * * Additionally, private (CoW) PFN maps encode the source PFN of the - * range in vma->vm_pgoff, which may otherwise cause spurious merges. + * range in the anonymous page offset, which may otherwise cause + * spurious merges. */ if (!vma_flags_is_mm_backed(flags)) return false; @@ -4625,8 +4626,7 @@ static inline unsigned long vma_pages(co * If @vma is a MAP_PRIVATE file-backed mapping, then this returns the * page offset within the file. * - * Edge cases: nommu does not abide by these and CoW MAP_PRIVATE-pfnmap regions - * have their page offset set to the first PFN in the range. + * Edge cases: nommu does not abide by these. * * Returns: The page offset of the start of @vma. */ @@ -4680,6 +4680,10 @@ static inline pgoff_t vma_last_pgoff(con * This value is used for tracking MAP_PRIVATE file-backed mappings by their * anonymous page offset. * + * Edge cases: unmergeable VMAs keep their anonymous page offset when moved + * while unfaulted, and CoW MAP_PRIVATE-pfnmap regions have it set to the + * first PFN in the range. + * * Returns: The anonymous page offset of the start of @vma. */ static inline pgoff_t vma_start_anon_pgoff(const struct vm_area_struct *vma) --- a/mm/memory.c~mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset +++ a/mm/memory.c @@ -687,10 +687,11 @@ static void print_bad_pte(struct vm_area * * The way we recognize COWed pages within VM_PFNMAP mappings is through the * rules set up by "remap_pfn_range()": the vma will have the VM_PFNMAP bit - * set, and the vm_pgoff will point to the first PFN mapped: thus every special - * mapping will always honor the rule + * set, and the anonymous page offset will point to the first PFN mapped: thus + * every special mapping will always honor the rule * - * pfn_of_page == vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT) + * pfn_of_page == vma_start_anon_pgoff(vma) + + * ((addr - vma->vm_start) >> PAGE_SHIFT) * * And for normal mappings this is false. * @@ -745,13 +746,11 @@ static inline struct page *__vm_normal_p if (!pfn_valid(pfn)) return NULL; } else { - const pgoff_t index = linear_page_index(vma, addr); - /* Only CoW'ed anon folios are "normal". */ - if (pfn == index) - return NULL; if (!vma_is_cow_mapping(vma)) return NULL; + if (pfn == linear_anon_page_index(vma, addr)) + return NULL; } } @@ -3217,22 +3216,17 @@ static inline int remap_p4d_range(struct return 0; } -static int get_remap_pgoff(bool is_cow, unsigned long addr, - unsigned long end, unsigned long vm_start, unsigned long vm_end, - unsigned long pfn, pgoff_t *vm_pgoff_p) +static int check_cow_pfnmap_range(unsigned long addr, unsigned long end, + unsigned long vm_start, unsigned long vm_end) { /* * There's a horrible special case to handle copy-on-write * behaviour that some programs depend on. We mark the "original" - * un-COW'ed pages by matching them up with "vma->vm_pgoff". - * See vm_normal_page() for details. + * un-COW'ed pages by matching them up with the anonymous page + * offset. See vm_normal_page() for details. */ - if (is_cow) { - if (addr != vm_start || end != vm_end) - return -EINVAL; - *vm_pgoff_p = pfn; - } - + if (addr != vm_start || end != vm_end) + return -EINVAL; return 0; } @@ -3370,17 +3364,18 @@ int remap_pfn_range_prepare(struct vm_ar const struct mmap_action *action = &desc->action; const unsigned long start = action->remap.start; const unsigned long end = start + action->remap.size; - const unsigned long pfn = action->remap.start_pfn; const bool is_cow = vma_desc_is_cow_mapping(desc); int err; if (!range_in_vma_desc(desc, start, end)) return -EFAULT; - err = get_remap_pgoff(is_cow, start, end, desc->start, desc->end, pfn, - &desc->pgoff); - if (err) - return err; + if (is_cow) { + err = check_cow_pfnmap_range(start, end, desc->start, + desc->end); + if (err) + return err; + } vma_desc_set_flags_mask(desc, VMA_REMAP_FLAGS); return 0; @@ -3394,11 +3389,13 @@ static int remap_pfn_range_prepare_vma(s const bool is_cow = vma_is_cow_mapping(vma); int err; - err = get_remap_pgoff(is_cow, addr, end, vma->vm_start, vma->vm_end, - pfn, &vma->vm_pgoff); - if (err) - return err; - + if (is_cow) { + err = check_cow_pfnmap_range(addr, end, vma->vm_start, + vma->vm_end); + if (err) + return err; + vma_set_anon_pgoff(vma, pfn); + } vma_set_flags_mask(vma, VMA_REMAP_FLAGS); return 0; } @@ -3436,6 +3433,8 @@ int remap_pfn_range_complete(struct vm_a const unsigned long size = action->remap.size; const pgprot_t prot = action->remap.pgprot; + if (vma_is_cow_mapping(vma)) + vma_set_anon_pgoff(vma, pfn); return do_remap_pfn_range(vma, start, pfn, size, prot); } --- a/mm/vma.c~mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset +++ a/mm/vma.c @@ -2006,10 +2006,10 @@ struct vm_area_struct *copy_vma(struct v VMG_VMA_STATE(vmg, &vmi, NULL, vma, addr, addr + len); /* - * If a vma has not yet been faulted, update its anonymous pgoff to - * match the new location to increase its chance of merging. + * If a vma has not yet been faulted and can merge, update its anonymous + * pgoff to match the new location to increase its chance of merging. */ - if (!vma_has_anon_rmap(vma)) { + if (!vma_has_anon_rmap(vma) && vma_can_merge(vma)) { anon_pgoff = addr >> PAGE_SHIFT; if (vma_is_anonymous(vma)) { --- a/mm/vma.h~mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset +++ a/mm/vma.h @@ -290,8 +290,7 @@ static inline void assert_sane_pgoff(str return; /* * File-backed VMAs have arbitrary page offset (either page offset into - * file or for pfnmap the PFN of the start of the range or drivers may - * set arbitrary page offset). + * file or drivers may set arbitrary page offset). */ if (!vma_is_anonymous(vma)) return; --- a/tools/testing/vma/include/dup.h~mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset +++ a/tools/testing/vma/include/dup.h @@ -1741,7 +1741,8 @@ static inline bool vma_flags_can_merge(c * mapping not embodied in any attribute of the VMA. * * Additionally, private (CoW) PFN maps encode the source PFN of the - * range in vma->vm_pgoff, which may otherwise cause spurious merges. + * range in the anonymous page offset, which may otherwise cause + * spurious merges. */ if (!vma_flags_is_mm_backed(flags)) return false; _ Patches currently in -mm which might be from david@kernel.org are mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch 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-hugetlb-always-mark-new-page-cache-folios-migratable.patch mm-memfd-mark-new-hugetlb-folios-migratable.patch mm-hugetlb-free-surplus-folios-of-other-nodes-on-free.patch hugetlbfs-dont-zero-poisoned-pages-in-a-hole-punch.patch mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch mm-migrate-check-hugetlb-pmd-sharing-in-move_pages.patch mm-hugetlb-dont-share-page-tables-of-a-vma-during-mprotect.patch mm-hugetlb-count-migration-entries-at-fork-and-unmap.patch mm-hugetlb-stop-accounting-hugetlbpages-once-pmd-tables-were-shared.patch fs-proc-task_mmu-dont-clear-vm_softdirty-on-hugetlb-vmas.patch rfc-mm-hugetlb_cgroup-charge-faults-to-mm-owner.patch mm-filemap-avoid-retrying-faults-on-uffd-wp-markers.patch