From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes" <ljs@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH] x86/mm/pat: acquire mmap lock on page table free to avoid ptdump UAF
Date: Fri, 10 Jul 2026 12:14:54 +0000 [thread overview]
Message-ID: <20260710121454.BE3C11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260710-fix-cpa-ptdump-race-v1-1-d898699a7417@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch fails to protect ptdump invocations on mm_structs other than init_mm (such as current->mm or efi_mm), leaving them vulnerable to Use-After-Free.
- [High] The patch fails to protect lockless kernel page table walkers from a Use-After-Free race when freeing collapsed page tables.
--
--- Patch [1]: [PATCH] x86/mm/pat: acquire mmap lock on page table free to avoid ptdump UAF ---
commit 34992f845258302500edbd0c5e7fac8afe267207
Author: Lorenzo Stoakes <ljs@kernel.org>
x86/mm/pat: acquire mmap lock on page table free to avoid ptdump UAF
This commit attempts to fix a use-after-free issue when ptdump walks kernel
page tables concurrently with them being collapsed and freed by CPA. It adds
an mmap_read_lock on init_mm during the free operation.
> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
> index d023a40a1e034..4c4b8244502fc 100644
> --- a/arch/x86/mm/pat/set_memory.c
> +++ b/arch/x86/mm/pat/set_memory.c
[ ... ]
> @@ -436,9 +437,16 @@ static void cpa_collapse_large_pages(struct cpa_data *cpa)
>
> flush_tlb_all();
>
> - list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
> - list_del(&ptdesc->pt_list);
> - pagetable_free(ptdesc);
> + /*
> + * ptdump might read these page tables, so avoid a use-after-free by
> + * acquiring the mmap read lock on init_mm (ptdump acquires the mmap
> + * write lock).
> + */
> + scoped_guard(mmap_read_lock, &init_mm) {
[Severity: High]
This isn't a bug introduced by this patch, but does locking init_mm protect
ptdump invocations that use a different mm_struct?
For example, when reading /sys/kernel/debug/page_tables/current_kernel,
the kernel calls ptdump_curknl_show() which invokes ptdump on current->mm:
arch/x86/mm/debug_pagetables.c:ptdump_curknl_show() {
...
ptdump_walk_pgd_level_debugfs(m, current->mm, false);
...
}
The ptdump walker will acquire the mmap_write_lock for current->mm, entirely
bypassing the init_mm lock added here. Can this still lead to a
use-after-free if set_memory_rox() concurrently frees a PTE page while
ptdump_curknl_show() is reading it?
> + list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
> + list_del(&ptdesc->pt_list);
> + pagetable_free(ptdesc);
[Severity: High]
This is a pre-existing issue, but does mmap_read_lock protect against
lockless kernel page table walkers?
Functions like vmalloc_to_page() traverse kernel page tables locklessly:
mm/vmalloc.c:vmalloc_to_page() {
...
ptep = pte_offset_kernel(pmd, addr);
pte = ptep_get(ptep);
...
}
If a lockless walker reads a PMD and gets preempted, and concurrently
cpa_collapse_large_pages() collapses the PMD and synchronously frees the
page table to the buddy allocator via pagetable_free(), will the walker
dereference freed memory when it resumes?
Since mmap_read_lock does not block lockless walkers, would fixing this
properly require RCU-delayed freeing for kernel page tables instead of
synchronous freeing?
> + }
> + }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260710-fix-cpa-ptdump-race-v1-1-d898699a7417@kernel.org?part=1
next prev parent reply other threads:[~2026-07-10 12:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 11:56 [PATCH] x86/mm/pat: acquire mmap lock on page table free to avoid ptdump UAF Lorenzo Stoakes
2026-07-10 12:14 ` sashiko-bot [this message]
2026-07-10 12:50 ` Kiryl Shutsemau
2026-07-10 16:26 ` Dave Hansen
2026-07-10 18:53 ` Lorenzo Stoakes
2026-07-10 19:50 ` Dave Hansen
2026-07-11 8:27 ` Lorenzo Stoakes
2026-07-11 10:05 ` Mike Rapoport
2026-07-12 8:56 ` Lorenzo Stoakes
2026-07-12 10:46 ` Lorenzo Stoakes
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=20260710121454.BE3C11F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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