tracing: Add size check when printing trace_marker output
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 12 Dec 2023 13:44:44 +0000 (08:44 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 13 Dec 2023 03:07:22 +0000 (22:07 -0500)
commit60be76eeabb3d83858cc6577fc65c7d0f36ffd42
treea9810f7cd2152a1c673266bc0af1d49136251f67
parentb049525855fdd0024881c9b14b8fbec61c3f53d3
tracing: Add size check when printing trace_marker output

If for some reason the trace_marker write does not have a nul byte for the
string, it will overflow the print:

  trace_seq_printf(s, ": %s", field->buf);

The field->buf could be missing the nul byte. To prevent overflow, add the
max size that the buf can be by using the event size and the field
location.

  int max = iter->ent_size - offsetof(struct print_entry, buf);

  trace_seq_printf(s, ": %*.s", max, field->buf);

Link: https://lore.kernel.org/linux-trace-kernel/20231212084444.4619b8ce@gandalf.local.home
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_output.c