From: Joel Fernandes <joel@joelfernandes.org>
To: Will Deacon <will.deacon@arm.com>
Cc: Qais Yousef <qais.yousef@arm.com>,
linux-kernel@vger.kernel.org,
Michal Gregorczyk <michalgr@live.com>,
Adrian Ratiu <adrian.ratiu@collabora.com>,
Mohammad Husain <russoue@gmail.com>,
Srinivas Ramana <sramana@codeaurora.org>,
duyuchao <yuchao.du@unisoc.com>,
Manjo Raja Rao <linux@manojrajarao.com>,
Karim Yaghmour <karim.yaghmour@opersys.com>,
Tamir Carmeli <carmeli.tamir@gmail.com>,
Yonghong Song <yhs@fb.com>, Alexei Starovoitov <ast@kernel.org>,
Brendan Gregg <brendan.d.gregg@gmail.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Peter Ziljstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Kees Cook <keescook@chromium.org>,
kernel-team@android.com, Daniel Borkmann <daniel@iogearbox.net>,
Ingo Molnar <mingo@redhat.com>,
netdev@vger.kernel.org, Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH RFC] bpf: Add support for reading user pointers
Date: Tue, 7 May 2019 22:00:23 -0400 [thread overview]
Message-ID: <20190508020023.GA184577@google.com> (raw)
In-Reply-To: <20190507095242.GA17052@fuggles.cambridge.arm.com>
On Tue, May 07, 2019 at 10:52:42AM +0100, Will Deacon wrote:
> On Mon, May 06, 2019 at 10:57:37PM +0100, Qais Yousef wrote:
> > On 05/06/19 16:58, Joel Fernandes wrote:
> > > > If you're trying to dereference a pointer to userspace using
> > > > probe_kernel_read(), that clearly isn't going to work.
> > >
> > > Ok. Thanks for confirming as well. The existing code has this bug and these
> > > patches fix it.
> >
> > 5.1-rc7 and 4.9.173 stable both managed to read the path in do_sys_open() on my
> > Juno-r2 board using the defconfig in the tree.
>
> That's not surprising: Juno-r2 only features v8.0 CPUs, so doesn't have PAN
> or UAO capabilities. The SoC Joel is talking about is 8.2, so has both of
> those.
>
> Here's some background which might help...
>
> PAN (Privileged Access Never) prevents the kernel from inadvertently
> accessing userspace and will cause a page (permission) fault if such an
> access is made outside of the standard uaccess routines. This means that
> in those routines (e.g. get_user()) we have to toggle the PAN state in the
> same way that x86 toggles SMAP. This can be expensive and was part of the
> motivation for the adoption of things like unsafe_get_user() on x86.
>
> On arm64, we have a set of so-called "translated" memory access instructions
> which can be used to perform unprivileged accesses to userspace from within
> the kernel even when PAN is enabled. Using these special instructions (e.g.
> LDTR) in our uaccess routines can therefore remove the need to toggle PAN.
> Sounds great, right? Well, that all falls apart when the uaccess routines
> are used on kernel addresses as in probe_kernel_read() because they will
> fault when trying to dereference a kernel pointer.
>
> The answer is UAO (User Access Override). When UAO is set, the translated
> memory access instructions behave the same as non-translated accesses.
> Therefore we can toggle UAO in set_fs() so that it is set when we're using
> KERNEL_DS and cleared when we're using USER_DS.
>
> The side-effect of this is that when KERNEL_DS is set on a system that
> implements both PAN and UAO, passing a user pointer to our uaccess routines
> will return -EFAULT. In other words, set_fs() can be thought of as a
> selector between the kernel and user address spaces, which are distinct.
>
> Joel -- does disabling UAO in your .config "fix" the issue? If so, feel
> free to use some of the above text in a commit message if it helps to
> justify your change.
Disabling CONFIG_ARM64_UAO does "fix" it.
I will use the description above in the commit message as you suggested,
thanks a lot for the explantation of this!
- Joel
next prev parent reply other threads:[~2019-05-08 2:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-02 20:49 [PATCH RFC] bpf: Add support for reading user pointers Joel Fernandes (Google)
2019-05-03 12:12 ` Qais Yousef
2019-05-03 13:49 ` Joel Fernandes
2019-05-03 13:54 ` Peter Zijlstra
2019-05-03 15:09 ` Joel Fernandes
2019-05-05 11:04 ` Qais Yousef
2019-05-05 13:29 ` Joel Fernandes
2019-05-05 14:46 ` Qais Yousef
2019-05-05 15:52 ` Joel Fernandes
2019-05-05 18:03 ` Joel Fernandes
2019-05-05 18:51 ` Andrii Nakryiko
2019-05-06 0:01 ` Qais Yousef
2019-05-06 18:35 ` Will Deacon
2019-05-06 20:58 ` Joel Fernandes
2019-05-06 21:57 ` Qais Yousef
2019-05-07 9:52 ` Will Deacon
2019-05-08 2:00 ` Joel Fernandes [this message]
2019-05-05 7:19 ` Alexei Starovoitov
2019-05-05 13:33 ` Joel Fernandes
2019-05-06 14:47 ` Masami Hiramatsu
2019-05-06 16:14 ` Joel Fernandes
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=20190508020023.GA184577@google.com \
--to=joel@joelfernandes.org \
--cc=adrian.ratiu@collabora.com \
--cc=ast@kernel.org \
--cc=brendan.d.gregg@gmail.com \
--cc=carmeli.tamir@gmail.com \
--cc=daniel@iogearbox.net \
--cc=karim.yaghmour@opersys.com \
--cc=keescook@chromium.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@manojrajarao.com \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=michalgr@live.com \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=qais.yousef@arm.com \
--cc=rostedt@goodmis.org \
--cc=russoue@gmail.com \
--cc=sramana@codeaurora.org \
--cc=will.deacon@arm.com \
--cc=yhs@fb.com \
--cc=yuchao.du@unisoc.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 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.