[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALCETrU1dx+Om9k0Q7KbXSVRUpapFWe1bLr7ETm8Rdq=7c9AHw@mail.gmail.com>
Date: Mon, 25 Feb 2019 10:16:20 -0800
From: Andy Lutomirski <luto@...nel.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Peter Zijlstra <peterz@...radead.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Steven Rostedt <rostedt@...dmis.org>,
Linux List Kernel Mailing <linux-kernel@...r.kernel.org>,
Ingo Molnar <mingo@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Changbin Du <changbin.du@...il.com>,
Jann Horn <jannh@...gle.com>,
Kees Cook <keescook@...omium.org>,
Andy Lutomirski <luto@...nel.org>,
Alexei Starovoitov <alexei.starovoitov@...il.com>,
Nadav Amit <namit@...are.com>
Subject: Re: [RFC PATCH 2/4] uaccess: Add non-pagefault user-space read functions
On Mon, Feb 25, 2019 at 9:01 AM Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> On Mon, Feb 25, 2019 at 7:06 AM Peter Zijlstra <peterz@...radead.org> wrote:
> >
> > Would something like so work for people?
>
> Looks reasonable to me.
>
> > Why not keep it simple:
> >
> > mm_segment_t old_fs = get_fs();
> >
> > set_fs(USER_DS);
> > ret = __strncpy...();
> > set_fs(old_fd);
> >
> > return ret;
>
> So none of this code looks sane. First odd, there's no real reason to
> use __get_user(). The thing should never be used. It does the whole
> stac/clac for every byte.
>
> In the copy_from_user() case, I suggested re-doing it as one common
> routine without the set_fs() dance for the "already there" case to
> simplify error handling. Here it doesn't do that.
>
> But honestly, I think for the strncpy case, we could just do
>
> long strncpy_from_unsafe_user(char *dst, const void __user *src, long count)
> {
> long ret;
> mm_segment_t old_fs = get_fs();
>
> set_fs(USER_DS);
> pagefault_disable();
> ret = strncpy_from_user(dst, src, count);
> pagefault_enable();
> set_fs(old_fs);
> return ret;
> }
>
> and be done with it. Efficient and simple.
>
> Note: the above will *only* work for actual user addresses, because
> strncpy_from_user() does that proper range check.
>
Can we also stick the nmi_uaccess_okay() thing in here and kill an
extra bird with the same stone? Basically, this is "I have no idea
what context I'm in, but I want to try to read a string from current's
address space, so do your best." In which case, we need to handle the
fact that we might be in KERNEL_DS *and* we need to handle the fact
that CR3 might be wrong.
Powered by blists - more mailing lists