mm-memory-constrain-generic_access_phys-to-page-boundary.patch removed from -mm tree
The quilt patch titled
Subject: mm/memory: constrain generic_access_phys() to page boundary
has been removed from the -mm tree. Its filename was
mm-memory-constrain-generic_access_phys-to-page-boundary.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Luxiao Xu <[email protected]>
Subject: mm/memory: constrain generic_access_phys() to page boundary
Date: Thu, 10 Sep 2026 11:42:50 +0800
This patch addresses an issue in generic_access_phys() where accessing memory across page boundaries in PFNMAP VMAs assumes physical pages are contiguous, which can lead to accessing unintended physical memory or exceeding VMA boundaries.
generic_access_phys() improperly validates the memory access range: it only validates the start address using follow_pfnmap_start() and passes PAGE_ALIGN(len + offset) to ioremap_prot().
This poses two problems:
1. In PFNMAP VMAs, consecutive virtual pages are not guaranteed to be physically contiguous, and individual PTEs may have different access permissions or writability.
2. The mapping may cross VMA boundaries if len extends beyond vma->vm_end.
Constrain the access in generic_access_phys() to at most the current page boundary (PAGE_SIZE - offset) and map only a single PAGE_SIZE via ioremap_prot(). Since the caller __access_remote_vm() already loops over the requested length and handles partial transfers, it will naturally iterate over the remaining pages.
Also add a missing (resource_size_t) cast during PFN re-validation to avoid truncation on 32-bit PAE systems.
---
mm/memory.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/memory.c renamed from mm/memory.c~mm-memory-constrain-generic_access_phys-to-page-boundary +8 -2
@@ -7131,6 +7131,12 @@ int generic_access_phys(struct vm_area_sbool writable;struct follow_pfnmap_args args = { .vma = vma, .address = addr }; +/* +* Limit access to one page at a time, as that's what follow_pfnmap_start() +* guarantees; expect the caller to retry to read larger ranges. +*/ + len =min_t (int, len,PAGE_SIZE - offset); + retry:if (follow_pfnmap_start (&args))return -EINVAL ;
@@ -7142,7 +7148,7 @@ retry:if ((write &FOLL_WRITE ) && !writable)return -EINVAL ; - maddr =ioremap_prot (phys_addr,PAGE_ALIGN (len + offset), prot); + maddr =ioremap_prot (phys_addr,PAGE_SIZE , prot);if (!maddr)return -ENOMEM ;
@@ -7150,7 +7156,7 @@ retry: goto out_unmap;if ((pgprot_val (prot) !=pgprot_val (args.pgprot)) || - (phys_addr != (args.pfn <<PAGE_SHIFT )) || + (phys_addr != ((resource_size_t )args.pfn <<PAGE_SHIFT )) || (writable != args.writable)) {follow_pfnmap_end (&args);iounmap (maddr);
_
Patches currently in -mm which might be from [email protected] are