Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amir Ayupov" <aaupov@fb.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/9] perf thread-stack: Report branch stack hw_idx as not available
Date: Mon, 03 Aug 2026 09:19:56 +0000	[thread overview]
Message-ID: <20260803091956.A9C781F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803090640.2412336-2-aaupov@fb.com>

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

Pre-existing issues:
- [Critical] Pre-existing heap buffer overflow in thread_stack__br_sample due to incorrect memcpy length.
--

--- Patch [2]: [PATCH 2/9] perf thread-stack: Report branch stack hw_idx as not available ---
commit 51033b3641484a31783c5c945c25ef5ee0bfb23e
Author: Amir Ayupov <aaupov@fb.com>

perf thread-stack: Report branch stack hw_idx as not available

This commit sets hw_idx to -1ULL for synthesised branch stacks to indicate
that the hardware index is not available. This prevents consumers from
erroneously assuming these branch stacks start at LBR TOS entry 0, matching
the behaviour of intel-pt and cs-etm.

> diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
> --- a/tools/perf/util/thread-stack.c
> +++ b/tools/perf/util/thread-stack.c
> @@ -624,6 +624,7 @@ void thread_stack__br_sample(struct thread *thread, int cpu,
>  	unsigned int nr;
>  
>  	dst->nr = 0;
> +	dst->hw_idx = -1ULL;
>  
>  	if (!ts)
>  		return;

[ ... ]

>  	if (src->nr >= ts->br_stack_sz) {
>  		sz -= nr;
>  		be = &dst->entries[nr];
>  		nr = min(ts->br_stack_pos, sz);
>  		memcpy(be, &src->entries[0], bsz * ts->br_stack_pos);

[Severity: Critical]
This is a pre-existing issue, but does this memcpy() write past the end of
the dst buffer?

We calculate nr as min(ts->br_stack_pos, sz), which limits the count
to the available size in the buffer. However, the memcpy() uses
bsz * ts->br_stack_pos instead of bsz * nr.

When running perf commands that parse Intel PT traces, ts->br_stack_sz can
be larger than the sample size sz. This could cause ts->br_stack_pos to
exceed nr, leading to a heap buffer overflow when copying to be.

>  	}
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803090640.2412336-1-aaupov@fb.com?part=2

  reply	other threads:[~2026-08-03  9:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03  9:06 [PATCH 1/9] perf header: Tolerate inconsistent HEADER_GROUP_DESC Amir Ayupov
2026-08-03  9:06 ` [PATCH 2/9] perf thread-stack: Report branch stack hw_idx as not available Amir Ayupov
2026-08-03  9:19   ` sashiko-bot [this message]
2026-08-03  9:06 ` [PATCH 3/9] perf thread-stack: Bound wrapped branch stack copy Amir Ayupov
2026-08-03  9:26   ` sashiko-bot
2026-08-03  9:06 ` [PATCH 4/9] perf dlfilter: Add non-empty branch stack filter Amir Ayupov
2026-08-03  9:06 ` [PATCH 5/9] perf cs-etm: Split up cs_etm__process_timestamped_queues() Amir Ayupov
2026-08-03  9:06 ` [PATCH 6/9] perf cs-etm: Add branch history to existing samples Amir Ayupov
2026-08-03  9:23   ` sashiko-bot
2026-08-03  9:06 ` [PATCH 7/9] perf test cs-etm: Test branch history on " Amir Ayupov
2026-08-03  9:21   ` sashiko-bot
2026-08-03  9:06 ` [PATCH 8/9] perf cs-etm: Consume branch history when attaching it to a sample Amir Ayupov
2026-08-03  9:06 ` [PATCH 9/9] Documentation: coresight: Document context-sensitive PGO workflow Amir Ayupov

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=20260803091956.A9C781F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aaupov@fb.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox