Skip to contentSkip to conversation

mm-filemap-stop-fault-around-when-the-walk-steps-back.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Nov 10 Stable branch

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/filemap: stop fault-around when the walk steps back
has been removed from the -mm tree. Its filename was
mm-filemap-stop-fault-around-when-the-walk-steps-back.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: "Jose Fernandez (Anthropic)" <[email protected]>
Subject: mm/filemap: stop fault-around when the walk steps back
Date: Sat, 31 Oct 2026 04:33:59 +0000

filemap_map_pages() can dereference a PTE pointer outside the page table it locked. KASAN has reported this as a use-after-free read [1]. The same path can also write out of bounds. When the stray entry reads as none, the fault-around loop maps a page there with set_pte_range().

Its fault-around loop walks the page cache and moves vmf->pte by the change in index. A lower index moves it back. xas_find() can step back to a lower index when a multi-index entry is split during the walk.

[1] fixes xas_find(), but the loop still relies on the walk never stepping back. Stop the fault-around when the walk steps back. ->fault() maps the faulting page if the loop did not.

---

 mm/filemap.c |    7 +++++++
 1 file changed, 7 insertions(+)
mm/filemap.c renamed from mm/filemap.c~mm-filemap-stop-fault-around-when-the-walk-steps-back +7 -0
@@ -3968,6 +3968,13 @@ vm_fault_t filemap_map_pages(struct vm_f
 		unsigned long end;
 		vm_fault_t map_ret;
 
+		/* A lower index could move vmf->pte out of its page table. */
+		if (unlikely(xas.xa_index < last_pgoff)) {
+			folio_unlock(folio);
+			folio_put(folio);
+			break;
+		}
+
 		addr += (xas.xa_index - last_pgoff) << PAGE_SHIFT;
 		vmf->pte += xas.xa_index - last_pgoff;
 		last_pgoff = xas.xa_index;

_

Patches currently in -mm which might be from [email protected] are