* [PATCH] perf trace: Fix heap overflow when -e expands a syscall alias
@ 2026-12-02 15:58 ` Anh Nguyen Hoang via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Anh Nguyen Hoang @ 2026-12-02 15:58 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
linux-perf-users, linux-kernel, Anh Nguyen Hoang
trace__parse_events_option() splits the -e argument into a list of
syscalls and a list of other events. Both lists are allocated with
strlen(str) + 1 bytes, which is enough only as long as every name copied
into them is a piece of the argument.
That stopped being true when the syscall alias lookup was added: a name
that is not in the syscall table but matches an alias in syscall_fmts[]
is replaced with the canonical name, which can be longer than what the
user typed: "pread" becomes "preadv", "umount" becomes "umount2" and
"fstatat" becomes "newfstatat". The strcpy() and sprintf() calls then
write past the end of the allocation.
Short overruns land in the allocator's padding and go unnoticed, so the
visible effect depends on the length of the argument. On x86_64 with a
normal perf build:
$ perf trace -e open,close,read,fstatat true
double free or corruption (!prev)
Aborted
With perf built with -fsanitize=address the overflow is reported
directly, e.g. for "perf trace -e fstatat true":
ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 11 [...] in trace__parse_events_option
Build the lists from the resolved names instead of using a buffer sized
from the argument: strdup() the first name and asprintf() each further
one onto the list.
With the change perf trace with the -e list above traces and prints
the newfstatat() calls, and the sanitizer no longer reports this
overflow.
Found by an automated code-checking tool.
Fixes: f932184e282f ("perf trace: Consider syscall aliases too")
Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
---
Built with make -C tools/perf on x86_64 (this tree and linux-next
20261201), default flags and -fsanitize=address; no new warnings.
Before: ASan reports the overflow for -e fstatat, umount or pread and
most lists holding them; the default build aborts for some list lengths,
also as root in a QEMU guest.
After: no report in this function, no such abort; the guest traces
newfstatat(), umount2() and preadv().
Not fixed here: a separate, older overflow in
trace__validate_ev_qualifier() when a glob is followed by more names,
e.g. -e 'newfstatat,*stat*'.
Testing:
- checkpatch.pl --strict: no errors or warnings.
This patch was drafted with AI assistance (Claude, claude-fable-5-2).
---
tools/perf/builtin-trace.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c08f2c3a8128..d5604a9ee206 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -5579,7 +5579,7 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
struct trace *trace = (struct trace *)opt->value;
const char *s;
char *strd, *sep = NULL, *lists[2] = { NULL, NULL, };
- int len = strlen(str) + 1, err = -1, list, idx;
+ int err = -1, list, idx;
char *strace_groups_dir = system_path(STRACE_GROUPS_DIR);
char group_name[PATH_MAX];
const struct syscall_fmt *fmt;
@@ -5619,12 +5619,16 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
}
do_concat:
if (lists[list]) {
- sprintf(lists[list] + strlen(lists[list]), ",%s", s);
+ char *tmp;
+
+ if (asprintf(&tmp, "%s,%s", lists[list], s) < 0)
+ goto out;
+ free(lists[list]);
+ lists[list] = tmp;
} else {
- lists[list] = malloc(len);
+ lists[list] = strdup(s);
if (lists[list] == NULL)
goto out;
- strcpy(lists[list], s);
}
if (!sep)
---
base-commit: 419442c00c667d33e27db4fef9733fa966e6a149
change-id: 20261202-kbug-l947-d9656b8b44cc
Best regards,
--
Anh Nguyen Hoang <anhnh.4work@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] perf trace: Fix heap overflow when -e expands a syscall alias
@ 2026-12-02 15:58 ` Anh Nguyen Hoang via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Anh Nguyen Hoang via B4 Relay @ 2026-12-02 15:58 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
linux-perf-users, linux-kernel, Anh Nguyen Hoang
From: Anh Nguyen Hoang <anhnh.4work@gmail.com>
trace__parse_events_option() splits the -e argument into a list of
syscalls and a list of other events. Both lists are allocated with
strlen(str) + 1 bytes, which is enough only as long as every name copied
into them is a piece of the argument.
That stopped being true when the syscall alias lookup was added: a name
that is not in the syscall table but matches an alias in syscall_fmts[]
is replaced with the canonical name, which can be longer than what the
user typed: "pread" becomes "preadv", "umount" becomes "umount2" and
"fstatat" becomes "newfstatat". The strcpy() and sprintf() calls then
write past the end of the allocation.
Short overruns land in the allocator's padding and go unnoticed, so the
visible effect depends on the length of the argument. On x86_64 with a
normal perf build:
$ perf trace -e open,close,read,fstatat true
double free or corruption (!prev)
Aborted
With perf built with -fsanitize=address the overflow is reported
directly, e.g. for "perf trace -e fstatat true":
ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 11 [...] in trace__parse_events_option
Build the lists from the resolved names instead of using a buffer sized
from the argument: strdup() the first name and asprintf() each further
one onto the list.
With the change perf trace with the -e list above traces and prints
the newfstatat() calls, and the sanitizer no longer reports this
overflow.
Found by an automated code-checking tool.
Fixes: f932184e282f ("perf trace: Consider syscall aliases too")
Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
---
Built with make -C tools/perf on x86_64 (this tree and linux-next
20261201), default flags and -fsanitize=address; no new warnings.
Before: ASan reports the overflow for -e fstatat, umount or pread and
most lists holding them; the default build aborts for some list lengths,
also as root in a QEMU guest.
After: no report in this function, no such abort; the guest traces
newfstatat(), umount2() and preadv().
Not fixed here: a separate, older overflow in
trace__validate_ev_qualifier() when a glob is followed by more names,
e.g. -e 'newfstatat,*stat*'.
Testing:
- checkpatch.pl --strict: no errors or warnings.
This patch was drafted with AI assistance (Claude, claude-fable-5-2).
---
tools/perf/builtin-trace.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c08f2c3a8128..d5604a9ee206 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -5579,7 +5579,7 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
struct trace *trace = (struct trace *)opt->value;
const char *s;
char *strd, *sep = NULL, *lists[2] = { NULL, NULL, };
- int len = strlen(str) + 1, err = -1, list, idx;
+ int err = -1, list, idx;
char *strace_groups_dir = system_path(STRACE_GROUPS_DIR);
char group_name[PATH_MAX];
const struct syscall_fmt *fmt;
@@ -5619,12 +5619,16 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
}
do_concat:
if (lists[list]) {
- sprintf(lists[list] + strlen(lists[list]), ",%s", s);
+ char *tmp;
+
+ if (asprintf(&tmp, "%s,%s", lists[list], s) < 0)
+ goto out;
+ free(lists[list]);
+ lists[list] = tmp;
} else {
- lists[list] = malloc(len);
+ lists[list] = strdup(s);
if (lists[list] == NULL)
goto out;
- strcpy(lists[list], s);
}
if (!sep)
---
base-commit: 419442c00c667d33e27db4fef9733fa966e6a149
change-id: 20261202-kbug-l947-d9656b8b44cc
Best regards,
--
Anh Nguyen Hoang <anhnh.4work@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf trace: Fix heap overflow when -e expands a syscall alias
2026-12-02 15:58 ` Anh Nguyen Hoang via B4 Relay
(?)
@ 2026-12-02 16:05 ` sashiko-bot
-1 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-02 16:05 UTC (permalink / raw)
To: Anh Nguyen Hoang; +Cc: linux-perf-users
> From: Anh Nguyen Hoang <anhnh.4work@gmail.com>
>
> trace__parse_events_option() splits the -e argument into a list of
> syscalls and a list of other events. Both lists are allocated with
> strlen(str) + 1 bytes, which is enough only as long as every name copied
> into them is a piece of the argument.
>
> That stopped being true when the syscall alias lookup was added: a name
> that is not in the syscall table but matches an alias in syscall_fmts[]
> is replaced with the canonical name, which can be longer than what the
> user typed: "pread" becomes "preadv", "umount" becomes "umount2" and
> "fstatat" becomes "newfstatat". The strcpy() and sprintf() calls then
> write past the end of the allocation.
>
> Short overruns land in the allocator's padding and go unnoticed, so the
> [ ... ]
>
> Found by an automated code-checking tool.
>
> Fixes: f932184e282f ("perf trace: Consider syscall aliases too")
> Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-kbug-l947-v1-1-9c324b56cea5@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-02 16:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 15:58 [PATCH] perf trace: Fix heap overflow when -e expands a syscall alias Anh Nguyen Hoang
2026-12-02 15:58 ` Anh Nguyen Hoang via B4 Relay
2026-12-02 16:05 ` sashiko-bot
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.