Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dominik Maier" <dmnk@google.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v3] tracing: Bound synthetic event dynamic string and stack stores to reserved size
Date: Thu, 03 Dec 2026 02:24:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-246990@kernel.org> (raw)
In-Reply-To: <20261203020420.3573008-1-dmnk@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing: unhandled is_stack fields in
  synth_event_trace_array()
--

commit 60ba01049fe709a42cf69d5ea5a710f9f24b88c0
Author: Dominik Maier <dmnk@google.com>

tracing: Bound synthetic event dynamic string and stack stores to reserved size

This commit bounds dynamic string and stacktrace copies in synthetic
events to the reserved ring-buffer space, ensures dynamic strings are
always NUL-terminated, and guards readers against empty dynamic fields
and excessive stack depths.

> diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
> index e2870212e58d4..ba9ee84cba036 100644
> --- a/kernel/trace/trace_events_synth.c
> +++ b/kernel/trace/trace_events_synth.c

[ ... ]

> @@ -1925,7 +1973,7 @@ EXPORT_SYMBOL_GPL(synth_event_trace);
>  int synth_event_trace_array(struct trace_event_file *file, u64 *vals,
>  			    unsigned int n_vals)
>  {
> -	unsigned int i, n_u64, field_pos, len, data_size = 0;
> +	unsigned int i, n_u64, field_pos, len, maxlen, rem_strings, data_size = 0;
>  	struct synth_event_trace_state state;
>  	char *str_val;
>  	int ret;
> @@ -1939,10 +1987,12 @@ int synth_event_trace_array(struct trace_event_file *file, u64 *vals,
>  
>  	if (state.event->n_dynamic_fields) {
>  		for (i = 0; i < state.event->n_dynamic_fields; i++) {
> +			if (state.event->dynamic_fields[i]->is_stack)
> +				continue;
> +
>  			field_pos = state.event->dynamic_fields[i]->field_pos;
>  			str_val = (char *)(long)vals[field_pos];
> -			len = strlen(str_val) + 1;
> -			data_size += len;
> +			data_size += max(fetch_store_strlen((unsigned long)str_val), 1);
>  		}
>  	}
>  
> @@ -1955,16 +2005,23 @@ int synth_event_trace_array(struct trace_event_file *file, u64 *vals,
>  		goto out;
>  	}
>  
> +	maxlen = data_size;
> +	rem_strings = state.event->n_dynamic_strings;
>  	data_size = 0;
>  
>  	for (i = 0, n_u64 = 0; i < state.event->n_fields; i++) {
>  		if (state.event->fields[i]->is_string) {
>  			char *str_val = (char *)(long)vals[i];
> +			unsigned int str_max = 0;
> +
> +			if (state.event->fields[i]->is_dynamic)
> +				str_max = synth_dyn_budget(maxlen, --rem_strings);
>  
>  			len = trace_string(state.entry, state.event, str_val,
>  					   state.event->fields[i]->is_dynamic,
> -					   data_size, &n_u64);
> +					   data_size, str_max, &n_u64);
>  			data_size += len; /* only dynamic string increments */
> +			maxlen -= len;
>  		} else {
>  			struct synth_field *field = state.event->fields[i];
>  			u64 val = vals[i];

[Severity: Medium]
Can an is_stack field in synth_event_trace_array() or synth_event_trace()
corrupt state.entry->fields[n_u64].as_dynamic and trigger an out-of-bounds
read?

Skipping is_stack fields in the reservation loop reserves zero dynamic
bytes for them, but the field-writing loop below has no is_stack branch
and falls into the scalar switch, where field->size == sizeof(u64) writes
vals[i] into state.entry->fields[n_u64].as_u64.  That overwrites
as_dynamic.offset and as_dynamic.len with raw bits from vals[i], so
print_synth_event() and hist_field_stack() read past the end of the ring
buffer entry.

Should synth_event_trace_array() and synth_event_trace() either reserve
and store stack fields via synth_stack_size() and trace_stack(), or
reject events with is_stack fields with -ENOTSUPP like
synth_event_trace_start()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203020420.3573008-1-dmnk@google.com?part=1

      reply	other threads:[~2026-12-03  2:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  2:04 [PATCH v3] tracing: Bound synthetic event dynamic string and stack stores to reserved size Dominik Maier
2026-12-03  2:24 ` 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-246990@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