Linux Trace Kernel
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Dominik Maier <dmnk@google.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Tom Zanussi <zanussi@kernel.org>, Lee Jones <lee@kernel.org>,
	linux-trace-kernel@vger.kernel.org, dmnk+artist@google.com
Subject: Re: [PATCH v3] tracing: Bound synthetic event dynamic string and stack stores to reserved size
Date: Fri, 4 Dec 2026 15:32:06 -0500	[thread overview]
Message-ID: <20261204153206.6a180c94@gandalf.local.home> (raw)
In-Reply-To: <20261203020420.3573008-1-dmnk@google.com>

On Thu,  3 Dec 2026 02:04:20 +0000
Dominik Maier <dmnk@google.com> wrote:

> Synthetic events measure dynamic string and stack fields before
> reserving ring-buffer space, then copy from unlocked histogram variables
> without re-checking the reserved size.
> 
> If another CPU stores a longer string or deeper stack trace before the
> copy runs, trace_string() and trace_stack() write past the reserved
> entry and corrupt adjacent kernel memory. Truncated or empty dynamic
> fields can also cause out-of-bounds reads when formatting or keying
> events.
> 
> Reserve at least one NUL byte per dynamic string, bound string and stack
> copies to the remaining budget while NUL-terminating every string, and
> guard empty fields and stack depth in readers.
> 
> Fixes: bd82631d7ccd ("tracing: Add support for dynamic strings to synthetic events")
> Fixes: 00cf3d672a9d ("tracing: Allow synthetic events to pass around stacktraces")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dominik Maier <dmnk@google.com>
> ---
> v3:
> - Always NUL-terminate dynamic strings, guard zero-length strings in
>   print_synth_event(), and use "tracing: Bound ..." subject (Steven
>   Rostedt, Sashiko).
> - v2: https://lore.kernel.org/linux-trace-kernel/20261130160412.2637358-1-dmnk@google.com/
> - v1: https://lore.kernel.org/linux-trace-kernel/20261126035553.406453-1-dmnk@google.com/
> 
> Found with an AI-assisted code review tool (ARTIST) and verified in
> QEMU/KVM with KASAN, lockdep, and synth_event_gen_test.
> 
>  kernel/trace/trace_events_hist.c  |  10 ++-
>  kernel/trace/trace_events_synth.c | 141 +++++++++++++++++++++---------
>  kernel/trace/trace_synth.h        |   1 +
>  3 files changed, 109 insertions(+), 43 deletions(-)
> 
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index d4702ad..a3a093d 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -251,6 +251,9 @@ static u64 hist_field_dynstring(struct hist_field *hist_field,
>  	int str_loc = str_item & 0xffff;

Please add here:
	int str_len = str_item >> 16;

and use that, so we know what the hell that shift is for.

>  	char *addr = (char *)(event + str_loc);
>  
> +	if (!(str_item >> 16))
> +		return (u64)(unsigned long)"";
> +
>  	return (u64)(unsigned long)addr;
>  }
>  
> @@ -4384,10 +4387,14 @@ static u64 hist_field_stack(struct hist_field *hist_field,
>  			    struct ring_buffer_event *rbe,
>  			    void *event)
>  {
> +	static const unsigned long empty_stack;
>  	u32 str_item = *(u32 *)(event + hist_field->field->offset);
>  	int str_loc = str_item & 0xffff;

Same here.

-- Steve

>  	char *addr = (char *)(event + str_loc);
>  
> +	if ((str_item >> 16) < sizeof(unsigned long))
> +		return (u64)(unsigned long)&empty_stack;
> +
>  	return (u64)(unsigned long)addr;
>  }

      parent reply	other threads:[~2026-12-04 20:32 UTC|newest]

Thread overview: 4+ 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
2026-12-04 20:32   ` Steven Rostedt
2026-12-04 20:32 ` Steven Rostedt [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=20261204153206.6a180c94@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=dmnk+artist@google.com \
    --cc=dmnk@google.com \
    --cc=lee@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=zanussi@kernel.org \
    /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