All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pingfan Liu <kernelfans@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: David Laight <David.Laight@aculab.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Tom Zanussi <zanussi@kernel.org>
Subject: Re: [PATCH v2] tracing: Add test for user space strings when filtering on  string pointers
Date: Wed, 12 Jan 2022 12:13:03 +0800	[thread overview]
Message-ID: <Yd5VTy0UW1tOcjTD@piliu.users.ipa.redhat.com> (raw)
In-Reply-To: <20220110122436.5302128f@gandalf.local.home>

Hi Steven,

Sorry that I am out of office, and not reply in time.

On Mon, Jan 10, 2022 at 12:24:36PM -0500, Steven Rostedt wrote:
> On Mon, 10 Jan 2022 17:11:52 +0000
> David Laight <David.Laight@ACULAB.COM> wrote:
> 
> > From: Steven Rostedt
> > > Sent: 10 January 2022 16:56
> > > 
> > > From: Steven Rostedt <rostedt@goodmis.org>
> > > 
> > > Pingfan reported that the following causes a fault:
> > > 
> > >   echo "filename ~ \"cpu\"" > events/syscalls/sys_enter_openat/filter
> > >   echo 1 > events/syscalls/sys_enter_at/enable
> > > 
> > > The reason is that trace event filter treats the user space pointer
> > > defined by "filename" as a normal pointer to compare against the "cpu"
> > > string. If the string is not loaded into memory yet, it will trigger a
> > > fault in kernel space:  

For accurate commit log, the swapped-out user page is not the root cause
of this bug is "supervisor read access in kernel mode". And it is trueth
that swapped-out user page can trigger a bug here, but it should be a
different a stack.

> > 
> > If a userspace pointer can end up the kernel structure then presumably
> > a 'dodgy' user program can supply an arbitrary kernel address instead?
> > This may give the user the ability to read arbitrary kernel addresses
> > (including ones that are mapped to PCIe IO addresses).
> > Doesn't sound good at all.
> 
> Only root has access to the information read here. All tracing requires
> root or those explicitly given access to the tracing data, which pretty
> much allows all access to kernel internals (including all memory). So
> nothing to worry about here ;-)
> 

I am not sure about the opposite way. Since kernel is not allowed to
access userspace most of the time, then is it an leakage, which looks
like:
    use tracepoint as trampoline to uaccess.
    read out user info from ustring_per_cpu

But any kernel code can call copy_from_user() function family freely, so
it is not a problem caused by this patch, right? Or ustring_per_cpu
should be zeroed out.

For V2, feel free to add "Tested-by"


Thanks,

	Pingfan
> > 
> > ...
> > > +	if (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;
> > > +	} else {
> > > +		/* user space address? */
> > > +		ustr = (char __user *)str;
> > > +		if (!strncpy_from_user_nofault(kstr, ustr, USTRING_BUF_SIZE))
> > > +			return NULL;  
> > 
> > Is that check against TASK_SIZE even correct for all architectures?
> > copy_to/from_user() uses access_ok() - which is architecture dependant.
> 
> The problem with access_ok() (which I tried first) is that it can't be used
> from interrupt context, and this check can happen in interrupt context.
> Either way, if we pick the wrong one for the arch, the only thing bad that
> can happen is that it returns "fault" and the filter fails, just like if
> the pointer was to bad memory.
> 
> > 
> > I think you need to remember where the pointer came from.
> > 
> 
> Why?
> 
> -- Steve

  parent reply	other threads:[~2022-01-12  4:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10 16:55 [PATCH v2] tracing: Add test for user space strings when filtering on string pointers 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
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 [this message]
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=Yd5VTy0UW1tOcjTD@piliu.users.ipa.redhat.com \
    --to=kernelfans@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.