From: sashiko-bot@kernel.org
To: "Ard Biesheuvel" <ardb+git@google.com>
Cc: linux-trace-kernel@vger.kernel.org, linux-modules@vger.kernel.org
Subject: Re: [RFC PATCH 2/9] mm: execmem: Allow huge vmappings to be avoided for execmem caches
Date: Sat, 22 Aug 2026 14:10:16 +0000 [thread overview]
Message-ID: <20260822141017.199431F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260822135323.795946-13-ardb+git@google.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Omitting VM_ALLOW_HUGE_VMAP breaks the ROX cache shrinker by stripping PMD_SIZE alignment, causing a permanent memory leak of cached module memory.
Pre-existing issues:
- [High] Fallback allocations in execmem_cache_populate_alloc() leak memory due to failing the PMD_SIZE alignment checks in the cache shrinker.
- [High] Ignored return value of execmem_restore_rox() allows memory to be silently returned to the ROX cache with RW permissions.
--
--- Patch [2]: [RFC PATCH 2/9] mm: execmem: Allow huge vmappings to be avoided for execmem caches ---
commit 3d4b59f7ca74d71807be337626018d273686c686
Author: Ard Biesheuvel <ardb@kernel.org>
mm: execmem: Allow huge vmappings to be avoided for execmem caches
Only recent arm64 systems are guaranteed to be able to manipulate the
permissions on live kernel mappings that may use huge mappings. Older
ones can only do so on live mappings that are mapped down to pages.
In order to make execmem caches work on arm64 despite this distinction,
allow huge vmappings to be omitted when allocating the caches.
> diff --git a/mm/execmem.c b/mm/execmem.c
> index 6db0c1d82a9d6..5790d4a8532af 100644
> --- a/mm/execmem.c
> +++ b/mm/execmem.c
> @@ -276,7 +276,8 @@ static void *__execmem_cache_alloc(struct execmem_range *range, size_t size)
>
> static void *execmem_cache_populate_alloc(struct execmem_range *range, size_t size)
> {
> - unsigned long vm_flags = VM_ALLOW_HUGE_VMAP;
> + unsigned long vm_flags = (range->flags & EXECMEM_NO_HUGE_VMAP)
> + ? 0 : VM_ALLOW_HUGE_VMAP;
[Severity: High]
Does dropping VM_ALLOW_HUGE_VMAP here cause a permanent memory leak in the
ROX cache?
When VM_ALLOW_HUGE_VMAP is omitted, the allocation may fall back to the
standard alignment (typically PAGE_SIZE) instead of being PMD_SIZE aligned.
However, the shrinker in execmem_cache_clean() strictly requires PMD_SIZE
alignment to free the memory:
mm/execmem.c:execmem_cache_clean() {
...
mas_for_each(&mas, area, ULONG_MAX) {
size_t size = mas_range_len(&mas);
if (IS_ALIGNED(size, PMD_SIZE) &&
IS_ALIGNED(mas.index, PMD_SIZE)) {
struct vm_struct *vm = find_vm_area(area);
...
}
If the starting address (mas.index) of the chunk allocated without
VM_ALLOW_HUGE_VMAP is not PMD_SIZE aligned, the shrinker will skip it,
never returning it to the vmalloc subsystem.
> struct mutex *mutex = &execmem_cache.mutex;
> struct vm_struct *vm;
> size_t alloc_size;
> int err = -ENOMEM;
> void *p;
>
> alloc_size = round_up(size, PMD_SIZE);
> p = execmem_vmalloc(range, alloc_size, PAGE_KERNEL, vm_flags);
> if (!p) {
> alloc_size = size;
> p = execmem_vmalloc(range, alloc_size, PAGE_KERNEL, vm_flags);
[Severity: High]
This is a pre-existing issue, but does this exact-size fallback allocation
leak memory for the same reason?
If the PMD_SIZE rounded allocation fails under pressure, the fallback
allocates the exact requested size. Since this fallback size is not
guaranteed to be PMD_SIZE aligned, it will also permanently fail the
IS_ALIGNED(size, PMD_SIZE) check in execmem_cache_clean(), leaking the
vmalloc space.
[ ... ]
> static int __execmem_cache_free(struct ma_state *mas, void *ptr, gfp_t gfp_mask)
> {
> size_t size = mas_range_len(mas);
> int err;
>
> err = execmem_force_rw(ptr, size);
> if (err)
> return err;
>
> execmem_fill_trapping_insns(ptr, size);
> execmem_restore_rox(ptr, size);
>
> err = execmem_cache_add_locked(ptr, size, gfp_mask);
[Severity: High]
This isn't a bug introduced by this patch, but is it safe to ignore the
return value of execmem_restore_rox() here?
If restoring the ROX permissions fails (for example, if set_memory_rox() fails
internally), the chunk is still added back to the free_areas tree. Subsequent
allocations could then receive memory that is still writable, silently breaking
the W^X security guarantee.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260822135323.795946-11-ardb+git@google.com?part=2
next prev parent reply other threads:[~2026-08-22 14:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 13:53 [RFC PATCH 0/9] arm64: Allocate .text and .init.text together Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 1/9] mm: execmem: Add API to split an existing execmem cache allocation Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 2/9] mm: execmem: Allow huge vmappings to be avoided for execmem caches Ard Biesheuvel
2026-08-22 14:10 ` sashiko-bot [this message]
2026-08-22 13:53 ` [RFC PATCH 3/9] module: Place MOD_TEXT before MOD_INIT_TEXT in enumeration Ard Biesheuvel
2026-08-22 14:05 ` sashiko-bot
2026-08-22 13:53 ` [RFC PATCH 4/9] module: Allocate MOD_INIT_TEXT from the MOD_TEXT ROX allocation Ard Biesheuvel
2026-08-28 14:11 ` Bradley Morgan
2026-08-22 13:53 ` [RFC PATCH 5/9] arm64: mm: Permit permissions changes on huge vmappings Ard Biesheuvel
2026-08-22 14:10 ` sashiko-bot
2026-08-23 16:52 ` Adrian Barnaś
2026-08-22 13:53 ` [RFC PATCH 6/9] arm64: Enable the execmem ROX cache for module text Ard Biesheuvel
2026-08-22 14:13 ` sashiko-bot
2026-08-23 16:46 ` Adrian Barnaś
2026-08-22 13:53 ` [RFC PATCH 7/9] arm64: ftrace: Revert "fix unreachable PLT for ftrace_caller ..." Ard Biesheuvel
2026-08-22 13:53 ` [RFC PATCH 8/9] arm64: module: Combine init and core PLT entries again Ard Biesheuvel
2026-08-22 14:12 ` sashiko-bot
2026-08-22 13:53 ` [RFC PATCH 9/9] arm64: ftrace: Simplify PLT handling Ard Biesheuvel
2026-08-28 13:07 ` [RFC PATCH 0/9] arm64: Allocate .text and .init.text together Petr Pavlu
2026-08-28 13:45 ` Ard Biesheuvel
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=20260822141017.199431F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ardb+git@google.com \
--cc=linux-modules@vger.kernel.org \
--cc=linux-trace-kernel@vger.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