From: sashiko-bot@kernel.org
To: "Hao Ge" <hao.ge@linux.dev>
Cc: linux-modules@vger.kernel.org, "Petr Pavlu" <petr.pavlu@suse.com>
Subject: Re: [PATCH v11 2/7] mm/vmalloc: undo partial mappings inside the mapping functions
Date: Tue, 29 Sep 2026 08:33:07 +0000 [thread overview]
Message-ID: <20260929083308.046B41F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260929082014.160587-3-hao.ge@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mm: BUG_ON() triggered in __vunmap_range_noflush() on first chunk failure
- [High] mm: stale TLB entries left on mapping rollback cause UAF
--
commit 8d2eaa273026d4be467acd8256954d343a66fc4c
Author: Hao Ge <hao.ge@linux.dev>
mm/vmalloc: undo partial mappings inside the mapping functions
This patch modifies __vmap_pages_range_noflush() and friends to undo the
PTEs they installed themselves on failure. Callers no longer need to clean up
partial mappings.
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index a9fce7efe4f49..436393aba7eb7 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -349,6 +349,10 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end,
> if (mask & ARCH_PAGE_TABLE_SYNC_MASK)
> arch_sync_kernel_mappings(start, end);
>
> + /* Undo the PTEs installed before the failure. */
> + if (err)
> + __vunmap_range_noflush(start, end);
> +
> return err;
> }
[Severity: High]
Is it safe to omit a TLB flush on rollback here?
By clearing the PTEs using __vunmap_range_noflush() without flushing the TLB,
the CPU might retain stale entries.
If a caller like vm_module_tags_populate() in mm/alloc_tag.c frees the
physical pages immediately after the mapping attempt fails:
if (vmap_pages_range(...) < 0) {
...
release_pages(arg, nr);
}
could speculative or adjacent accesses hit the freed memory, leading to a
use-after-free and state corruption?
[ ... ]
> @@ -683,6 +694,7 @@ int __vmap_pages_range_noflush(unsigned long addr, unsigned long end,
> pgprot_t prot, struct page **pages, unsigned int page_shift)
> {
> unsigned int i, nr = (end - addr) >> PAGE_SHIFT;
> + unsigned long start = addr;
>
> WARN_ON(page_shift < PAGE_SHIFT);
>
> @@ -696,8 +708,14 @@ int __vmap_pages_range_noflush(unsigned long addr, unsigned long end,
> err = vmap_range_noflush(addr, addr + (1UL << page_shift),
> page_to_phys(pages[i]), prot,
> page_shift);
> - if (err)
> + if (err) {
> + /*
> + * vmap_range_noflush() undoes its own partial work,
> + * discard the chunks that already mapped.
> + */
> + __vunmap_range_noflush(start, addr);
> return err;
> + }
[Severity: High]
What happens if vmap_range_noflush() fails on the very first iteration of
this loop?
In that case, the variable addr is still equal to start, so this calls
__vunmap_range_noflush() with a zero-length range.
Because __vunmap_range_noflush() contains:
BUG_ON(addr >= end);
will this immediately panic the kernel on an early allocation failure?
>
> addr += 1UL << page_shift;
> }
> @@ -714,7 +732,16 @@ int vmap_pages_range_noflush(unsigned long addr, unsigned long end,
>
> if (ret)
> return ret;
> - return __vmap_pages_range_noflush(addr, end, prot, pages, page_shift);
> +
> + ret = __vmap_pages_range_noflush(addr, end, prot, pages, page_shift);
> + /*
> + * The page tables undo themselves on failure. Tear down the
> + * metadata that was fully set up before the mapping failed.
> + */
> + if (ret)
> + kmsan_vunmap_range_noflush(addr, end);
[Severity: High]
Are we also leaving behind stale TLB entries for the KMSAN metadata here?
kmsan_vmap_pages_range_noflush() successfully maps the metadata and
explicitly flushes the TLB for shadow/origin mappings.
If the subsequent main mapping fails, this rollback clears the KMSAN PTEs but
skips the TLB flush, which might leave stale TLB entries pointing to freed
KMSAN metadata.
> +
> + return ret;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260929082014.160587-1-hao.ge@linux.dev?part=2
next prev parent reply other threads:[~2026-09-29 8:33 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 8:20 [PATCH v11 0/7] alloc_tag and module codetag section fixes Hao Ge
2026-09-29 8:20 ` [PATCH v11 1/7] alloc_tag: move release_module_tags() above reserve_module_tags() Hao Ge
2026-09-29 8:20 ` [PATCH v11 2/7] mm/vmalloc: undo partial mappings inside the mapping functions Hao Ge
2026-09-29 8:33 ` sashiko-bot [this message]
2026-09-30 10:12 ` Uladzislau Rezki
2026-10-04 17:42 ` Suren Baghdasaryan
2026-10-09 8:23 ` Hao Ge
2026-10-08 6:53 ` Hao Ge
2026-10-08 8:09 ` Hao Ge
2026-10-08 8:13 ` Hao Ge
2026-09-29 8:20 ` [PATCH v11 3/7] alloc_tag: clean up the populate failure path Hao Ge
2026-10-04 17:55 ` Suren Baghdasaryan
2026-09-29 8:20 ` [PATCH v11 4/7] module: introduce SH_ENTSIZE_STANDALONE for separately allocated sections Hao Ge
2026-09-29 8:20 ` [PATCH v11 5/7] module: allocate codetag sections before the regular module layout Hao Ge
2026-09-29 8:20 ` [PATCH v11 6/7] alloc_tag: skip percpu counter allocation when profiling is disabled Hao Ge
2026-09-29 8:40 ` sashiko-bot
2026-09-29 8:20 ` [PATCH v11 7/7] alloc_tag: fix the /proc/allocinfo lifecycle Hao Ge
2026-10-04 18:23 ` Suren Baghdasaryan
2026-10-09 11:16 ` Hao Ge
2026-09-29 20:44 ` [PATCH v11 0/7] alloc_tag and module codetag section fixes Andrew Morton
2026-09-30 2:39 ` Suren Baghdasaryan
2026-09-30 3:26 ` Hao Ge
2026-09-30 8:34 ` Uladzislau Rezki
2026-10-04 17:42 ` Suren Baghdasaryan
2026-10-04 18:37 ` Suren Baghdasaryan
2026-10-09 11:30 ` Hao Ge
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=20260929083308.046B41F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hao.ge@linux.dev \
--cc=linux-modules@vger.kernel.org \
--cc=petr.pavlu@suse.com \
--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