Skip to content

Commit

Permalink
tracing: Fix checking event hash pointer logic when tp_printk is enabled
Browse files Browse the repository at this point in the history
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.

Link: https://lore.kernel.org/linux-tegra/9835d9f1-8d3a-3440-c53f-516c2606ad07@nvidia.com/

Fixes: efbbdaa ("tracing: Show real address for trace event arguments")
Reported-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (VMware) committed Apr 20, 2021
1 parent 8db403b commit 0e1e71d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0e1e71d

Please sign in to comment.