Skip to content

Commit c57c58a

Browse files
lenticularis39rostedt
authored andcommitted
rtla: Fix segfault in save_trace_to_file call
Running rtla with exit on threshold, but without saving trace leads to a segmenetation fault: $ rtla timerlat hist -T 10 ... Max timerlat IRQ latency from idle: 4.29 us in cpu 0 Segmentation fault This is caused by null pointer deference in the call of save_trace_to_file, which attempts to dereference an uninitialized osnoise_tool variable: save_trace_to_file(record->trace.inst, params->trace_output); ^ this is uninitialized if params->trace_output is not set Fix this by not attempting to dereference "record" if it is NULL and passing NULL instead. As a safety measure, the first field is also checked for NULL inside save_trace_to_file. Cc: John Kacur <[email protected]> Cc: Luis Goncalves <[email protected]> Cc: Costa Shulyupin <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: dc4d4e7 ("rtla: Refactor save_trace_to_file") Signed-off-by: Tomas Glozar <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 814d051 commit c57c58a

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,8 @@ int osnoise_hist_main(int argc, char *argv[])
983983

984984
if (osnoise_trace_is_off(tool, record)) {
985985
printf("rtla osnoise hit stop tracing\n");
986-
save_trace_to_file(record->trace.inst, params->trace_output);
986+
save_trace_to_file(record ? record->trace.inst : NULL,
987+
params->trace_output);
987988
}
988989

989990
out_hist:

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,8 @@ int osnoise_top_main(int argc, char **argv)
813813

814814
if (osnoise_trace_is_off(tool, record)) {
815815
printf("osnoise hit stop tracing\n");
816-
save_trace_to_file(record->trace.inst, params->trace_output);
816+
save_trace_to_file(record ? record->trace.inst : NULL,
817+
params->trace_output);
817818
}
818819

819820
out_top:

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,8 @@ int timerlat_hist_main(int argc, char *argv[])
14731473
if (!params->no_aa)
14741474
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
14751475

1476-
save_trace_to_file(record->trace.inst, params->trace_output);
1476+
save_trace_to_file(record ? record->trace.inst : NULL,
1477+
params->trace_output);
14771478
}
14781479

14791480
out_hist:

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,8 @@ int timerlat_top_main(int argc, char *argv[])
12951295
if (!params->no_aa)
12961296
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
12971297

1298-
save_trace_to_file(record->trace.inst, params->trace_output);
1298+
save_trace_to_file(record ? record->trace.inst : NULL,
1299+
params->trace_output);
12991300
} else if (params->aa_only) {
13001301
/*
13011302
* If the trace did not stop with --aa-only, at least print the

tools/tracing/rtla/src/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int save_trace_to_file(struct tracefs_instance *inst, const char *filename)
7575
int out_fd, in_fd;
7676
int retval = -1;
7777

78-
if (!filename)
78+
if (!inst || !filename)
7979
return 0;
8080

8181
in_fd = tracefs_instance_file_open(inst, file, O_RDONLY);

0 commit comments

Comments
 (0)