]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 Jan 2024 10:50:07 +0000 (11:50 +0100)
commite75c3db90445623c4e41d931d1840223fd5ef7c7
tree0178f2aa8e885265daa218da7a075d088f33c286
parent7d885c171765293c9906288bafb6a75e7411286d
tracing: Add size check when printing trace_marker output

[ Upstream commit 60be76eeabb3d83858cc6577fc65c7d0f36ffd42 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/trace/trace_output.c