From: Zi Yan <ziy@nvidia.com>
To: David Hildenbrand <david@kernel.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
Rik van Riel <riel@surriel.com>,
Vlastimil Babka <vbabka@kernel.org>,
Harry Yoo <harry@kernel.org>, Jann Horn <jannh@google.com>,
Kyle Zeng <kylebot@openai.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Zi Yan <ziy@nvidia.com>,
stable@vger.kernel.org, Balbir Singh <balbirs@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Andrew Donnellan <andrew+kernel@donnellan.id.au>,
Rohan McLure <rmclure@linux.ibm.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org, Sashiko <sashiko-bot@kernel.org>,
Jisheng Zhang <jszhang@kernel.org>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>, Zong Li <zong.li@sifive.com>,
Deepak Gupta <debug@rivosinc.com>,
Palmer Dabbelt <palmer@rivosinc.com>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
linux-riscv@lists.infradead.org,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
loongarch@lists.linux.dev,
Alexander Gordeev <agordeev@linux.ibm.com>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
linux-s390@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Andreas Larsson <andreas@gaisler.com>,
sparclinux@vger.kernel.org,
Andrea Arcangeli <aarcange@redhat.com>,
Suren Baghdasaryan <surenb@google.com>,
Jason Gunthorpe <jgg@ziepe.ca>
Subject: [PATCH v2 0/9] Re-enable discarding lazyfree PMD THPs and transient none PMD fixes
Date: Thu, 03 Dec 2026 23:17:48 -0500 [thread overview]
Message-ID: <20261203-anon_vma_uaf_fix-v2-0-3d4c746e8839@nvidia.com> (raw)
Patch 1 can be picked up separately if more work is needed for the rest of
the patches.
For maintainers, Patch 7 and 9 use pmdp_invalidate() in place of PMD
clearing, so they need the arch fixes from Patch 2 to 6. It might be
better to get ack from arch maintainers for Patch 2 to 6 and merge the
series via mm tree.
Motivation
===
A bug was found in the PMD-level discard of lazyfree THPs [1]. The
proposed fix keeps the PMD invalidated with pmdp_invalidate() instead of
clearing it, but that does not work on every architecture:
1. riscv, LoongArch and s390 let GUP-fast follow an invalidated PMD;
2. powerpc/book3s64 page table check counts an invalidated PMD as mapped;
3. sparc64's thp_pte_count becomes unbalanced around pmdp_invalidate().
So the PMD-level discard was disabled instead [2]. This series fixes the
arch code and re-enables it.
The discard decides from the folio refcount, so GUP-fast must not take a
reference through an invalidated PMD, and arch accounting must stay
balanced when an invalidated PMD is set again or cleared.
Details
===
Patch 1 fixes set_pmd_migration_entry() when migrating a device private
folio. set_pmd_migration_entry() clears the device private PMD
unnecessarily and the transient none PMD can be skipped by a concurrent
zap. It can cause lost deposited page table, RSS stats mismatch, or data
loss.
Patches 2-6 fix the arch code, patch 7 from Kyle keeps the PMD invalidated
instead of cleared until the discard is committed, and patch 8 enables the
PMD-level discard again:
2. powerpc/book3s64: page table check counts an invalidated PMD as a live
mapping, so setting it again or clearing it decrements the map count a
second time and hits BUG_ON(). This is already reachable via mprotect(),
and via MADV_COLD before v7.4, with CONFIG_PAGE_TABLE_CHECK.
3. riscv: an invalidated PMD still passes pmd_present() and the generic
pmd_access_permitted(), so GUP-fast follows it. The generic helpers
also let GUP-fast read execute-only entries and write shadow stack
entries. Require _PAGE_PRESENT and _PAGE_READ in
pte_access_permitted() and use it for PMDs and PUDs too. This patch
was posted on its own [3] and has Cc: stable; it is carried here
because the series depends on it.
4. LoongArch: an invalidated PMD passes the generic pmd_access_permitted()
too. Add a pmd_access_permitted() that requires _PAGE_PRESENT.
5. s390: _SEGMENT_ENTRY_INVALID also marks an old PMD, so GUP-fast follows
an invalidated PMD. Always clear _SEGMENT_ENTRY_READ in
pmdp_invalidate(), which makes it pmd_protnone(), so GUP-fast rejects
it.
6. sparc64: pmdp_invalidate() decrements thp_pte_count assuming a THP
split follows, so setting the PMD again loses a count. Move the
decrement to pmd_set(), which THP split uses to replace the huge PMD
with a page table, and initialize the split's on-stack _pmd to none.
7. mm/huge_memory: use pmdp_invalidate() in the discard, so munmap() and
mremap() wait on the PMD lock instead of skipping a none PMD.
8. mm/rmap: discard lazyfree THPs at PMD level again.
Patch 9 fixes a similar transient none PMD issue using pmdp_invalidate() in
UFFDIO_MOVE.
Note
===
1. x86, arm64 and powerpc already make GUP-fast reject an invalidated PMD,
and sparc64 has no GUP-fast. 32-bit MIPS would not reject it, but it
cannot have THP: _PAGE_HUGE makes PFN_PTE_SHIFT exceed PAGE_SHIFT, so
the BUILD_BUG_ON() in arch_mm_preinit() fires, which is why Ingenic
dropped huge pages in commit 69b686ddd579 ("MIPS: ingenic: Remove
CPU_SUPPORTS_HUGEPAGES").
2. A follow-up patch to remove on-stack _pmd in PMD split code can get rid
of the for-sparc64 _pmd initialization code
Link: https://lore.kernel.org/all/20261009165214.40212-2-kylebot@openai.com/ [1]
Link: https://lore.kernel.org/all/20261012-lazyfree-stable-fix-v2-1-6387d6e30063@nvidia.com/ [2]
Link: https://lore.kernel.org/all/20261015-riscv-gup-read-fix-v1-1-8cf7f2504029@nvidia.com/ [3]
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
Changes in v2:
- Patch 1: new. Do not clear a device private PMD in
set_pmd_migration_entry(), since a concurrent zap can skip the
transient none PMD.
- Patch 2: cite riscv commit bdda2887cbf39 instead of its subject; added
Usama's Acked-by.
- Patch 3: replaced "riscv: mm: don't let GUP-fast follow invalidated THP
PMDs" with the standalone "riscv: mm: don't let GUP-fast follow entries
without _PAGE_READ" [3], which also rejects execute-only and shadow
stack entries (Sashiko); added Jisheng's Reviewed-by.
- Patch 4: revised the commit message.
- Patch 5: revised the commit message.
- Patch 6: move the decrement to pmd_set() instead of counting only valid
huge PMDs: _PAGE_VALID is also the referenced bit (_PAGE_R), so v1
dropped old THPs from the count.
- Patch 7: dropped the dependency note.
- Patch 8: call update_hiwater_rss() before the PMD-level discard, as the
PTE path does (Sashiko).
- Patch 9: new. Use pmdp_invalidate() instead of clearing the PMD in
UFFDIO_MOVE.
- Dropped the Assisted-by tags; Claude and Codex were used to analyze the
code and review the patches.
- Link to v1: https://patch.msgid.link/20261015-anon_vma_uaf_fix-v1-0-7b977303b42b@nvidia.com
---
Kyle Zeng (1):
mm/huge_memory: avoid transient none PMDs during lazyfree reclaim
Zi Yan (8):
mm/migrate: do not clear device private entry in set_pmd_migration_entry()
powerpc/book3s64/mm: don't count invalidated PMDs in page table check
riscv: mm: don't let GUP-fast follow entries without _PAGE_READ
LoongArch: mm: don't let GUP-fast follow invalidated THP PMDs
s390/mm: always clear _SEGMENT_ENTRY_READ in pmdp_invalidate()
sparc64: mm: fix thp_pte_count accounting around pmdp_invalidate()
mm/rmap: re-enable discarding lazyfree THPs at PMD level
userfaultfd: avoid transient none PMDs during UFFDIO_MOVE
arch/loongarch/include/asm/pgtable.h | 6 ++++++
arch/powerpc/include/asm/book3s/64/pgtable.h | 7 +++----
arch/riscv/include/asm/pgtable.h | 27 ++++++++++++++++++++++++++
arch/s390/include/asm/pgtable.h | 8 ++++++--
arch/sparc/include/asm/pgtable_64.h | 7 +++++++
arch/sparc/mm/tlb.c | 27 ++++++++++++++------------
mm/huge_memory.c | 29 ++++++++++++++++++++++------
mm/rmap.c | 13 +++++++++++++
8 files changed, 100 insertions(+), 24 deletions(-)
---
base-commit: c6952260203fadee8e9f96c3f999f03b301d6f6d
change-id: 20261007-anon_vma_uaf_fix-e7accd1d2ee1
Best regards,
--
Yan, Zi
next reply other threads:[~2026-12-04 4:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 4:17 Zi Yan [this message]
2026-12-04 4:17 ` [PATCH v2 1/9] mm/migrate: do not clear device private entry in set_pmd_migration_entry() Zi Yan
2026-12-05 4:06 ` Lance Yang
2026-12-04 4:17 ` [PATCH v2 2/9] powerpc/book3s64/mm: don't count invalidated PMDs in page table check Zi Yan
2026-12-04 4:17 ` [PATCH v2 3/9] riscv: mm: don't let GUP-fast follow entries without _PAGE_READ Zi Yan
2026-12-04 4:17 ` [PATCH v2 4/9] LoongArch: mm: don't let GUP-fast follow invalidated THP PMDs Zi Yan
2026-12-04 4:17 ` [PATCH v2 5/9] s390/mm: always clear _SEGMENT_ENTRY_READ in pmdp_invalidate() Zi Yan
2026-12-04 12:31 ` Alexander Gordeev
2026-12-04 4:17 ` [PATCH v2 6/9] sparc64: mm: fix thp_pte_count accounting around pmdp_invalidate() Zi Yan
2026-12-04 4:17 ` [PATCH v2 7/9] mm/huge_memory: avoid transient none PMDs during lazyfree reclaim Zi Yan
2026-12-04 4:35 ` Liam R. Howlett
2026-12-04 9:38 ` Baolin Wang
2026-12-04 13:23 ` Lorenzo Stoakes (ARM)
2026-12-05 4:35 ` Lance Yang
2026-12-05 5:20 ` Lance Yang
2026-12-04 4:17 ` [PATCH v2 8/9] mm/rmap: re-enable discarding lazyfree THPs at PMD level Zi Yan
2026-12-04 4:37 ` Liam R. Howlett
2026-12-04 9:49 ` Baolin Wang
2026-12-05 5:30 ` Lance Yang
2026-12-04 4:17 ` [PATCH v2 9/9] userfaultfd: avoid transient none PMDs during UFFDIO_MOVE Zi Yan
2026-12-04 12:52 ` Lorenzo Stoakes (ARM)
2026-12-05 5:45 ` Lance Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203-anon_vma_uaf_fix-v2-0-3d4c746e8839@nvidia.com \
--to=ziy@nvidia.com \
--cc=aarcange@redhat.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=andreas@gaisler.com \
--cc=andrew+kernel@donnellan.id.au \
--cc=aou@eecs.berkeley.edu \
--cc=apopple@nvidia.com \
--cc=balbirs@nvidia.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=borntraeger@linux.ibm.com \
--cc=chenhuacai@kernel.org \
--cc=chleroy@kernel.org \
--cc=davem@davemloft.net \
--cc=david@kernel.org \
--cc=debug@rivosinc.com \
--cc=dev.jain@arm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=harry@kernel.org \
--cc=hca@linux.ibm.com \
--cc=jannh@google.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=jszhang@kernel.org \
--cc=kas@kernel.org \
--cc=kernel@xen0n.name \
--cc=kylebot@openai.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=ljs@kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=nico.pache@linux.dev \
--cc=npiggin@gmail.com \
--cc=palmer@dabbelt.com \
--cc=palmer@rivosinc.com \
--cc=pasha.tatashin@soleen.com \
--cc=peterx@redhat.com \
--cc=pjw@kernel.org \
--cc=riel@surriel.com \
--cc=ritesh.list@gmail.com \
--cc=rmclure@linux.ibm.com \
--cc=ryan.roberts@arm.com \
--cc=sashiko-bot@kernel.org \
--cc=sparclinux@vger.kernel.org \
--cc=sshegde@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=svens@linux.ibm.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=zong.li@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®