From: "Falcon, Thomas" <thomas.falcon@intel.com>
To: "sashiko-reviews@lists.linux.dev" <sashiko-reviews@lists.linux.dev>
Cc: "linux-perf-users@vger.kernel.org" <linux-perf-users@vger.kernel.org>
Subject: Re: [PATCH v2 1/6] perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf()
Date: Mon, 27 Jul 2026 17:06:53 +0000 [thread overview]
Message-ID: <4f122ecf3db0de4cb39deb20f5e4e15f23c0c14f.camel@intel.com> (raw)
In-Reply-To: <20260714005200.80E5E1F000E9@smtp.kernel.org>
On Tue, 2026-07-14 at 00:51 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider:
>
> Pre-existing issues:
> - [High] Severe pre-existing stack buffer overflows and integer
> underflows in `perf_mem__*_scnprintf` functions due to unsafe
> `strcat` usage and missing bounds checks.
Since these are pre-existing issues, can they be handled in a separate
patch series?
Thanks,
Tom
> --
>
> --- Patch [1]: [PATCH v2 1/6] perf mem: Fix size tracking for
> mem_lvl's in perf_script__meminfo_scnprintf() ---
> commit cf8f02c307060f141740bb3567a69f77761e0f5f
> Author: Thomas Falcon <thomas.falcon@intel.com>
>
> perf mem: Fix size tracking for mem_lvl's in
> perf_script__meminfo_scnprintf()
>
> When printing memory info in perf script, the entire size of the
> buffer is passed to perf_mem__lvl_scnprintf() instead of the
> remaining
> size. Pass the remaining buffer size instead.
>
> > diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-
> > events.c
> > index 0b49fce251fcc..4e490f9cd3488 100644
> > --- a/tools/perf/util/mem-events.c
> > +++ b/tools/perf/util/mem-events.c
> > @@ -610,7 +610,7 @@ int perf_script__meminfo_scnprintf(char *out,
> > size_t sz, const struct mem_info *
> > i += scnprintf(out, sz, "|OP ");
> > i += perf_mem__op_scnprintf(out + i, sz - i, mem_info);
> > i += scnprintf(out + i, sz - i, "|LVL ");
> > - i += perf_mem__lvl_scnprintf(out + i, sz, mem_info);
> > + i += perf_mem__lvl_scnprintf(out + i, sz - i, mem_info);
>
> [Severity: High]
> This is a pre-existing issue, but does passing sz - i here risk an
> integer
> underflow and stack buffer overflow in the callee if the buffer is
> already
> full?
>
> If previous fields exhaust the buffer, sz - i can be 0 (or wrap
> around if
> i > sz). If 0 is passed to perf_mem__lvl_scnprintf(), the size
> decrement
> at the start of the function will underflow:
>
> tools/perf/util/mem-events.c:perf_mem__lvl_scnprintf() {
> sz -= 1; /* -1 for null termination */
> out[0] = '\0';
> ...
> strcat(out, "Remote ");
> }
>
> When sz underflows to SIZE_MAX, out[0] = '\0' writes out of bounds,
> and
> the unbounded strcat operations can corrupt the stack if a malformed
> or
> untrusted perf.data file sets multiple bits in data_src.
>
> Does this same unsafe pattern also exist in perf_mem__snp_scnprintf,
> perf_mem__tlb_scnprintf, and perf_mem__blk_scnprintf, which all start
> with the same sz -= 1 decrement?
>
> > i += scnprintf(out + i, sz - i, "|SNP ");
> > i += perf_mem__snp_scnprintf(out + i, sz - i, mem_info);
> > i += scnprintf(out + i, sz - i, "|TLB ");
>
next prev parent reply other threads:[~2026-07-27 17:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 0:43 [PATCH v2 0/6] perf: Add support for memory region/range reporting Thomas Falcon
2026-07-14 0:43 ` [PATCH v2 1/6] perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf() Thomas Falcon
2026-07-14 0:51 ` sashiko-bot
2026-07-27 17:06 ` Falcon, Thomas [this message]
2026-07-15 6:59 ` Mi, Dapeng
2026-07-14 0:43 ` [PATCH v2 2/6] perf mem: Add support for printing PERF_MEM_LVLNUM_L0 Thomas Falcon
2026-07-15 7:11 ` Mi, Dapeng
2026-07-14 0:43 ` [PATCH v2 3/6] perf tools: Show memory region in perf-c2c subcommand Thomas Falcon
2026-07-14 0:56 ` sashiko-bot
2026-07-27 16:37 ` Falcon, Thomas
2026-07-14 0:43 ` [PATCH v2 4/6] perf tools: Show memory region in perf-script subcommand Thomas Falcon
2026-07-14 0:59 ` sashiko-bot
2026-07-14 0:43 ` [PATCH v2 5/6] perf header: Support memory ranges Thomas Falcon
2026-07-14 0:43 ` [PATCH v2 6/6] perf c2c: print memory region data with stdio output Thomas Falcon
2026-07-14 0:57 ` sashiko-bot
2026-07-27 17:05 ` Falcon, Thomas
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=4f122ecf3db0de4cb39deb20f5e4e15f23c0c14f.camel@intel.com \
--to=thomas.falcon@intel.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