Skip to contentSkip to conversation

rtla: Fix segfault on multiple SIGINTs

PATCH In review Tomas Glozar 2 participants 2 messages Mar 10

Subsystems (2)
lore
Share & tools
lore

Tomas Glozar

author maintainer
#0 lore raw

PATCH 1/1 rtla: Fix segfault on multiple SIGINTs

Detach stop_trace() from SIGINT/SIGALRM on tool clean-up to prevent it from crashing RTLA by accessing freed memory.

This prevents a crash when multiple SIGINTs are received.

Fixes d6899e560366 ("rtla/timerlat_hist: Abort event processing on second signal")
Fixes 80967b354a76 ("rtla/timerlat_top: Abort event processing on second signal")
---
 tools/tracing/rtla/src/common.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
tools/tracing/rtla/src/common.c +15 -1
index ceff76a62a30..51cdf86d60d0 100644
@@ -39,6 +39,18 @@ static void set_signals(struct common_params *params)
 	}
 }
 
+/*
+ * unset_signals - unsets the signals to stop the tool
+ */
+static void unset_signals(struct common_params *params)
+{
+	signal(SIGINT, SIG_DFL);
+	if (params->duration) {
+		alarm(0);
+		signal(SIGALRM, SIG_DFL);
+	}
+}
+
 /*
  * common_parse_options - parse common command line options
  *
@@ -284,7 +296,7 @@ int run_tool(struct tool_ops *ops, int argc, char *argv[])
 
 	retval = ops->main(tool);
 	if (retval)
-		goto out_trace;
+		goto out_signals;
 
 	if (params->user_workload && !params->user.stopped_running) {
 		params->user.should_run = 0;
@@ -306,6 +318,8 @@ int run_tool(struct tool_ops *ops, int argc, char *argv[])
 	if (ops->analyze)
 		ops->analyze(tool, stopped);
 
+out_signals:
+	unset_signals(params);
 out_trace:
 	trace_events_destroy(&tool->record->trace, params->events);
 	params->events = NULL;
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Tomas Glozar

Detach stop_trace() from SIGINT/SIGALRM on tool clean-up to prevent it from crashing RTLA by accessing freed memory.

This prevents a crash when multiple SIGINTs are received.

Fixes d6899e560366 ("rtla/timerlat_hist: Abort event processing on second signal")
Fixes 80967b354a76 ("rtla/timerlat_top: Abort event processing on second signal")

---

[...]