Skip to content

Commit b83a8ff

Browse files
committed
Merge tag 'trace-v6.19-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracing fixes from Steven Rostedt: - Fix a crash with passing a stacktrace between synthetic events A synthetic event is an event that combines two events into a single event that can display fields from both events as well as the time delta that took place between the events. It can also pass a stacktrace from the first event so that it can be displayed by the synthetic event (this is useful to get a stacktrace of a task scheduling out when blocked and recording the time it was blocked for). A synthetic event can also connect an existing synthetic event to another event. An issue was found that if the first synthetic event had a stacktrace as one of its fields, and that stacktrace field was passed to the new synthetic event to be displayed, it would crash the kernel. This was due to the stacktrace not being saved as a stacktrace but was still marked as one. When the stacktrace was read, it would try to read an array but instead read the integer metadata of the stacktrace and dereferenced a bad value. Fix this by saving the stacktrace field as a stacktrace. - Fix possible overflow in cmp_mod_entry() compare function A binary search is used to find a module address and if the addresses are greater than 2GB apart it could lead to truncation and cause a bad search result. Use normal compares instead of a subtraction between addresses to calculate the compare value. - Fix output of entry arguments in function graph tracer Depending on the configurations enabled, the entry can be two different types that hold the argument array. The macro FGRAPH_ENTRY_ARGS() is used to find the correct arguments from the given type. One location was missed and still referenced the arguments directly via entry->args and could produce the wrong value depending on how the kernel was configured. - Fix memory leak in scripts/tracepoint-update build tool If the array fails to allocate, the memory for the values needs to be freed and was not. Free the allocated values if the array failed to allocate. * tag 'trace-v6.19-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: scripts/tracepoint-update: Fix memory leak in add_string() on failure function_graph: Fix args pointer mismatch in print_graph_retval() tracing: Avoid possible signed 64-bit truncation tracing: Fix crash on synthetic stacktrace field usage
2 parents 1026064 + 361eb85 commit b83a8ff

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

kernel/trace/trace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6115,10 +6115,10 @@ static int cmp_mod_entry(const void *key, const void *pivot)
61156115
unsigned long addr = (unsigned long)key;
61166116
const struct trace_mod_entry *ent = pivot;
61176117

6118-
if (addr >= ent[0].mod_addr && addr < ent[1].mod_addr)
6119-
return 0;
6120-
else
6121-
return addr - ent->mod_addr;
6118+
if (addr < ent[0].mod_addr)
6119+
return -1;
6120+
6121+
return addr >= ent[1].mod_addr;
61226122
}
61236123

61246124
/**

kernel/trace/trace_events_hist.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,15 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
20572057
hist_field->fn_num = HIST_FIELD_FN_RELDYNSTRING;
20582058
else
20592059
hist_field->fn_num = HIST_FIELD_FN_PSTRING;
2060+
} else if (field->filter_type == FILTER_STACKTRACE) {
2061+
flags |= HIST_FIELD_FL_STACKTRACE;
2062+
2063+
hist_field->size = MAX_FILTER_STR_VAL;
2064+
hist_field->type = kstrdup_const(field->type, GFP_KERNEL);
2065+
if (!hist_field->type)
2066+
goto free;
2067+
2068+
hist_field->fn_num = HIST_FIELD_FN_STACK;
20602069
} else {
20612070
hist_field->size = field->size;
20622071
hist_field->is_signed = field->is_signed;

kernel/trace/trace_events_synth.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,22 @@ static int synth_event_define_fields(struct trace_event_call *call)
130130
struct synth_event *event = call->data;
131131
unsigned int i, size, n_u64;
132132
char *name, *type;
133+
int filter_type;
133134
bool is_signed;
135+
bool is_stack;
134136
int ret = 0;
135137

136138
for (i = 0, n_u64 = 0; i < event->n_fields; i++) {
137139
size = event->fields[i]->size;
138140
is_signed = event->fields[i]->is_signed;
139141
type = event->fields[i]->type;
140142
name = event->fields[i]->name;
143+
is_stack = event->fields[i]->is_stack;
144+
145+
filter_type = is_stack ? FILTER_STACKTRACE : FILTER_OTHER;
146+
141147
ret = trace_define_field(call, type, name, offset, size,
142-
is_signed, FILTER_OTHER);
148+
is_signed, filter_type);
143149
if (ret)
144150
break;
145151

kernel/trace/trace_functions_graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ static void print_graph_retval(struct trace_seq *s, struct ftrace_graph_ent_entr
901901
trace_seq_printf(s, "%ps", func);
902902

903903
if (args_size >= FTRACE_REGS_MAX_ARGS * sizeof(long)) {
904-
print_function_args(s, entry->args, (unsigned long)func);
904+
print_function_args(s, FGRAPH_ENTRY_ARGS(entry), (unsigned long)func);
905905
trace_seq_putc(s, ';');
906906
} else
907907
trace_seq_puts(s, "();");

scripts/tracepoint-update.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ static int add_string(const char *str, const char ***vals, int *count)
4949
array = realloc(array, sizeof(char *) * size);
5050
if (!array) {
5151
fprintf(stderr, "Failed memory allocation\n");
52+
free(*vals);
53+
*vals = NULL;
5254
return -1;
5355
}
5456
*vals = array;

0 commit comments

Comments
 (0)