mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Richard Weinberger <richard.weinberger@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: trace_printk() broken wrt %pV
Date: Thu, 9 Oct 2014 11:31:11 -0400	[thread overview]
Message-ID: <20141009113111.0ecb175d@gandalf.local.home> (raw)
In-Reply-To: <CAFLxGvyMO-HCaVOghrjXZkAEtmytrDgi4CqiRs0nFzQSnvg4UA@mail.gmail.com>

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

      reply	other threads:[~2014-10-09 15:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-09  9:01 Richard Weinberger
2014-10-09 15:31 ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141009113111.0ecb175d@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard.weinberger@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®