Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Heiko Carstens" <hca@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH 17/17] s390/execmem: Enable EXECMEM_ARCH_ROX
Date: Thu, 03 Dec 2026 11:09:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-247646@kernel.org> (raw)
In-Reply-To: <20261203103345.1206548-18-hca@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] s390/execmem: zero-sized EXECMEM_FTRACE alloc corrupts ROX
  cache maple trees
- [Medium] s390/mm: change_page_attr_alias() shatters direct-map PMDs on
  ROX cache refill
- [Low] s390/execmem: commit subject references nonexistent
  EXECMEM_ARCH_ROX
--

commit 6a59e81aa86e998734bf155ab53f0430bb991904
Author: Heiko Carstens <hca@linux.ibm.com>

s390/execmem: Enable EXECMEM_ARCH_ROX

This commit selects ARCH_HAS_EXECMEM_ROX on s390, adds
execmem_fill_trapping_insns(), and enables EXECMEM_ROX_CACHE for
EXECMEM_DEFAULT, EXECMEM_KPROBES, and EXECMEM_FTRACE when EDAT1 is
available, while defining EXECMEM_BPF and EXECMEM_MODULE_DATA as writable.

> s390/execmem: Enable EXECMEM_ARCH_ROX

[Severity: Low]
This isn't a bug, but the subject names EXECMEM_ARCH_ROX instead of
ARCH_HAS_EXECMEM_ROX.

> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index 0cac76ddb700b..139ca6461fc81 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -312,39 +312,70 @@ void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap)

[ ... ]

> +	if (IS_ENABLED(CONFIG_ARCH_HAS_EXECMEM_ROX) && cpu_has_edat1()) {
> +		pgprot = PAGE_KERNEL_ROX;
> +		flags = EXECMEM_KASAN_SHADOW | EXECMEM_ROX_CACHE;
> +	} else {
> +		pgprot = PAGE_KERNEL;
> +		flags = EXECMEM_KASAN_SHADOW;
> +	}

[Severity: Medium]
Does enabling EXECMEM_ROX_CACHE shatter 1MB direct-map PMDs on every cache
refill?

Each refill in execmem_vmalloc_rox() allocates a 1MB huge vmalloc block and
calls set_memory_rox() on the 256-page range.  change_page_attr_alias()
ignores vm_area_page_order(area) and updates the direct-map alias one 4KB
page at a time.

On the first page, walk_pmd_level() splits the 1MB direct-map PMD into 256
4KB PTEs, causing 256 global crdte/cspg shootdowns under
mmap_write_lock(&init_mm).  The PMD is never collapsed back, so a later
vfree() in execmem_cache_clean() triggers another 512 per-page shootdowns.

Updating contiguous direct-map spans at PMD granularity in
change_page_attr_alias() would avoid both the split and the shootdowns.

[ ... ]

>  			[EXECMEM_FTRACE] = {
> -				.flags	= EXECMEM_KASAN_SHADOW,
> +				.flags	= flags,
>  				.start	= start,
>  				.end	= MODULES_END,
>  				.pgprot	= PAGE_KERNEL_ROX,
>  				.alignment = MODULE_ALIGN,
>  			},

[Severity: High]
Can a zero-sized EXECMEM_FTRACE allocation corrupt the ROX cache maple trees
and cause a use-after-free?

When loading a module with an empty __mcount_loc section (s->sh_size == 0),
module_finalize() -> module_alloc_ftrace_hotpatch_trampolines() calls
execmem_alloc(EXECMEM_FTRACE, 0).  Previously __vmalloc_node_range()
rejected size 0 and returned NULL.

With EXECMEM_ROX_CACHE enabled, execmem_alloc() passes size 0 into
execmem_cache_alloc_locked(), where addr + size - 1 underflows to addr - 1.
That stores an inverted [addr, addr - 1] range in busy_areas while
re-inserting [addr, last] into free_areas and returning addr.

A subsequent allocation then reuses addr, and unloading the first module
calls execmem_free(mod->arch.trampolines_start), overwriting live code with
trapping zeroes via execmem_fill_trapping_insns().

Rejecting size == 0 in execmem_alloc() or skipping empty sections in
module_alloc_ftrace_hotpatch_trampolines() would prevent this regression.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203103345.1206548-1-hca@linux.ibm.com?part=17

  reply	other threads:[~2026-12-03 11:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 10:33 [PATCH 00/17] s390/mm: Large kernel mappings for vmalloc and execmem ROX cache Heiko Carstens
2026-12-03 10:33 ` [PATCH 01/17] s390/boot: Initialize asce_limit for init_mm properly Heiko Carstens
2026-12-03 11:01   ` sashiko-bot
2026-12-03 10:33 ` [PATCH 02/17] s390/pageattr: Only account direct mapping in direct map page counters Heiko Carstens
2026-12-03 10:33 ` [PATCH 03/17] s390/mm: Serialize kernel page table changes with init_mm mmap lock Heiko Carstens
2026-12-03 10:33 ` [PATCH 04/17] s390/vmem: Use generic page table allocators for vmem page tables Heiko Carstens
2026-12-03 11:02   ` sashiko-bot
2026-12-03 10:33 ` [PATCH 05/17] s390/mm: Show write-combining attribute in page table dump Heiko Carstens
2026-12-03 10:33 ` [PATCH 06/17] s390/mm: Implement HAVE_ARCH_HUGE_VMAP Heiko Carstens
2026-12-03 11:03   ` sashiko-bot
2026-12-03 10:33 ` [PATCH 07/17] s390/mm: Implement HAVE_ARCH_HUGE_VMALLOC Heiko Carstens
2026-12-03 10:33 ` [PATCH 08/17] s390/pageattr: Add helpers to replace kernel page table entries Heiko Carstens
2026-12-03 10:33 ` [PATCH 09/17] s390/mm: Add _SEGMENT_ENTRY_TYPE Heiko Carstens
2026-12-03 10:33 ` [PATCH 10/17] s390/pageattr: Use common helper to change kernel page table permissions Heiko Carstens
2026-12-03 10:33 ` [PATCH 11/17] s390/pageattr: Avoid splitting mappings if permissions do not change Heiko Carstens
2026-12-03 10:33 ` [PATCH 12/17] s390/pageattr: Mark intentional 4k kernel mappings Heiko Carstens
2026-12-03 11:00   ` sashiko-bot
2026-12-03 10:33 ` [PATCH 13/17] s390/pageattr: Collapse kernel mappings after changing page attributes Heiko Carstens
2026-12-03 11:10   ` sashiko-bot
2026-12-03 10:33 ` [PATCH 14/17] s390/mm: Add PAGE_KERNEL_ROX Heiko Carstens
2026-12-03 10:33 ` [PATCH 15/17] s390/execmem: Add EXECMEM_KPROBES range Heiko Carstens
2026-12-03 11:03   ` sashiko-bot
2026-12-03 10:33 ` [PATCH 16/17] s390/execmem: Add EXECMEM_FTRACE range Heiko Carstens
2026-12-03 11:04   ` sashiko-bot
2026-12-03 10:33 ` [PATCH 17/17] s390/execmem: Enable EXECMEM_ARCH_ROX Heiko Carstens
2026-12-03 11:09   ` sashiko-bot [this message]
2026-12-03 11:11 ` [PATCH 00/17] s390/mm: Large kernel mappings for vmalloc and execmem ROX cache sashiko-bot

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=sashiko-outbox-247646@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@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