lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190226212440.c59f0a3fd5a9133cf980e137@kernel.org>
Date:   Tue, 26 Feb 2019 21:24:40 +0900
From:   Masami Hiramatsu <mhiramat@...nel.org>
To:     Masami Hiramatsu <mhiramat@...nel.org>
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        Linux List Kernel Mailing <linux-kernel@...r.kernel.org>,
        Andy Lutomirski <luto@...capital.net>,
        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 Tue, 26 Feb 2019 13:16:05 +0900
Masami Hiramatsu <mhiramat@...nel.org> wrote:

> Hi Linus,
> 
> On Mon, 25 Feb 2019 09:00:57 -0800
> 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.
> 
> Ah, I got it. I just followed the commit bd28b14591b9 ("x86: remove more
> uaccess_32.h complexity") as same as strnlen_from_unsafe(). No special
> reason.
> 
> > 
> > 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.
> 
> Yes, it looks good to me :)
> 
> > 
> > Note: the above will *only* work for actual user addresses, because
> > strncpy_from_user() does that proper range check.
> 
> I think we can reuse do_strncpy_from_user() for strncpy_from_unsafe().
> (so maybe we should move it from mm/maccess.c to lib/strncpy_from_user.c?)

Ah, no, since lib/strncpy_from_user.c depends on CONFIG_GENERIC_STRNCPY_FROM_USER
which is not selected on a half of supported architectures. Hmm, can we make
strncpy_from_user() an __weak function and build that always?

> As Kees pointed out, I think it is a good chance to sort the behavior of
> these strXcpy APIs to match their names.

I meant, at first rename strncpy_from_unsafe() to strscpy_from_unsafe()
and change the behavior (returning the length of copied string, exclude NULL).

Thank you,

-- 
Masami Hiramatsu <mhiramat@...nel.org>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ