Skip to content

Commit 50a3242

Browse files
committed
tracing: Fix trace_check_vprintf() when tp_printk is used
When the tp_printk kernel command line is used, the trace events go directly to printk(). It is still checked via the trace_check_vprintf() function to make sure the pointers of the trace event are legit. The addition of reading buffers from previous boots required adding a delta between the addresses of the previous boot and the current boot so that the pointers in the old buffer can still be used. But this required adding a trace_array pointer to acquire the delta offsets. The tp_printk code does not provide a trace_array (tr) pointer, so when the offsets were examined, a NULL pointer dereference happened and the kernel crashed. If the trace_array does not exist, just default the delta offsets to zero, as that also means the trace event is not being read from a previous boot. Link: https://lore.kernel.org/all/[email protected]/ Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: 07714b4 ("tracing: Handle old buffer mappings for event strings and functions") Reported-by: Alison Schofield <[email protected]> Tested-by: Alison Schofield <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 9852d85 commit 50a3242

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

kernel/trace/trace.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,8 +3697,8 @@ static void test_can_verify(void)
36973697
void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
36983698
va_list ap)
36993699
{
3700-
long text_delta = iter->tr->text_delta;
3701-
long data_delta = iter->tr->data_delta;
3700+
long text_delta = 0;
3701+
long data_delta = 0;
37023702
const char *p = fmt;
37033703
const char *str;
37043704
bool good;
@@ -3710,6 +3710,17 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
37103710
if (static_branch_unlikely(&trace_no_verify))
37113711
goto print;
37123712

3713+
/*
3714+
* When the kernel is booted with the tp_printk command line
3715+
* parameter, trace events go directly through to printk().
3716+
* It also is checked by this function, but it does not
3717+
* have an associated trace_array (tr) for it.
3718+
*/
3719+
if (iter->tr) {
3720+
text_delta = iter->tr->text_delta;
3721+
data_delta = iter->tr->data_delta;
3722+
}
3723+
37133724
/* Don't bother checking when doing a ftrace_dump() */
37143725
if (iter->fmt == static_fmt_buf)
37153726
goto print;

0 commit comments

Comments
 (0)