Re: [PATCH v2 2/2] mm/memory: store the PFN of CoW PFNMAP mappings in the anon page offset
From: YinFengwei
Date: Fri Dec 04 2026 - 01:04:12 EST
On Thu, Dec 03, 2026 at 01:33:25PM +0100, David Hildenbrand (Arm) wrote:
> 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 VMAs not managed by
> core mm, which includes any PFNMAP mappings.
>
> This has medium urgency. Do not CC stable, as backports would be tricky
> either way and not worth it.
>
> Fixes: 8be71e1ba093 ("selinux: mark status and policy inodes as immutable, drop status mmap write checks")
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Reviewed-by: Yin Fengwei <fengwei_yin@xxxxxxxxxxxxxxxxx>
Regards
Yin, Fengwei