Skip to content

Commit 60be76e

Browse files
committed
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/[email protected] Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent b049525 commit 60be76e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kernel/trace/trace_output.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,11 +1587,12 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter,
15871587
{
15881588
struct print_entry *field;
15891589
struct trace_seq *s = &iter->seq;
1590+
int max = iter->ent_size - offsetof(struct print_entry, buf);
15901591

15911592
trace_assign_type(field, iter->ent);
15921593

15931594
seq_print_ip_sym(s, field->ip, flags);
1594-
trace_seq_printf(s, ": %s", field->buf);
1595+
trace_seq_printf(s, ": %.*s", max, field->buf);
15951596

15961597
return trace_handle_return(s);
15971598
}
@@ -1600,10 +1601,11 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
16001601
struct trace_event *event)
16011602
{
16021603
struct print_entry *field;
1604+
int max = iter->ent_size - offsetof(struct print_entry, buf);
16031605

16041606
trace_assign_type(field, iter->ent);
16051607

1606-
trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
1608+
trace_seq_printf(&iter->seq, "# %lx %.*s", field->ip, max, field->buf);
16071609

16081610
return trace_handle_return(&iter->seq);
16091611
}

0 commit comments

Comments
 (0)