lkml.org 
[lkml]   [2014]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: trace_printk() broken wrt %pV
On Thu, 9 Oct 2014 11:01:39 +0200
Richard Weinberger <richard.weinberger@gmail.com> wrote:

> Hi Steven,
>
> my code does something like:
>
> void my_printf(const char *fmt, ...)
> {
> struct va_format vaf;
> va_list args;
>
> va_start(args, fmt);
> vaf.fmt = fmt;
> vaf.va = &args;
> trace_printk("%pV", &vaf);
> va_end(args);
> }
>
> While reading from /sys/kernel/debug/tracing/trace a kernel oops happens.
>
> [ 54.406617] BUG: unable to handle kernel paging request at ffffffffffffffff

Yep, and as the doctor, I say "don't do that!" ;-)

There's a trace_vprintk(). It has an extra "ip" argument. Just put in
_THIS_IP_, for that parameter.

The reason is, trace_printk() on something like that will magically
convert to a trace_bprintk(), that stores the format and parameters on
the buffer and doesn't do the processing of the format until it needs
to be printed (read from the trace file).

In your case, it saved the format "%pV" and the address of the
va_format vaf. Then when you read from the trace file, it used the
address of the vaf to process the "%pV", and obviously at that time it
no longer is valid. It was a pointer to some stack address from the
past, and thus boom!


Use the trace_vprintk(), it will do the format processing at time of
recording, and lets you get rid of the need of using va_format.

-- Steve


\
 
 \ /
  Last update: 2014-10-09 18:03    [W:0.035 / U:0.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site