* [PATCH] tracing: Fix trace_check_vprintf() when tp_printk is used
@ 2024-10-03 14:49 Steven Rostedt
2024-10-03 19:25 ` Alison Schofield
0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2024-10-03 14:49 UTC (permalink / raw)
To: LKML, Linux Trace Kernel
Cc: Masami Hiramatsu, Mathieu Desnoyers, Alison Schofield
From: Steven Rostedt <rostedt@goodmis.org>
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/Zv3z5UsG_jsO9_Tb@aschofie-mobl2.lan/
Reported-by: Alison Schofield <alison.schofield@intel.com>
Fixes: 07714b4bb3f98 ("tracing: Handle old buffer mappings for event strings and functions")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index c01375adc471..1c69ca1f1088 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3697,8 +3697,8 @@ static void test_can_verify(void)
void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
va_list ap)
{
- long text_delta = iter->tr->text_delta;
- long data_delta = iter->tr->data_delta;
+ long text_delta = 0;
+ long data_delta = 0;
const char *p = fmt;
const char *str;
bool good;
@@ -3710,6 +3710,17 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
if (static_branch_unlikely(&trace_no_verify))
goto print;
+ /*
+ * When the kernel is booted with the tp_printk command line
+ * parameter, trace events go directly through to printk().
+ * It also is checked by this function, but it does not
+ * have an associated trace_array (tr) for it.
+ */
+ if (iter->tr) {
+ text_delta = iter->tr->text_delta;
+ data_delta = iter->tr->data_delta;
+ }
+
/* Don't bother checking when doing a ftrace_dump() */
if (iter->fmt == static_fmt_buf)
goto print;
--
2.45.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tracing: Fix trace_check_vprintf() when tp_printk is used
2024-10-03 14:49 [PATCH] tracing: Fix trace_check_vprintf() when tp_printk is used Steven Rostedt
@ 2024-10-03 19:25 ` Alison Schofield
0 siblings, 0 replies; 2+ messages in thread
From: Alison Schofield @ 2024-10-03 19:25 UTC (permalink / raw)
To: Steven Rostedt
Cc: LKML, Linux Trace Kernel, Masami Hiramatsu, Mathieu Desnoyers
On Thu, Oct 03, 2024 at 10:49:25AM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> 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/Zv3z5UsG_jsO9_Tb@aschofie-mobl2.lan/
>
Thanks Steve!
Tested-by: Alison Schofield <alison.schofield@intel.com>
> Reported-by: Alison Schofield <alison.schofield@intel.com>
> Fixes: 07714b4bb3f98 ("tracing: Handle old buffer mappings for event strings and functions")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> kernel/trace/trace.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
>
snip
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-03 19:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-03 14:49 [PATCH] tracing: Fix trace_check_vprintf() when tp_printk is used Steven Rostedt
2024-10-03 19:25 ` Alison Schofield
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox