Re: [PATCH] tracing: Add size check when printing trace_marker output

From: Steven Rostedt
Date: Tue Dec 12 2023 - 22:09:30 EST


On Tue, 12 Dec 2023 08:44:44 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>
>
> 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);

Bah, this needs to be:

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

Note the '.' between % and *. Otherwise it right aligns the output.

This did fail the selftest for trace_printk(), but I modified the new one
to add " *" to accommodate it :-p

Sending out v2.

-- Steve