From: sashiko-bot@kernel.org
To: "Aaron Tomlin" <atomlin@atomlin.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH perf-tools-next v8 3/6] perf symbol: Introduce vmlinux_path__find() helper
Date: Sun, 18 Oct 2026 02:45:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-175888@kernel.org> (raw)
In-Reply-To: <20261018023753.584873-4-atomlin@atomlin.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf symbol: heap overflow in vmlinux_path__init() after vmlinux_path__find()
--
commit 075bbaee1dd0bb499313531ce795ad3e9b4f107b
Author: Aaron Tomlin <atomlin@atomlin.com>
perf symbol: Introduce vmlinux_path__find() helper
This commit introduces vmlinux_path__find() to search through the configured
vmlinux_path entries (or symbol_conf.vmlinux_name if set) and return the path
to the first readable vmlinux file.
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index b61a574ce9a30..a0fc430be13ae 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -2372,6 +2372,36 @@ static int vmlinux_path__init(struct perf_env *env)
> return -1;
> }
>
> +/**
> + * vmlinux_path__find - Locate the first accessible vmlinux file
> + *
> + * Check symbol_conf.vmlinux_name first if set, then search through the
> + * initialized paths in vmlinux_path.
> + *
> + * Return: A pointer to the path of the first readable vmlinux file, or NULL if
> + * none is accessible.
> + */
> +const char *vmlinux_path__find(void)
> +{
> + int i;
> +
> + if (symbol_conf.vmlinux_name && access(symbol_conf.vmlinux_name, R_OK) == 0)
> + return symbol_conf.vmlinux_name;
> +
> + if (!vmlinux_path) {
> + symbol_conf.try_vmlinux_path = true;
> + if (vmlinux_path__init(NULL) < 0)
> + return NULL;
> + }
[Severity: Medium]
Can calling vmlinux_path__find() before symbol__init() cause
vmlinux_path__init() to overflow vmlinux_path[] and leak memory?
When vmlinux_path__find() is called prior to symbol__init(), vmlinux_path is
NULL and symbol_conf.initialized is false. vmlinux_path__find() sets
symbol_conf.try_vmlinux_path = true and calls vmlinux_path__init(NULL), which
allocates the 7-entry vmlinux_path array and populates it via
vmlinux_path__add(), advancing vmlinux_path__nr_entries to 7 (or 2 if
symbol_conf.symfs[0] != 0):
tools/perf/util/symbol.c:vmlinux_path__add() {
vmlinux_path[vmlinux_path__nr_entries] = strdup(new_entry);
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
return -1;
++vmlinux_path__nr_entries;
return 0;
}
When symbol__init() is subsequently called, symbol_conf.initialized is still
false and symbol_conf.try_vmlinux_path is true, so symbol__init() invokes
vmlinux_path__init(env) a second time:
tools/perf/util/symbol.c:symbol__init() {
...
if (symbol_conf.try_vmlinux_path && vmlinux_path__init(env) < 0)
return -1;
...
}
Because vmlinux_path__init() neither frees an existing vmlinux_path nor
resets vmlinux_path__nr_entries to 0:
tools/perf/util/symbol.c:vmlinux_path__init() {
...
vmlinux_path = malloc(sizeof(char *) * (ARRAY_SIZE(vmlinux_paths) +
ARRAY_SIZE(vmlinux_paths_upd)));
if (vmlinux_path == NULL)
return -1;
for (i = 0; i < ARRAY_SIZE(vmlinux_paths); i++)
if (vmlinux_path__add(vmlinux_paths[i]) < 0)
goto out_fail;
...
}
Doesn't the second call overwrite vmlinux_path with a new 7-entry buffer
(leaking the initial array and its strdup() strings) and then write the new
strdup() pointers starting at vmlinux_path[7] (or vmlinux_path[2]),
overflowing the heap buffer while leaving vmlinux_path[0..6] uninitialized
for dso__load_vmlinux_path() and vmlinux_path__exit()?
Additionally, if a caller invokes vmlinux_path__find() and skips
symbol__init(), symbol_conf.initialized remains false, so symbol__exit() will
return early without calling vmlinux_path__exit() to free vmlinux_path:
tools/perf/util/symbol.c:symbol__exit() {
if (!symbol_conf.initialized)
return;
...
vmlinux_path__exit();
...
}
> +
> + for (i = 0; i < vmlinux_path__nr_entries; ++i) {
> + if (access(vmlinux_path[i], R_OK) == 0)
> + return vmlinux_path[i];
> + }
> +
> + return NULL;
> +}
[ ... ]
>
> --
> 2.51.2
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261018023753.584873-1-atomlin@atomlin.com?part=3
next prev parent reply other threads:[~2026-10-18 2:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 2:37 [PATCH perf-tools-next v8 0/6] perf ftrace: Support inlined functions and display enhancements in function graph tracer Aaron Tomlin
2026-10-18 2:37 ` [PATCH perf-tools-next v8 1/6] perf ftrace: Optimise __cmd_ftrace() stack frame with strbuf streaming Aaron Tomlin
2026-10-18 2:49 ` sashiko-bot
2026-10-18 2:37 ` [PATCH perf-tools-next v8 2/6] perf ftrace: Support filtering return address comments Aaron Tomlin
2026-10-18 2:46 ` sashiko-bot
2026-10-18 2:37 ` [PATCH perf-tools-next v8 3/6] perf symbol: Introduce vmlinux_path__find() helper Aaron Tomlin
2026-10-18 2:45 ` sashiko-bot [this message]
2026-10-18 2:37 ` [PATCH perf-tools-next v8 4/6] perf ftrace: Support display of inlined functions in function graph tracer Aaron Tomlin
2026-10-18 3:00 ` sashiko-bot
2026-10-18 2:37 ` [PATCH perf-tools-next v8 5/6] perf ftrace: Support omitting execution duration " Aaron Tomlin
2026-10-18 2:51 ` sashiko-bot
2026-10-18 2:37 ` [PATCH perf-tools-next v8 6/6] perf ftrace: Filter extraneous functions " Aaron Tomlin
2026-10-18 2:55 ` 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=sashiko-outbox-175888@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=atomlin@atomlin.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 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.