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>
Subject: [PATCH v2 1/9] mm/migrate: do not clear device private entry in set_pmd_migration_entry()
Date: Thu, 03 Dec 2026 23:17:49 -0500 [thread overview]
Message-ID: <20261203-anon_vma_uaf_fix-v2-1-3d4c746e8839@nvidia.com> (raw)
In-Reply-To: <20261203-anon_vma_uaf_fix-v2-0-3d4c746e8839@nvidia.com>
A device private entry is never followed by GUP-fast, so there is no need
to clear the entry to avoid it. Furthermore, clearing the entry creates a
none PMD and a concurrent zap skips it. set_pmd_migration_entry() might not
hold a VMA lock nor a mmap lock. As a result:
1. When racing with munmap(), a "bad pmd" can appear, deposited page table
can be lost, and RSS stats can be off.
2. When racing with mremap(), the PMD is not moved, so the new address
faults and sees zeros instead of the original data.
Fix it by not clearing device private entry.
Fixes: 65edfda6f3f2e ("mm/rmap: extend rmap and migration support device-private entries")
Cc: stable@vger.kernel.org
Signed-off-by: Zi Yan <ziy@nvidia.com>
To: David Hildenbrand <david@kernel.org>
To: Zi Yan <ziy@nvidia.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: "Liam R. Howlett" <liam@infradead.org>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
mm/huge_memory.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 6305b4e2a6b68..91f3c7e7a044a 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -5223,7 +5223,12 @@ int set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,
} else {
softleaf_t old_entry;
- pmdval = pmdp_huge_get_and_clear(vma->vm_mm, address, pvmw->pmd);
+ /*
+ * The device private entry stays as is since GUP-fast
+ * never follows it and folio_try_share_anon_rmap_pmd()
+ * below never fails for it.
+ */
+ pmdval = pmdp_get(pvmw->pmd);
old_entry = softleaf_from_pmd(pmdval);
writable = softleaf_is_device_private_write(old_entry);
--
2.53.0
next prev parent 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 [PATCH v2 0/9] Re-enable discarding lazyfree PMD THPs and transient none PMD fixes Zi Yan
2026-12-04 4:17 ` Zi Yan [this message]
2026-12-05 4:06 ` [PATCH v2 1/9] mm/migrate: do not clear device private entry in set_pmd_migration_entry() 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-1-3d4c746e8839@nvidia.com \
--to=ziy@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=balbirs@nvidia.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=harry@kernel.org \
--cc=jannh@google.com \
--cc=kas@kernel.org \
--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=ljs@kernel.org \
--cc=nico.pache@linux.dev \
--cc=riel@surriel.com \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
/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®