From: sashiko-bot@kernel.org
To: "Andreas Grapentin" <gra@linux.ibm.com>
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
linux-perf-users@vger.kernel.org,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH 10/10] s390/perf: Recognize SAE guests
Date: Fri, 04 Dec 2026 12:30:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-249794@kernel.org> (raw)
In-Reply-To: <20261204-host-irq-v1-10-a8387ee8a380@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] s390/perf: NULL dereference of sae_block() in
perf_arch_instruction_pointer()
--
commit 4b5d91e0d26617e654b0c5cf570e3076efc5d4a8
Author: Andreas Grapentin <gra@linux.ibm.com>
s390/perf: Recognize SAE guests
This commit extends s390 perf guest detection to recognize ARM64 SAE
guests alongside SIE guests, retrieving the guest instruction pointer and
user/kernel mode from struct kvm_sae_block.
> diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c
> index 606750bae508d..00464fbe33ead 100644
> --- a/arch/s390/kernel/perf_event.c
> +++ b/arch/s390/kernel/perf_event.c
[ ... ]
> @@ -33,31 +34,64 @@ static struct kvm_s390_sie_block *sie_block(struct pt_regs *regs)
> return (struct kvm_s390_sie_block *)stack->sie_control_block;
> }
>
> -static bool is_in_guest(struct pt_regs *regs)
> +static struct kvm_sae_block *sae_block(struct pt_regs *regs)
> {
> - if (user_mode(regs))
> - return false;
> -#if IS_ENABLED(CONFIG_KVM)
> - return instruction_pointer(regs) == (unsigned long) &sie_exit;
> -#else
> - return false;
> -#endif
> + struct stack_frame *stack = (struct stack_frame *)regs->gprs[15];
> +
> + if (!stack)
> + return NULL;
> +
> + return (struct kvm_sae_block *)stack->sae_block;
> }
>
> -static unsigned long guest_is_user_mode(struct pt_regs *regs)
> +enum guest_type {
> + GUEST_TYPE_NONE = 0,
> + GUEST_TYPE_SIE,
> + GUEST_TYPE_SAE,
> +};
> +
> +static enum guest_type is_in_guest(struct pt_regs *regs)
> {
> - return sie_block(regs)->gpsw.mask & PSW_MASK_PSTATE;
> +#if IS_ENABLED(CONFIG_KVM)
> + if (user_mode(regs))
> + return GUEST_TYPE_NONE;
> + if (instruction_pointer(regs) == (unsigned long)&sie_exit)
> + return GUEST_TYPE_SIE;
> + if (instruction_pointer(regs) == (unsigned long)&sae_exit)
> + return GUEST_TYPE_SAE;
> +#endif
> + return GUEST_TYPE_NONE;
> }
[ ... ]
> unsigned long perf_arch_instruction_pointer(struct pt_regs *regs)
> {
> - return is_in_guest(regs) ? instruction_pointer_guest(regs)
> - : instruction_pointer(regs);
> + switch (is_in_guest(regs)) {
> + case GUEST_TYPE_SIE:
> + return sie_block(regs)->gpsw.addr;
> + case GUEST_TYPE_SAE:
> + return sae_block(regs)->pc;
> + default:
> + return instruction_pointer(regs);
> + }
> }
[Severity: High]
Can sae_block(regs)->pc cause a NULL pointer dereference when called with
synthetic pt_regs from CPU-MF sampling?
In arch/s390/kernel/perf_cpum_sf.c, perf_push_sample() builds a
zero-initialized pt_regs (leaving regs.gprs[15] == 0) with the sampled
instruction address and pstate in regs.psw, then calls
perf_event_overflow() -> ... -> perf_arch_instruction_pointer().
Unlike perf_arch_misc_flags(), which checks !regs->gprs[15] before calling
is_in_guest(), neither is_in_guest() nor perf_arch_instruction_pointer()
guards against a zero stack pointer.
When a supervisor-mode hardware sample lands on sae_exit, is_in_guest()
returns GUEST_TYPE_SAE, sae_block() returns NULL, and sae_block(regs)->pc
dereferences a NULL pointer. With relocated lowcore enabled, address 0 is
unmapped and this crashes the host in hardirq context.
Returning GUEST_TYPE_NONE from is_in_guest() when !regs->gprs[15] (or
checking the returned block pointer for NULL) would prevent this and also
close the same pre-existing hazard on the GUEST_TYPE_SIE path.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=10
next prev parent reply other threads:[~2026-12-04 12:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
2026-12-04 12:09 ` [PATCH 01/10] s390/sae: Prepare handling host interrupts during SAE execution Andreas Grapentin
2026-12-04 12:31 ` sashiko-bot
2026-12-04 12:09 ` [PATCH 02/10] s390/sae: Add sae_entry and sae_exit symbols Andreas Grapentin
2026-12-04 12:30 ` sashiko-bot
2026-12-04 12:09 ` [PATCH 03/10] KVM: s390: Share mcck_volatile_info between KVMs Andreas Grapentin
2026-12-04 12:09 ` [PATCH 04/10] s390/irq: Add kvm_exit callback for arm-on-s390 Andreas Grapentin
2026-12-04 12:40 ` sashiko-bot
2026-12-04 12:09 ` [PATCH 05/10] KVM: s390: arm64: Enable host irq Andreas Grapentin
2026-12-04 12:35 ` sashiko-bot
2026-12-04 12:09 ` [PATCH 06/10] s390: Rename CIF_MCCK_GUEST to CIF_MCCK_SIE Andreas Grapentin
2026-12-04 12:09 ` [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests Andreas Grapentin
2026-12-04 12:40 ` sashiko-bot
2026-12-04 12:09 ` [PATCH 08/10] KVM: s390: arm64: Enable SError injection Andreas Grapentin
2026-12-04 12:34 ` sashiko-bot
2026-12-04 12:09 ` [PATCH 09/10] KVM: s390: arm64: Enable mcck forwarding Andreas Grapentin
2026-12-04 12:33 ` sashiko-bot
2026-12-04 12:09 ` [PATCH 10/10] s390/perf: Recognize SAE guests Andreas Grapentin
2026-12-04 12:30 ` sashiko-bot [this message]
2026-12-04 12:40 ` [PATCH 00/10] s390: Host interrupt handling for " 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-249794@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=gra@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.