public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Sean Christopherson <seanjc@google.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Jacob Wen <jian.w.wen@oracle.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 2/2] tracing: Add a verifier to check string pointers for trace events
Date: Fri, 4 Jun 2021 22:45:44 -0400	[thread overview]
Message-ID: <20210604224544.134c652f@rorschach.local.home> (raw)
In-Reply-To: <20210604222830.2505d67a@rorschach.local.home>

On Fri, 4 Jun 2021 22:28:30 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> What you described to me does not sound like a false positive, and
> converting to __string() is not a workaround but an actual fix, and
> would also need to be backported to stable.

If the event you are talking about is kvm_nested_vmenter_failed, which
records a pointer to the message, then, yes, that is unsafe and buggy.

If that event is defined by the kvm module, and used in kvm_intel. If
you have this:

	# echo 1 > /sys/kernel/tracing/events/kvm/kvm_nested_vmenter_failed

	# do_whatever_causes_that_to_trigger

	# rmmod kvm_intel

	# cat trace

Then that pointer to the string will point to some random memory.
Before this patch, it could even possibly crash the kernel!

There's two fixes you can do with this. One is to covert that to use
__string, the other is to do what RCU does, and use the
tracepoint_string() functionality.

RCU has:

	#define TPS(x)	tracepoint_string(x)

And wrap all strings with that TPS(), like in nested_vmx_reflect_vmexit():

        if (unlikely(vmx->fail)) {
                trace_kvm_nested_vmenter_failed(
-                       "hardware VM-instruction error: ",
+                       TPS("hardware VM-instruction error: "),
                        vmcs_read32(VM_INSTRUCTION_ERROR));
                exit_intr_info = 0;
                exit_qual = 0;
                goto reflect_vmexit;
        }

What the tracepoint_string does is to save the string into core kernel
memory (there's logic to use the same string if it is already
available), and it wont free it when the module is unloaded.

This makes the string safe to use by the trace event directly.

Not only is the TPS safe, it also allows userspace tools to know what
the string is, as it is exported in printk_formats. Otherwise trace-cmd
and perf will only display a pointer hex value as it has no idea what
its pointing to (both TPS and __string fixes this).

-- Steve

  reply	other threads:[~2021-06-05  2:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-26 18:59 [PATCH 0/2] tracing: Detect unsafe dereferencing of pointers from trace events Steven Rostedt
2021-02-26 18:59 ` [PATCH 1/2] tracing: Add check of trace event print fmts for dereferencing pointers Steven Rostedt
2021-02-27 14:16   ` [tracing] 5c71984c21: WARNING:at_kernel/trace/trace_events.c:#test_event_printk kernel test robot
2021-02-26 18:59 ` [PATCH 2/2] tracing: Add a verifier to check string pointers for trace events Steven Rostedt
2021-06-05  1:20   ` Sean Christopherson
2021-06-05  2:28     ` Steven Rostedt
2021-06-05  2:45       ` Steven Rostedt [this message]
2021-06-07 16:02         ` Sean Christopherson
2021-06-07 17:24           ` Steven Rostedt
2021-02-26 22:21 ` [PATCH 0/2] tracing: Detect unsafe dereferencing of pointers from " Linus Torvalds
2021-02-26 23:33   ` Steven Rostedt
2021-02-27  4:04     ` Joe Perches
2021-02-27 19:18   ` Steven Rostedt
2021-02-28  0:08     ` Steven Rostedt
2021-03-01  5:27       ` Pawel Laszczak
2021-03-02  8:23         ` Peter Chen
2021-03-02 14:56           ` Steven Rostedt
2021-03-03  1:21             ` Peter Chen
2021-03-03  1:54               ` Steven Rostedt
2021-03-07  4:01             ` Peter Chen
2021-03-07 21:14               ` Steven Rostedt

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=20210604224544.134c652f@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=jian.w.wen@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=torvalds@linux-foundation.org \
    /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