From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Tomas Glozar <tglozar@redhat.com>, John Kacur <jkacur@redhat.com>,
Luis Goncalves <lgoncalv@redhat.com>,
Costa Shulyupin <costa.shul@redhat.com>
Subject: [for-next][PATCH 2/9] rtla: Fix segfault in save_trace_to_file call
Date: Wed, 26 Mar 2025 10:55:51 -0400 [thread overview]
Message-ID: <20250326145603.969401580@goodmis.org> (raw)
In-Reply-To: 20250326145549.978154551@goodmis.org
From: Tomas Glozar <tglozar@redhat.com>
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 <jkacur@redhat.com>
Cc: Luis Goncalves <lgoncalv@redhat.com>
Cc: Costa Shulyupin <costa.shul@redhat.com>
Link: https://lore.kernel.org/20250313141034.299117-1-tglozar@redhat.com
Fixes: dc4d4e7c72d1 ("rtla: Refactor save_trace_to_file")
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
tools/tracing/rtla/src/osnoise_hist.c | 3 ++-
tools/tracing/rtla/src/osnoise_top.c | 3 ++-
tools/tracing/rtla/src/timerlat_hist.c | 3 ++-
tools/tracing/rtla/src/timerlat_top.c | 3 ++-
tools/tracing/rtla/src/trace.c | 2 +-
5 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index 7c6ef67ef3e6..f4c9051c33c4 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -983,7 +983,8 @@ int osnoise_hist_main(int argc, char *argv[])
if (osnoise_trace_is_off(tool, record)) {
printf("rtla osnoise hit stop tracing\n");
- save_trace_to_file(record->trace.inst, params->trace_output);
+ save_trace_to_file(record ? record->trace.inst : NULL,
+ params->trace_output);
}
out_hist:
diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index 0eeefbbbf317..dacec2f99017 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -813,7 +813,8 @@ int osnoise_top_main(int argc, char **argv)
if (osnoise_trace_is_off(tool, record)) {
printf("osnoise hit stop tracing\n");
- save_trace_to_file(record->trace.inst, params->trace_output);
+ save_trace_to_file(record ? record->trace.inst : NULL,
+ params->trace_output);
}
out_top:
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 93d0c9e45020..822c068b4776 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -1473,7 +1473,8 @@ int timerlat_hist_main(int argc, char *argv[])
if (!params->no_aa)
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
- save_trace_to_file(record->trace.inst, params->trace_output);
+ save_trace_to_file(record ? record->trace.inst : NULL,
+ params->trace_output);
}
out_hist:
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index 3894ac37d81c..c3196a0bb585 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -1295,7 +1295,8 @@ int timerlat_top_main(int argc, char *argv[])
if (!params->no_aa)
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
- save_trace_to_file(record->trace.inst, params->trace_output);
+ save_trace_to_file(record ? record->trace.inst : NULL,
+ params->trace_output);
} else if (params->aa_only) {
/*
* If the trace did not stop with --aa-only, at least print the
diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c
index 74ed2f6208ba..69cbc48d53d3 100644
--- a/tools/tracing/rtla/src/trace.c
+++ b/tools/tracing/rtla/src/trace.c
@@ -75,7 +75,7 @@ int save_trace_to_file(struct tracefs_instance *inst, const char *filename)
int out_fd, in_fd;
int retval = -1;
- if (!filename)
+ if (!inst || !filename)
return 0;
in_fd = tracefs_instance_file_open(inst, file, O_RDONLY);
--
2.47.2
next prev parent reply other threads:[~2025-03-26 14:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 14:55 [for-next][PATCH 0/9] rtla: Updates for 6.15 Steven Rostedt
2025-03-26 14:55 ` [for-next][PATCH 1/9] tools/build: Use SYSTEM_BPFTOOL for system bpftool Steven Rostedt
2025-03-26 14:55 ` Steven Rostedt [this message]
2025-03-26 14:55 ` [for-next][PATCH 3/9] rtla/osnoise: Unify params struct Steven Rostedt
2025-03-26 14:55 ` [for-next][PATCH 4/9] rtla: Unify apply_config between top and hist Steven Rostedt
2025-03-26 14:55 ` [for-next][PATCH 5/9] rtla/osnoise: Set OSNOISE_WORKLOAD to true Steven Rostedt
2025-03-26 14:55 ` [for-next][PATCH 6/9] rtla: Always set all tracer options Steven Rostedt
2025-03-26 14:55 ` [for-next][PATCH 7/9] rtla/tests: Reset osnoise options before check Steven Rostedt
2025-03-26 14:55 ` [for-next][PATCH 8/9] rtla/tests: Test setting default options Steven Rostedt
2025-03-26 14:55 ` [for-next][PATCH 9/9] rtla: Add the ability to create ctags and etags Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250326145603.969401580@goodmis.org \
--to=rostedt@goodmis.org \
--cc=costa.shul@redhat.com \
--cc=jkacur@redhat.com \
--cc=lgoncalv@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglozar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox