Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Richter" <tmricht@linux.ibm.com>
Cc: linux-s390@vger.kernel.org,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH 1/3 v8] s390/pai: Use PAI PMU index as parameter replacing event
Date: Tue, 01 Sep 2026 09:12:38 +0000	[thread overview]
Message-ID: <20260901091238.F26751F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901085448.2260658-2-tmricht@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing bounds check on the hardware-reported NNPA counter count (`ib.num_nnpa`) leads to an out-of-bounds kernel heap read.
--

commit a6f12edfe6f84375133dd3bb77d40f4e8c67385e
Author: Thomas Richter <tmricht@linux.ibm.com>
s390/pai: Use PAI PMU index as parameter replacing event

This patch updates pai_alloc_cpu() and pai_event_destroy_cpu() to use
the PAI PMU index value as a parameter instead of a struct perf_event
pointer. Only the index value is actually needed inside these functions.

> diff --git a/arch/s390/kernel/perf_pai.c b/arch/s390/kernel/perf_pai.c
> index cdb8006220ca0..7c13f5586c793 100644
> --- a/arch/s390/kernel/perf_pai.c
> +++ b/arch/s390/kernel/perf_pai.c

[ ... ]

> @@ -241,12 +239,12 @@ static u64 paicrypt_getall(struct perf_event *event)
>   *
>   * Allocate the memory for the event.
>   */
> -static int pai_alloc_cpu(struct perf_event *event, int cpu)
> +static int pai_alloc_cpu(int idx, int cpu)
>  {
> -	int rc, idx = PAI_PMU_IDX(event);
>  	struct pai_map *cpump = NULL;
>  	bool need_paiext_cb = false;
>  	struct pai_mapptr *mp;
> +	int rc;

[Severity: High]
This is a pre-existing issue, but I have a question about how the buffer
allocated in this function is accessed.

In paipmu_setup(), the hardware-reported counter count (ib.num_nnpa) can be
up to 127. The code then artificially increments it for the software ALL event:

arch/s390/kernel/perf_pai.c:paipmu_setup() {
    ...
		case PAI_PMU_EXT:
			p->num_avail = ib.num_nnpa;
			break;
		}
		p->num_avail += 1;		/* Add xxx_ALL event */
    ...
}

This means p->num_avail can reach 128.

Later in pai_alloc_cpu(), cpump->area is allocated with a fixed size:

arch/s390/kernel/perf_pai.c:pai_alloc_cpu() {
    ...
			cpump->area = kzalloc(pai_pmu[idx].area_size, GFP_KERNEL);
    ...
}

For PAI_PMU_EXT, area_size is 1024 bytes, which holds exactly 128 elements.

However, pai_getdata() iterates up to p->num_avail:

arch/s390/kernel/perf_pai.c:pai_getdata() {
    ...
	for (i = 1; i <= pp->num_avail; i++) {
		u64 val = pai_getctr(cpump->area, i,
				     kernel ? pp->kernel_offset : 0);
    ...
}

If ib.num_nnpa is 127, p->num_avail becomes 128. The loop evaluates i = 128
and pai_getctr() accesses cpump->area[128] (the 129th element).

Can this cause an out-of-bounds heap read if cpump->area is strictly 1024
bytes?

>  
>  	mutex_lock(&pai_reserve_mutex);
>  	/* Allocate root node */

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

  reply	other threads:[~2026-09-01  9:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  8:54 [PATCH 0/3 v8] Add CPU hotplug support for PAI PMU Thomas Richter
2026-09-01  8:54 ` [PATCH 1/3 v8] s390/pai: Use PAI PMU index as parameter replacing event Thomas Richter
2026-09-01  9:12   ` sashiko-bot [this message]
2026-09-01  9:56     ` Thomas Richter
2026-09-01  8:54 ` [PATCH 2/3 v8] s390/pai: Move locking to event init and delete Thomas Richter
2026-09-01  9:12   ` sashiko-bot
2026-09-01  8:54 ` [PATCH 3/3 v8] s390/pai: Support CPU hotplug for PMU PAI Thomas Richter
2026-09-01  9:03   ` sashiko-bot
2026-09-01 11:19   ` Heiko Carstens
2026-09-01 14:20 ` [PATCH 0/3 v8] Add CPU hotplug support for PAI PMU Heiko Carstens
2026-09-01 14:22   ` Heiko Carstens

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=20260901091238.F26751F000E9@smtp.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 \
    --cc=tmricht@linux.ibm.com \
    /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