From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/9] perf machine: Use snprintf() for guestmount path construction
Date: Tue, 16 Jun 2026 01:23:11 +0000 [thread overview]
Message-ID: <20260616012311.AEC101F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616010834.37618-3-acme@kernel.org>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Silent path truncation due to unchecked snprintf return value can cause data corruption.
- [Medium] The patch claims to fix get_kernel_version() by switching it to snprintf(), but the provided code changes do not modify this function.
Pre-existing issues:
- [High] Unchecked failure of strlist__new() leads to a NULL pointer dereference in strlist__has_entry().
- [High] Unchecked failure of machine__findnew_thread() leads to a NULL pointer dereference.
--
commit 95810f32b8a216c1bb3b9a1565b24c27cfec9f8d
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
perf machine: Use snprintf() for guestmount path construction
This commit updates machines__findnew() and
machines__create_guest_kernel_maps() to use snprintf() instead of sprintf()
for constructing guestmount paths. This change prevents stack buffer
overflows caused by unchecked user configuration strings.
> machines__findnew(), machines__create_guest_kernel_maps(), and
> get_kernel_version() use sprintf() to build paths by prepending
> symbol_conf.guestmount or root_dir. All write into PATH_MAX stack
[Severity: Medium]
Is the commit message description for get_kernel_version() accurate?
The commit message states that get_kernel_version() uses sprintf() and is
being switched to snprintf() to prevent overflow. However, the provided code
changes do not modify this function. It appears get_kernel_version() already
uses snprintf() in the baseline.
[ ... ]
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -333,7 +333,7 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid)
> if ((pid != HOST_KERNEL_ID) &&
> (pid != DEFAULT_GUEST_KERNEL_ID) &&
> (symbol_conf.guestmount)) {
> - sprintf(path, "%s/%d", symbol_conf.guestmount, pid);
> + snprintf(path, sizeof(path), "%s/%d", symbol_conf.guestmount, pid);
[Severity: High]
Could this unchecked snprintf() lead to silent data corruption?
If symbol_conf.guestmount is long enough, snprintf() could silently truncate
the trailing digits of the guest PID. If the resulting shorter PID
coincidentally exists (e.g., guestmount/12 instead of guestmount/1234),
access() will falsely succeed. This would assign the wrong root_dir to the
guest, silently corrupting profiling data by attributing maps to the wrong
guest.
> if (access(path, R_OK)) {
> static struct strlist *seen;
[Severity: High]
This is a pre-existing issue, but does this code handle a failed allocation
correctly?
If access() fails, a static seen list is initialized:
tools/perf/util/machine.c:machines__findnew() {
...
if (!seen)
seen = strlist__new(NULL, NULL);
if (!strlist__has_entry(seen, path)) {
...
}
If strlist__new() fails due to out-of-memory, it returns a null pointer. The
immediate subsequent check !strlist__has_entry(seen, path) unconditionally
passes this null pointer, which causes an immediate segmentation fault when
accessing underlying structures.
[ ... ]
> @@ -1260,9 +1260,9 @@ int machines__create_guest_kernel_maps(struct machines *machines)
> namelist[i]->d_name);
> continue;
> }
> - sprintf(path, "%s/%s/proc/kallsyms",
> - symbol_conf.guestmount,
> - namelist[i]->d_name);
> + snprintf(path, sizeof(path), "%s/%s/proc/kallsyms",
> + symbol_conf.guestmount,
> + namelist[i]->d_name);
[Severity: High]
Could an unchecked snprintf() here also result in a falsely successful
access() check?
Similar to the issue above, if the path is truncated, it might inadvertently
match an existing shorter path instead of properly failing the access() test.
[ ... ]
While reviewing this file, I noticed another pre-existing issue unrelated to
the patch diff:
[Severity: High]
This isn't a bug introduced by this patch, but can machine__findnew_thread()
return a null pointer here?
tools/perf/util/machine.c:machine__process_fork_event() {
struct thread *parent = machine__findnew_thread(machine,
event->fork.ppid,
event->fork.ptid);
...
if (thread__pid(parent) != (pid_t)event->fork.ppid) {
...
}
If memory allocation fails within thread creation, machine__findnew_thread()
returns a null pointer. Unconditionally evaluating thread__pid(parent) accesses
fields of the null object, which results in a segmentation fault.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260616010834.37618-1-acme@kernel.org?part=2
next prev parent reply other threads:[~2026-06-16 1:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 1:08 [PATCHES v3 0/9] perf tools: Fix pre-existing bugs in machine, cs-etm, c2c, bpf, and dso Arnaldo Carvalho de Melo
2026-06-16 1:08 ` [PATCH 1/9] perf machine: Propagate machine__init() error to callers Arnaldo Carvalho de Melo
2026-06-16 1:08 ` [PATCH 2/9] perf machine: Use snprintf() for guestmount path construction Arnaldo Carvalho de Melo
2026-06-16 1:23 ` sashiko-bot [this message]
2026-06-16 1:08 ` [PATCH 3/9] perf cs-etm: Validate num_cpu before metadata allocation Arnaldo Carvalho de Melo
2026-06-16 1:21 ` sashiko-bot
2026-06-16 1:08 ` [PATCH 4/9] perf cs-etm: Require full global header in auxtrace_info size check Arnaldo Carvalho de Melo
2026-06-16 1:08 ` [PATCH 5/9] perf cs-etm: Bounds-check CPU in cs_etm__get_queue() Arnaldo Carvalho de Melo
2026-06-16 1:28 ` sashiko-bot
2026-06-16 1:08 ` [PATCH 6/9] perf c2c: Free format list entries when c2c_hists__init() fails Arnaldo Carvalho de Melo
2026-06-16 1:23 ` sashiko-bot
2026-06-16 1:08 ` [PATCH 7/9] perf c2c: Fix hist entry and format list leaks in c2c_he_free() Arnaldo Carvalho de Melo
2026-06-16 1:08 ` [PATCH 8/9] perf bpf: Validate array presence before casting BPF prog info pointers Arnaldo Carvalho de Melo
2026-06-16 1:08 ` [PATCH 9/9] perf dso: Set standard errno on decompression failure Arnaldo Carvalho de Melo
2026-06-16 1:38 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-06-16 2:27 [PATCHES v4 0/9] perf tools: Fix pre-existing bugs in machine, cs-etm, c2c, bpf, and dso Arnaldo Carvalho de Melo
2026-06-16 2:27 ` [PATCH 2/9] perf machine: Use snprintf() for guestmount path construction Arnaldo Carvalho de Melo
2026-06-16 2:40 ` sashiko-bot
2026-06-15 22:32 [PATCHES v2 0/9] perf tools: Fix pre-existing bugs in machine, cs-etm, c2c, bpf, and dso Arnaldo Carvalho de Melo
2026-06-15 22:32 ` [PATCH 2/9] perf machine: Use snprintf() for guestmount path construction Arnaldo Carvalho de Melo
2026-06-15 21:36 [PATCHES v1 0/9] perf tools: Fix pre-existing bugs in machine, cs-etm, c2c, bpf, and dso Arnaldo Carvalho de Melo
2026-06-15 21:36 ` [PATCH 2/9] perf machine: Use snprintf() for guestmount path construction Arnaldo Carvalho de Melo
2026-06-15 21:51 ` 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=20260616012311.AEC101F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acme@kernel.org \
--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 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.