From: sashiko-bot@kernel.org
To: "Weiming Shi" <bestswngs@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH perf/core] perf: Save callchain->nr in perf_sample_data
Date: Sat, 05 Dec 2026 17:29:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-251768@kernel.org> (raw)
In-Reply-To: <20261205170903.4178905-2-bestswngs@gmail.com>
> get_perf_callchain() releases the per-CPU recursion slot via
> put_callchain_entry() before returning, so a same-context callchain taker
> (e.g. a kprobe or BPF tracing program) on the same CPU can reuse the
> entry and overwrite entry->nr.
>
> perf_sample_save_callchain() folds data->callchain->nr into data->dyn_size
> for ring-buffer reservation and discards the count, while
> perf_output_sample() re-reads data->callchain->nr without READ_ONCE() to
> size __output_copy(). A rewrite between the two reads either writes past
> header->size into neighboring ring-buffer records or under-writes and
> corrupts record framing. For example, with a kprobe perf event on
> perf_output_copy() taking a callchain in the same hardirq context:
>
> header->size = 48 bytes (reserved nr = 2)
> copied = 120 bytes (copied nr = 11, +72 bytes past header->size)
>
> Read data->callchain->nr once with READ_ONCE() in
> perf_sample_save_callchain(), store it in data->callchain_nr (which fits
> in existing trailing padding of struct perf_sample_data), and use that
> cached count in perf_output_sample() to emit nr and copy
> data->callchain->ip.
>
> Fixes: 5622f295b53f ("x86, perf_counter, bts: Optimize BTS overflow handling")
> Cc: stable@vger.kernel.org
> Reported-by: <co+a3fa2401636b2e85@bugs.sh>
> Assisted-by: LLM
> Signed-off-by: Weiming Shi <bestswngs@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205170903.4178905-2-bestswngs@gmail.com?part=1
prev parent reply other threads:[~2026-12-05 17:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 17:09 [PATCH perf/core] perf: Save callchain->nr in perf_sample_data Weiming Shi
2026-12-05 17:29 ` 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=sashiko-outbox-251768@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bestswngs@gmail.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