All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Falcon" <thomas.falcon@intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v7 5/6] perf tools: Show memory region in perf-script subcommand
Date: Wed, 09 Sep 2026 16:17:11 +0000	[thread overview]
Message-ID: <20260909161711.DFA981F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260909160218.174928-6-thomas.falcon@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Integer underflow leading to stack buffer overflow if the accumulated string length reaches the buffer size in `perf_mem__region_scnprintf`.
- [Low] Unnecessary full header inclusion of "session.h" in mem-events.h instead of using a forward declaration.
--

commit f7491b8d4beca72ae600f38adac9d0669b182411
Author: Dapeng Mi <dapeng1.mi@linux.intel.com>

perf tools: Show memory region in perf-script subcommand

Show the memory region in perf-script subcommand. Memory region is found
in the mem_region field of the memory information data source.

Link: https://lore.kernel.org/all/20260114011750.350569-1-dapeng1.mi@linux.intel.com/

> diff --git a/tools/perf/util/mem-events.h b/tools/perf/util/mem-events.h
> index daa22748f9fea..4ebb8109fc3c4 100644
> --- a/tools/perf/util/mem-events.h
> +++ b/tools/perf/util/mem-events.h
> @@ -4,6 +4,7 @@
>  
>  #include <stdbool.h>
>  #include <linux/types.h>
> +#include "session.h"

[Severity: Low]
Does this code introduce unnecessary namespace pollution and risk musl 
compilation failures? The subsystem guidelines recommend using a forward 
declaration for struct perf_session instead of a full header inclusion 
when only structure pointer handles are referenced.

[ ... ]

> diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
> index 4fd48fd200552..8ce4996cad8d3 100644
> --- a/tools/perf/util/mem-events.c
> +++ b/tools/perf/util/mem-events.c
[ ... ]
> +static int perf_mem__region_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
>  {
> +	size_t l = 0;
> +	u64 mem = PERF_MEM_REGION_NA;
> +
> +	sz -= 1; /* -1 for null termination */
> +	out[0] = '\0';

[Severity: Medium]
Can this lead to an integer underflow and a stack buffer overflow?

In perf_script__meminfo_scnprintf, the characters written are accumulated 
in i. If i grows larger than or equal to the initial buffer size (e.g. 200) 
due to previous print operations, sz - i passed to 
perf_mem__region_scnprintf evaluates to 0. 

When sz is 0 in perf_mem__region_scnprintf, sz -= 1 underflows to the 
maximum unsigned size. The subsequent out[0] assignment writes 
out-of-bounds, and scnprintf receives the maximum size as its limit, which 
can cause a massive buffer overflow when parsing a complex perf.data file.

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909160218.174928-1-thomas.falcon@intel.com?part=5

  reply	other threads:[~2026-09-09 16:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 16:02 [PATCH v7 0/6] perf: Add support for memory region/range reporting Thomas Falcon
2026-09-09 16:02 ` [PATCH v7 1/6] perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf() Thomas Falcon
2026-09-09 16:12   ` sashiko-bot
2026-09-09 16:02 ` [PATCH v7 2/6] perf mem: Add support for printing PERF_MEM_LVLNUM_L0 Thomas Falcon
2026-09-09 16:10   ` sashiko-bot
2026-09-09 16:02 ` [PATCH v7 3/6] perf header: Support memory ranges Thomas Falcon
2026-09-09 16:15   ` sashiko-bot
2026-09-09 16:02 ` [PATCH v7 4/6] perf tools: Show memory region in perf-c2c subcommand Thomas Falcon
2026-09-09 16:13   ` sashiko-bot
2026-09-10  2:19   ` Mi, Dapeng
2026-09-09 16:02 ` [PATCH v7 5/6] perf tools: Show memory region in perf-script subcommand Thomas Falcon
2026-09-09 16:17   ` sashiko-bot [this message]
2026-09-10  2:22   ` Mi, Dapeng
2026-09-10 14:10     ` Arnaldo Carvalho de Melo
2026-09-09 16:02 ` [PATCH v7 6/6] perf c2c: print memory region data with stdio output Thomas Falcon
2026-09-09 16:12   ` sashiko-bot

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=20260909161711.DFA981F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=thomas.falcon@intel.com \
    /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.