mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Sven Schnelle <svens@linux.ibm.com>
Cc: David Laight <David.Laight@ACULAB.COM>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Pingfan Liu <kernelfans@gmail.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Tom Zanussi <zanussi@kernel.org>,
	hca@linux.ibm.com, deller@gmx.de
Subject: Re: [PATCH v2] tracing: Add test for user space strings when filtering on  string pointers
Date: Thu, 13 Jan 2022 12:57:54 -0500	[thread overview]
Message-ID: <20220113125754.0cb5273f@gandalf.local.home> (raw)
In-Reply-To: <yt9d8rvmt2jq.fsf@linux.ibm.com>

On Tue, 11 Jan 2022 21:55:53 +0100
Sven Schnelle <svens@linux.ibm.com> wrote:

> > Isn't there also at least one architecture where you can't differentiate
> > between user and kernel pointers by looking at the address?
> > (Something like sparc ASI is used for user accesses so both user
> > and kernel get the full 4G address range. But it isn't sparc (or pdp/11))
> > ISTR it causing issues with the code for kernel_setsockopt() and
> > required a separate flag.  
> 
> On s390 TASK_SIZE is defined as -PAGE_SIZE, so with the patch above the
> kernel would always try to fetch it from user space. I think it would be
> the same for parisc.

As a work around for these cases, would something like this work?

-- Steve

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 91352a64be09..06013822764c 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -676,7 +676,15 @@ static __always_inline char *test_string(char *str)
 	ubuf = this_cpu_ptr(ustring_per_cpu);
 	kstr = ubuf->buffer;
 
-	if (likely((unsigned long)str >= TASK_SIZE)) {
+	/*
+	 * Test the address of ustring_per_cpu against TASK_SIZE, as
+	 * comparing TASK_SIZE to determine kernel/user space address
+	 * is not enough on some architectures. If the address is less
+	 * than TASK_SIZE we know this is the case, in which we should
+	 * always use the from_kernel variant.
+	 */
+	if ((unsigned long)&ustring_per_cpu < (unsigned long)TASK_SIZE ||
+	    likely((unsigned long)str >= TASK_SIZE)) {
 		/* For safety, do not trust the string pointer */
 		if (!strncpy_from_kernel_nofault(kstr, str, USTRING_BUF_SIZE))
 			return NULL;

  reply	other threads:[~2022-01-13 17:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10 16:55 Steven Rostedt
2022-01-10 17:11 ` David Laight
2022-01-10 17:24   ` Steven Rostedt
2022-01-10 17:29     ` Steven Rostedt
2022-01-10 21:58     ` David Laight
2022-01-11 20:55       ` Sven Schnelle
2022-01-13 17:57         ` Steven Rostedt [this message]
2022-01-13 21:28           ` Sven Schnelle
2022-01-13 21:51             ` Steven Rostedt
2022-01-14  2:15               ` Steven Rostedt
2022-01-14  7:29                 ` Sven Schnelle
2022-01-14  9:35                 ` David Laight
2022-01-13 22:11             ` David Laight
2022-01-13 22:28               ` Steven Rostedt
2022-01-10 22:03     ` David Laight
2022-01-11  0:21       ` Steven Rostedt
2022-01-12  4:13     ` Pingfan Liu
2022-01-13 18:04       ` Steven Rostedt
2022-01-13 22:02       ` 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=20220113125754.0cb5273f@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=David.Laight@ACULAB.COM \
    --cc=akpm@linux-foundation.org \
    --cc=deller@gmx.de \
    --cc=hca@linux.ibm.com \
    --cc=kernelfans@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=zanussi@kernel.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

all inboxes | Powered by JetHome®