Skip to contentSkip to conversation

tracing: Fix checking event hash pointer logic when tp_printk is enabled

GIT PULL Merged Steven Rostedt 2 participants 2 messages Apr 20, 2021 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Linus,

tracing: Fix tp_printk command line and trace events

Masami added a wrapper to be able to unhash trace event pointers as they are only read by root anyway, and they can also be extracted by the raw trace data buffers. But this wrapper utilized the iterator to have a temporary buffer to manipulate the text with.

tp_printk is a kernel command line option that will send the trace output of a trace event to the console on boot up (useful when the system crashes before finishing the boot). But the code used the same wrapper that Masami added, and its iterator did not have a buffer, and this caused the system to crash.

Have the wrapper just print the trace event normally if the iterator has no temporary buffer.

Please pull the latest trace-v5.12-rc8 tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v5.12-rc8

Tag SHA1: 39ed1af76146f9f995c224de1987f14babc9aa28 Head SHA1: 0e1e71d34901a633825cd5ae78efaf8abd9215c6

Steven Rostedt (VMware) (1):
tracing: Fix checking event hash pointer logic when tp_printk is enabled

----

 kernel/trace/trace.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---------------------------
commit 0e1e71d34901a633825cd5ae78efaf8abd9215c6
Author: Steven Rostedt (VMware) <[email protected]>
Date:   Mon Apr 19 14:23:12 2021 -0400

tracing: Fix checking event hash pointer logic when tp_printk is enabled

Pointers in events that are printed are unhashed if the flags allow it, and the logic to do so is called before processing the event output from the raw ring buffer. In most cases, this is done when a user reads one of the trace files.

But if tp_printk is added on the kernel command line, this logic is done for trace events when they are triggered, and their output goes out via printk. The unhash logic (and even the validation of the output) did not support the tp_printk output, and would crash.

Fixes efbbdaa22bb7 ("tracing: Show real address for trace event arguments")
kernel/trace/trace.c +7 -3
index 5c777627212f..c0c9aa5cd8e2 100644
@@ -3545,7 +3545,11 @@ static char *trace_iter_expand_format(struct trace_iterator *iter)
 {
 	char *tmp;
 
-	if (iter->fmt == static_fmt_buf)
+	/*
+	 * iter->tr is NULL when used with tp_printk, which makes
+	 * this get called where it is not safe to call krealloc().
+	 */
+	if (!iter->tr || iter->fmt == static_fmt_buf)
 		return NULL;
 
 	tmp = krealloc(iter->fmt, iter->fmt_size + STATIC_FMT_BUF_SIZE,
@@ -3566,7 +3570,7 @@ const char *trace_event_format(struct trace_iterator *iter, const char *fmt)
 	if (WARN_ON_ONCE(!fmt))
 		return fmt;
 
-	if (iter->tr->trace_flags & TRACE_ITER_HASH_PTR)
+	if (!iter->tr || iter->tr->trace_flags & TRACE_ITER_HASH_PTR)
 		return fmt;
 
 	p = fmt;
@@ -9692,7 +9696,7 @@ void __init early_trace_init(void)
 {
 	if (tracepoint_printk) {
 		tracepoint_print_iter =
-			kmalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL);
+			kzalloc(sizeof(*tracepoint_print_iter), GFP_KERNEL);
 		if (MEM_FAIL(!tracepoint_print_iter,
 			     "Failed to allocate trace iterator\n"))
 			tracepoint_printk = 0;
merge bot Merged
#1 lore raw
The pull request you sent on Tue, 20 Apr 2021 14:38:43 -0400:

The pull request you sent on Tue, 20 Apr 2021 14:38:43 -0400:

Quoted 1 line

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git trace-v5.12-rc8

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/1fe5501ba1abf2b7e78295df73675423bd6899a0

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/prtracker.html