Skip to content

Commit 784bd08

Browse files
Tom Zanussirostedt
authored andcommitted
tracing: Fix number printing bug in print_synth_event()
Fix a varargs-related bug in print_synth_event() which resulted in strange output and oopses on 32-bit x86 systems. The problem is that trace_seq_printf() expects the varargs to match the format string, but print_synth_event() was always passing u64 values regardless. This results in unspecified behavior when unpacking with va_arg() in trace_seq_printf(). Add a function that takes the size into account when calling trace_seq_printf(). Before: modprobe-1731 [003] .... 919.039758: gen_synth_test: next_pid_field=777(null)next_comm_field=hula hoops ts_ns=1000000 ts_ms=1000 cpu=3(null)my_string_field=thneed my_int_field=598(null) After: insmod-1136 [001] .... 36.634590: gen_synth_test: next_pid_field=777 next_comm_field=hula hoops ts_ns=1000000 ts_ms=1000 cpu=1 my_string_field=thneed my_int_field=598 Link: http://lkml.kernel.org/r/a9b59eb515dbbd7d4abe53b347dccf7a8e285657.1581720155.git.zanussi@kernel.org Reported-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 3843083 commit 784bd08

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,29 @@ static const char *synth_field_fmt(char *type)
820820
return fmt;
821821
}
822822

823+
static void print_synth_event_num_val(struct trace_seq *s,
824+
char *print_fmt, char *name,
825+
int size, u64 val, char *space)
826+
{
827+
switch (size) {
828+
case 1:
829+
trace_seq_printf(s, print_fmt, name, (u8)val, space);
830+
break;
831+
832+
case 2:
833+
trace_seq_printf(s, print_fmt, name, (u16)val, space);
834+
break;
835+
836+
case 4:
837+
trace_seq_printf(s, print_fmt, name, (u32)val, space);
838+
break;
839+
840+
default:
841+
trace_seq_printf(s, print_fmt, name, val, space);
842+
break;
843+
}
844+
}
845+
823846
static enum print_line_t print_synth_event(struct trace_iterator *iter,
824847
int flags,
825848
struct trace_event *event)
@@ -858,10 +881,13 @@ static enum print_line_t print_synth_event(struct trace_iterator *iter,
858881
} else {
859882
struct trace_print_flags __flags[] = {
860883
__def_gfpflag_names, {-1, NULL} };
884+
char *space = (i == se->n_fields - 1 ? "" : " ");
861885

862-
trace_seq_printf(s, print_fmt, se->fields[i]->name,
863-
entry->fields[n_u64],
864-
i == se->n_fields - 1 ? "" : " ");
886+
print_synth_event_num_val(s, print_fmt,
887+
se->fields[i]->name,
888+
se->fields[i]->size,
889+
entry->fields[n_u64],
890+
space);
865891

866892
if (strcmp(se->fields[i]->type, "gfp_t") == 0) {
867893
trace_seq_puts(s, " (");

0 commit comments

Comments
 (0)