From: sashiko-bot@kernel.org
To: "Aaron Tomlin" <atomlin@atomlin.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH perf-tools-next v6 4/5] perf trace: Enhance BTF type formatting to symbolise kernel function pointers
Date: Mon, 24 Aug 2026 13:49:59 +0000 [thread overview]
Message-ID: <20260824134959.98CFC1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260824133122.751733-5-atomlin@atomlin.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The `btf_struct_scnprintf` function fails to properly validate `augmented_arg->size` against buffer limits and is vulnerable to an integer overflow, leading to out-of-bounds memory access.
--
--- Patch [4]: [PATCH perf-tools-next v6 4/5] perf trace: Enhance BTF type formatting to symbolise kernel function pointers ---
commit c939026eded5d8aaf079b56970d0829b2a8ad559
Author: Aaron Tomlin <atomlin@atomlin.com>
perf trace: Enhance BTF type formatting to symbolise kernel function pointers
This commit introduces btf_is_func_ptr() to identify function pointers in BTF
types. It caches the BTF type in syscall_arg_fmt and routes function pointers
to syscall_arg__scnprintf_ksym() during BTF pretty-printing.
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index f6ab7dabfa4c3..d0089230dc5d4 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
[ ... ]
> @@ -1077,14 +1126,19 @@ static size_t btf_struct_scnprintf(const struct btf_type *type, struct btf *btf,
> .bf = bf,
> .size = size,
> };
> - struct augmented_arg *augmented_arg = arg->augmented.args;
> + struct augmented_arg *augmented_arg;
> int type_id = arg->fmt->type_id, consumed;
> struct btf_dump *btf_dump;
>
> LIBBPF_OPTS(btf_dump_opts, dump_opts);
> LIBBPF_OPTS(btf_dump_type_data_opts, dump_data_opts);
>
> - if (arg == NULL || arg->augmented.args == NULL)
> + if (arg == NULL || arg->augmented.args == NULL || arg->augmented.size <= 0 ||
> + arg->fmt == NULL || !arg->fmt->from_user)
> + return 0;
> +
> + augmented_arg = arg->augmented.args;
> + if (augmented_arg->size <= 0)
> return 0;
>
> dump_data_opts.compact = true;
> @@ -1097,8 +1151,10 @@ static size_t btf_struct_scnprintf(const struct btf_type *type, struct btf *btf,
> /* pretty print the struct data here */
> if (btf_dump__dump_type_data(btf_dump, type_id,
> arg->augmented.args->value,
> - type->size, &dump_data_opts) <= 0)
> + type->size, &dump_data_opts) <= 0) {
> + btf_dump__free(btf_dump);
> return 0;
> + }
>
> consumed = sizeof(*augmented_arg) + augmented_arg->size;
> arg->augmented.args = ((void *)arg->augmented.args) + consumed;
> arg->augmented.size -= consumed;
[Severity: High]
This is a pre-existing issue, but does btf_struct_scnprintf() need upper bound
checks for augmented_arg->size and type->size?
When parsing ring buffer data from a potentially untrusted perf.data file,
augmented_arg->size is read directly from the buffer. While this patch adds
a check for augmented_arg->size <= 0, it doesn't enforce an upper bound
against the total available buffer (arg->augmented.size >=
sizeof(*augmented_arg) + augmented_arg->size).
Additionally, type->size from BTF is passed to btf_dump__dump_type_data()
without verifying that the available payload is large enough
(arg->augmented.size - sizeof(*augmented_arg) >= type->size). Could this lead
to out-of-bounds reads if the BTF struct is large but the captured payload
is truncated?
Finally, if a crafted file has an extremely large augmented_arg->size (e.g.,
INT_MAX), could the calculation for consumed overflow the signed int variable
and corrupt the augmented parsing state?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260824133122.751733-1-atomlin@atomlin.com?part=4
next prev parent reply other threads:[~2026-08-24 13:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 13:31 [PATCH perf-tools-next v6 0/5] perf trace: Symbolise kernel virtual addresses and function pointers Aaron Tomlin
2026-08-24 13:31 ` [PATCH perf-tools-next v6 1/5] perf trace: Fix error checking in btf_struct_scnprintf() Aaron Tomlin
2026-08-24 13:40 ` sashiko-bot
2026-09-04 21:17 ` Arnaldo Carvalho de Melo
2026-09-04 22:14 ` Aaron Tomlin
2026-08-24 13:31 ` [PATCH perf-tools-next v6 2/5] perf trace: Introduce kernel symbol beautifier for virtual addresses Aaron Tomlin
2026-08-24 13:38 ` sashiko-bot
2026-08-24 13:31 ` [PATCH perf-tools-next v6 3/5] perf trace: Auto-assign kernel symbol beautifier to function pointer fields Aaron Tomlin
2026-08-24 13:39 ` sashiko-bot
2026-08-24 13:31 ` [PATCH perf-tools-next v6 4/5] perf trace: Enhance BTF type formatting to symbolise kernel function pointers Aaron Tomlin
2026-08-24 13:49 ` sashiko-bot [this message]
2026-08-24 13:31 ` [PATCH perf-tools-next v6 5/5] perf tests: Add shell test for kernel symbol beautifier Aaron Tomlin
2026-08-24 13:38 ` sashiko-bot
2026-08-24 16:30 ` [PATCH perf-tools-next v6 0/5] perf trace: Symbolise kernel virtual addresses and function pointers Ian Rogers
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=20260824134959.98CFC1F00A3A@smtp.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.