lkml.org 
[lkml]   [2019]   [Feb]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [RFC PATCH 2/4] uaccess: Add non-pagefault user-space read functions
On Mon, Feb 25, 2019 at 6:06 AM Masami Hiramatsu <mhiramat@kernel.org> wrote:
> +static __always_inline long strncpy_from_unsafe_common(char *dst,
> + const char __user *unsafe_addr, long count)
> +{
> + const char __user *src = unsafe_addr;
> + int ret;
> +
> + pagefault_disable();
> + do {
> + ret = __get_user(*dst++, src++);
> + } while (dst[-1] && ret == 0 && src - unsafe_addr < count);
> + dst[-1] = '\0';
> + pagefault_enable();
> +
> + return ret ? -EFAULT : src - unsafe_addr;
> +}

I'm all for always NUL-truncating, but this isn't "strncpy" (which has
the buggy maybe-I-didn't-NUL-terminate behavior). Can we call this
strscpy_...() instead?

--
Kees Cook

\
 
 \ /
  Last update: 2019-02-25 18:08    [W:0.101 / U:1.292 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site