[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Yd5VTy0UW1tOcjTD@piliu.users.ipa.redhat.com>
Date: Wed, 12 Jan 2022 12:13:03 +0800
From: Pingfan Liu <kernelfans@...il.com>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: David Laight <David.Laight@...lab.com>,
LKML <linux-kernel@...r.kernel.org>,
Ingo Molnar <mingo@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Tom Zanussi <zanussi@...nel.org>
Subject: Re: [PATCH v2] tracing: Add test for user space strings when
filtering on string pointers
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@...LAB.COM> wrote:
>
> > From: Steven Rostedt
> > > Sent: 10 January 2022 16:56
> > >
> > > From: Steven Rostedt <rostedt@...dmis.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
Powered by blists - more mailing lists