All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Huang Shijie" <huangsj@hygon.cn>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [RFC PATCH] perf/amd/ibs: Report physical address for IBS fetch samples
Date: Mon, 17 Aug 2026 07:47:50 +0000	[thread overview]
Message-ID: <20260817074751.0C7131F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260817073323.2504767-1-huangsj@hygon.cn>

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

Pre-existing issues:
- [High] Kernel stack buffer overflow when handling AMD IBS Op samples with both IBS_CAPS_BRNTRGT and IBS_CAPS_OPDATA4 capabilities.
--

--- Patch [1]: [RFC PATCH] perf/amd/ibs: Report physical address for IBS fetch samples ---
commit 96b9a5e865d821f72dd58d33f3f265a7de5821e5
Author: Huang Shijie <huangsj@hygon.cn>

perf/amd/ibs: Report physical address for IBS fetch samples

This commit updates AMD IBS fetch sampling to report the physical address of
fetched instructions when PERF_SAMPLE_PHYS_ADDR is requested. It implements
this by parsing the fetch data similarly to how operations data is handled.

> diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
> index 3531f9c23b8c9..e5376ad5b2ecd 100644
> --- a/arch/x86/events/amd/ibs.c
> +++ b/arch/x86/events/amd/ibs.c

[ ... ]

> @@ -1555,6 +1575,8 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
>  
>  	if (perf_ibs == &perf_ibs_op)
>  		perf_ibs_parse_ld_st_data(event->attr.sample_type, &ibs_data, &data);
> +	else
> +		perf_ibs_parse_fetch_data(event->attr.sample_type, &ibs_data, &data);

[Severity: High]
This isn't a bug introduced by this patch, but while looking at how
ibs_data is handled in perf_ibs_handle_irq(), I noticed a potential kernel
stack buffer overflow.

Does the code overflow the ibs_data.regs[] array when a CPU supports both
IBS_CAPS_BRNTRGT and IBS_CAPS_OPDATA4 capabilities?

MSR_AMD64_IBS_REG_COUNT_MAX is defined as 8 in asm/msr-index.h. If both
capabilities are present, it appears 7 MSRs are read into indices 0 to 6,
MSR_AMD64_IBSBRTARGET is read into index 7, and then MSR_AMD64_IBSOPDATA4
would be written to index 8, writing past the end of the array.

Could this also cause uninitialized kernel stack memory to be exposed to
userspace via the perf ring buffer since ibs_data.size would evaluate to 72
bytes, making raw.frag.size 76 bytes, while the valid struct space is only
68 bytes?

>  
>  	/*
>  	 * rip recorded by IbsOpRip will not be consistent with rsp and rbp

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260817073323.2504767-1-huangsj@hygon.cn?part=1

      reply	other threads:[~2026-08-17  7:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  7:33 [RFC PATCH] perf/amd/ibs: Report physical address for IBS fetch samples Huang Shijie
2026-08-17  7:47 ` sashiko-bot [this message]

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=20260817074751.0C7131F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=huangsj@hygon.cn \
    --cc=linux-perf-users@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.