On Mon, Mar 4, 2019 at 1:06 AM Masami Hiramatsu <mhira...@kernel.org> wrote:
>
> On Sun, 3 Mar 2019 18:37:59 -0800
> Linus Torvalds <torva...@linux-foundation.org> wrote:
> > We've had this before. We've gotten rid of the actual "use system
> > calls", but we still have some of the init sequence in particular just
> > calling the wrappers instead.
>
> Are those safe if we are in init sequence?

Yes, they are, it runs with set_fs(KERNEL_DS).

But the patches made that now complain about copying from non-user
space, even though it's fine.

Basically, "strncpy_from_user()" shouldn't use "user_access_ok()",
since it actually can take a kernel address (with set_fs()).

Your "unsafe" version for tracing that actually sets "set_fs(USER_DS)"
is thje only thing that should use that helper.

> > And yes, ksys_mount() takes __user pointers.
> >
> > It would be a lot better to use "do_mount()", which is the interface
> > that takes actual "char *" pointers.
>
> Unfortunately, it still takes a __user pointer.

Ahh, yes, the name remains in user space.

Besides, I'm sure you'd just hit other cases instead where people use
set_fs() and copy strings.

> So what we need is
>
> long do_mount(const char *dev_name, struct path *dir_path,
>                 const char *type_page, unsigned long flags, void *data_page)
>
> or introduce kern_do_mount()?

It's actually fairly painful. Particularly because of that "void *data_page".

Your second email with "Would this work?" helper function _wopuldn't_
work correctly, exactly because you passed in a regular string to the
data page.

Also, I don't want to see code that replaces the unconditional "copy
path from user space" with a conditional "do we have path in kernel
space".

So together with the whole "uyou'll hit other peoblems anyway", I
don't think this is a good approach.

I think you simply need to have a separate "unsafe_strncpy()"
function, and not change the existing "strncpy_from_user()".

                Linus

Reply via email to