From: Leo Yan <leo.yan@arm.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v8 4/8] perf cs-etm: Use thread-stack for last branch entries
Date: Tue, 16 Jun 2026 15:16:56 +0100 [thread overview]
Message-ID: <20260616141656.GA31870@e132581.arm.com> (raw)
In-Reply-To: <20260611171846.DC8031F00893@smtp.kernel.org>
On Thu, Jun 11, 2026 at 05:18:46PM +0000, sashiko-bot@kernel.org wrote:
[...]
> > @@ -1644,8 +1593,11 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
> >
> > cs_etm__copy_insn(etmq, tidq, packet, &sample);
> >
> > - if (etm->synth_opts.last_branch)
> > + if (etm->synth_opts.last_branch) {
> > + thread_stack__br_sample(tidq->frontend_thread, tidq->packet->cpu,
> > + tidq->last_branch, tidq->br_stack_sz);
>
> [Severity: Critical]
> This is a pre-existing issue, but calling thread_stack__br_sample() can
> trigger an out-of-bounds write in that function.
>
> In thread_stack__br_sample(), when copying from the wrapped ring buffer, it
> calculates bounds using nr but ignores it in memcpy:
>
> nr = min(ts->br_stack_pos, sz);
> memcpy(be, &src->entries[0], bsz * ts->br_stack_pos);
>
> If the destination buffer size sz is smaller than ts->br_stack_pos, does the
> memcpy write beyond the allocated bounds for nr elements?
This is a common bug but irrelevant to this series. I will
use a separate patch set to address the issue.
>
> > sample.branch_stack = tidq->last_branch;
> > + }
>
> [ ... ]
>
> > @@ -2020,7 +1956,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
> >
> > /* Reset last branches after flush the trace */
> > if (etm->synth_opts.last_branch)
> > - cs_etm__reset_last_branch_rb(tidq);
> > + thread_stack__flush(tidq->frontend_thread);
[...]
> [Severity: Medium]
> Looking at thread_stack__flush(), it clears the call stack but does not
> reset the branch stack array (ts->br_stack_pos and ts->br_stack_rb remain
> intact).
>
> Will this leave stale branch entries from before a trace gap to be prepended
> to the new trace segment?
Seems it should clean up both ts->br_stack_pos and br_stack_rb->nr.
This will be addressed in separate series for fix common code.
Thanks,
Leo
next prev parent reply other threads:[~2026-06-16 14:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 14:50 [PATCH v8 0/8] perf cs-etm: Support thread stack and callchain Leo Yan
2026-06-11 14:50 ` [PATCH v8 1/8] perf cs-etm: Filter synthesized branch samples Leo Yan
2026-06-11 14:50 ` [PATCH v8 2/8] perf cs-etm: Decode ETE exception packets Leo Yan
2026-06-11 14:50 ` [PATCH v8 3/8] perf cs-etm: Refactor instruction size handling Leo Yan
2026-06-11 14:50 ` [PATCH v8 4/8] perf cs-etm: Use thread-stack for last branch entries Leo Yan
2026-06-11 17:18 ` sashiko-bot
2026-06-16 14:16 ` Leo Yan [this message]
2026-06-11 14:50 ` [PATCH v8 5/8] perf cs-etm: Flush thread stacks after decoder reset Leo Yan
2026-06-11 15:06 ` sashiko-bot
2026-06-11 18:00 ` Leo Yan
2026-06-11 18:06 ` Leo Yan
2026-06-11 14:50 ` [PATCH v8 6/8] perf cs-etm: Support call indentation Leo Yan
2026-06-11 15:11 ` sashiko-bot
2026-06-11 14:50 ` [PATCH v8 7/8] perf cs-etm: Synthesize callchains for instruction samples Leo Yan
2026-06-11 15:05 ` sashiko-bot
2026-06-11 14:50 ` [PATCH v8 8/8] perf test: Add Arm CoreSight callchain test Leo Yan
2026-06-11 15:06 ` James Clark
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=20260616141656.GA31870@e132581.arm.com \
--to=leo.yan@arm.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