Re: [RFC][PATCH] tracing: Add trace_printk_ptr() to force non use of trace_bprintk()

From: Jiri Olsa
Date: Wed Jun 29 2016 - 03:24:34 EST


On Tue, Jun 28, 2016 at 07:19:29PM -0400, Steven Rostedt wrote:
> trace_printk() is a very helpful tool for debugging the kernel. It adds
> lots of tricks to optimize itself to prevent any "heisenbugs". That is,
> having the addition of tracing cause the bug to change its timing and
> disappear. One of this tricks is to use trace_bprintk() when possible,
> which just stores the format and the arguments into the ring buffer to
> be processed later at the time of reading the trace output.
>
> The issue with this is that there's some printf() fields that can do
> redirection. There's a list of "%p*" values that will dereference the
> pointer saved in the buffer. This is an issue with trace_printk()
> because the pointer could have been freed between the time the
> trace_printk() was called and the time the buffer is read. This will
> cause a bad pointer dereference.
>
> The preferable fix is most likely to change bprintk() to recognize
> these pointers and instead of saving the pointer in the buffer to be
> processed later, it could do the conversion and save the value in the
> buffer. But this added processing kills the whole point of bprintk()
> from being fast and not doing any processing during the recording.
> Perhaps it should simply warn and/or refuse to print.
>
> The simpler solution is to add an alternate trace_printk() that always
> uses the non optimized version that does the string processing at the
> time of the record, and saves just the string to the ring buffer.
>
> There's been many times that I myself wanted this version. So here it
> is.
>
> Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>

if we dont go with this change:
http://marc.info/?l=linux-kernel&m=146715171527229&w=2

this patch works for me:

Tested-by: Jiri Olsa <jolsa@xxxxxxxxxx>

thanks,
jirka