public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Ravi Bangoria <ravi.bangoria@amd.com>
To: <sashiko@lists.linux.dev>, Ingo Molnar <mingo@kernel.org>
Cc: <linux-perf-users@vger.kernel.org>,
	Ravi Bangoria <ravi.bangoria@amd.com>
Subject: Re: [GIT PULL] Performance events changes for v7.1
Date: Tue, 14 Apr 2026 09:30:40 +0530	[thread overview]
Message-ID: <752bb73b-5828-4d38-b05c-16da0f262d33@amd.com> (raw)
In-Reply-To: <20260413094110.C3CAAC116C6@smtp.kernel.org>

>> diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
>> --- a/arch/x86/include/asm/msr-index.h
>> +++ b/arch/x86/include/asm/msr-index.h
>> @@ -698,6 +698,8 @@
>>  #define MSR_AMD64_IBSBRTARGET		0xc001103b
>>  #define MSR_AMD64_ICIBSEXTDCTL		0xc001103c
>>  #define MSR_AMD64_IBSOPDATA4		0xc001103d
>> +#define MSR_AMD64_IBSOPCTL2		0xc001103e
>> +#define MSR_AMD64_IBSFETCHCTL2		0xc001103f
>>  #define MSR_AMD64_IBS_REG_COUNT_MAX	8 /* includes MSR_AMD64_IBSBRTARGET */
> 
> This isn't a regression from the current patch, but looking at the adjacent
> MSR handling code, is there a potential stack buffer overflow in the IBS
> NMI handler on CPUs supporting IBS_CAPS_OPDATA4?
> 
> In arch/x86/events/amd/ibs.c, struct perf_ibs_data is allocated on the
> stack in perf_ibs_handle_irq(). Its regs array is sized using
> MSR_AMD64_IBS_REG_COUNT_MAX, which is 8.
> 
> When handling a perf_ibs_op event, the initial read loop fetches up to 7
> MSRs, advancing the pointer buf to &ibs_data.regs[7].
> 
> Subsequently, the handler reads additional MSRs depending on CPU caps:
> 
> 	if (event->attr.sample_type & PERF_SAMPLE_RAW) {
> 		if (perf_ibs == &perf_ibs_op) {
> 			if (ibs_caps & IBS_CAPS_BRNTRGT) {
> 				rdmsrq(MSR_AMD64_IBSBRTARGET, *buf++);
> 				br_target_idx = size;
> 				size++;
> 			}
> 			if (ibs_caps & IBS_CAPS_OPDATA4) {
> 				rdmsrq(MSR_AMD64_IBSOPDATA4, *buf++);
> 				size++;
> 			}
> 		}
> 
> If the CPU supports IBS_CAPS_BRNTRGT, MSR_AMD64_IBSBRTARGET is read into
> regs[7], advancing buf to &regs[8].
> 
> If the CPU also supports IBS_CAPS_OPDATA4, it reads MSR_AMD64_IBSOPDATA4 into
> the next pointer position, which translates to regs[8]. This writes one
> element past the end of the 8-element array, overwriting adjacent local
> variables on the stack.
> 
> Furthermore, ibs_data.size is incremented to 9, so
> perf_sample_save_raw_data() will subsequently read 72 bytes of regs,
> exposing the corrupted stack data to user-space in the raw perf record. Since
> unprivileged users can configure RAW IBS events, this might lead to
> unintended behavior.
> 
> Should MSR_AMD64_IBS_REG_COUNT_MAX be increased to account for
> IBS_CAPS_OPDATA4?

Thanks for the bug report.

While this seems like a genuine overflow issue, IbsOpData4 has been
deprecated from long back. I was unable to find any platform that
supports it. So it's not a real a concern.

Thanks,
Ravi

  parent reply	other threads:[~2026-04-14  4:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13  8:19 [GIT PULL] Performance events changes for v7.1 Ingo Molnar
2026-04-13  9:41 ` sashiko-bot
2026-04-13 21:43   ` Namhyung Kim
2026-04-14  4:00   ` Ravi Bangoria [this message]
2026-04-14 20:45 ` pr-tracker-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=752bb73b-5828-4d38-b05c-16da0f262d33@amd.com \
    --to=ravi.bangoria@amd.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=sashiko@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