From: sashiko-bot@kernel.org
To: "Dominik Maier" <dmnk@google.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tracing/synthetic: bound dynamic string and stack stores to reserved size
Date: Mon, 30 Nov 2026 16:22:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-241572@kernel.org> (raw)
In-Reply-To: <20261130160412.2637358-1-dmnk@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing/synthetic: out-of-bounds read on empty dynstring in
print_synth_event()
--
commit fd194d819ad6073b2273ec9552d1b33827c2073f
Author: Dominik Maier <dmnk@google.com>
tracing/synthetic: bound dynamic string and stack stores to reserved size
This commit bounds synthetic event dynamic string and stack trace stores
to the remaining reserved ring buffer budget and adds length and depth
guards to downstream histogram readers.
> diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
> index e2870212e58d4..4989b59473667 100644
> --- a/kernel/trace/trace_events_synth.c
> +++ b/kernel/trace/trace_events_synth.c
> @@ -424,11 +424,25 @@ static struct trace_event_functions synth_event_funcs = {
> .trace = print_synth_event
> };
>
> +static __always_inline unsigned int synth_stack_size(const long *stack)
> +{
> + unsigned long n_entries;
> +
> + if (!stack)
> + return 0;
> +
> + n_entries = min_t(unsigned long,
> + READ_ONCE(*(const unsigned long *)stack),
> + HIST_STACKTRACE_DEPTH);
> + return (n_entries + 1) * sizeof(unsigned long);
> +}
> +
> static unsigned int trace_string(struct synth_trace_event *entry,
> struct synth_event *event,
> char *str_val,
> bool is_dynamic,
> unsigned int data_size,
> + unsigned int maxlen,
> unsigned int *n_u64)
> {
> unsigned int len = 0;
> @@ -438,11 +452,12 @@ static unsigned int trace_string(struct synth_trace_event *entry,
> if (is_dynamic) {
> union trace_synth_field *data = &entry->fields[*n_u64];
>
> - len = fetch_store_strlen((unsigned long)str_val);
> data->as_dynamic.offset = struct_size(entry, fields, event->n_u64) + data_size;
> - data->as_dynamic.len = len;
> + data->as_dynamic.len = min_t(unsigned int, maxlen, MAX_STRING_SIZE);
>
> ret = fetch_store_string((unsigned long)str_val, &entry->fields[*n_u64], entry);
> + if (ret > 0)
> + len = ret;
>
> (*n_u64)++;
> } else {
[Severity: Medium]
Can print_synth_event() read out of bounds when formatting a dynamic
string with data->as_dynamic.len == 0?
If an earlier dynamic field grows between sizing and copying and consumes
the reserved budget, maxlen becomes 0 for a subsequent dynamic string.
trace_string() then sets data->as_dynamic.offset to the end of the
reserved entry and data->as_dynamic.len to 0, and fetch_store_string()
returns -ENOMEM without writing a NUL terminator. Unlike
hist_field_dynstring(), print_synth_event() passes
(char *)entry + data->as_dynamic.offset directly to trace_seq_printf()
without checking data->as_dynamic.len:
kernel/trace/trace_events_synth.c:print_synth_event() {
...
if (se->fields[i]->is_string) {
if (se->fields[i]->is_dynamic) {
union trace_synth_field *data = &entry->fields[n_u64];
trace_seq_printf(s, print_fmt, se->fields[i]->name,
(char *)entry + data->as_dynamic.offset,
i == se->n_fields - 1 ? "" : " ");
...
}
Reading the trace output (or formatting via tracepoint_printk) will then
read past the end of the reserved ring buffer entry. Checking
data->as_dynamic.len in print_synth_event() and falling back to "" when it
is 0 (matching hist_field_dynstring()) would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130160412.2637358-1-dmnk@google.com?part=1
prev parent reply other threads:[~2026-11-30 16:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 16:04 [PATCH v2] tracing/synthetic: bound dynamic string and stack stores to reserved size Dominik Maier
2026-11-30 16:22 ` sashiko-bot [this message]
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-241572@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmnk@google.com \
--cc=linux-trace-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox