From: Masami Hiramatsu <mhiramat@kernel.org>
To: Kees Cook <keescook@chromium.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
Andy Lutomirski <luto@amacapital.net>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Changbin Du <changbin.du@gmail.com>, Jann Horn <jannh@google.com>,
Andy Lutomirski <luto@kernel.org>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Nadav Amit <namit@vmware.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [RFC PATCH 2/4] uaccess: Add non-pagefault user-space read functions
Date: Tue, 26 Feb 2019 13:07:20 +0900 [thread overview]
Message-ID: <20190226130720.189c882ce8355bb605d1ca9d@kernel.org> (raw)
In-Reply-To: <CAGXu5jL+8nBen8_BjTziF=bGQm7hijV7YMa_a53vXfFT4+mwzQ@mail.gmail.com>
Hi Kees,
On Mon, 25 Feb 2019 09:06:55 -0800
Kees Cook <keescook@chromium.org> wrote:
> 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?
Yes, it is easy to me to fit it to strscpy spec and caller side too.
But if we reuse strncpy_from_user() as Linus suggested, it may be better
keep it or write a wrapper, since this function spec is still a bit
different from strscpy (this doesn't return -E2BIG but returns the
copied length of the string with NULL terminal byte).
Thank you,
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2019-02-26 4:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-25 14:04 [RFC PATCH 0/4] tracing/probes: uaccess: Add support user-space access Masami Hiramatsu
2019-02-25 14:05 ` [RFC PATCH 1/4] uaccess: Make sure kernel_uaccess_faults_ok is updated before pagefault Masami Hiramatsu
2019-02-25 14:05 ` [RFC PATCH 2/4] uaccess: Add non-pagefault user-space read functions Masami Hiramatsu
2019-02-25 15:06 ` Peter Zijlstra
2019-02-25 17:00 ` Linus Torvalds
2019-02-25 18:16 ` Andy Lutomirski
2019-02-26 4:16 ` Masami Hiramatsu
2019-02-26 12:24 ` Masami Hiramatsu
2019-02-26 15:14 ` [RFC PATCH v2] " Masami Hiramatsu
2019-02-26 3:01 ` [RFC PATCH 2/4] " Masami Hiramatsu
2019-02-25 17:06 ` Kees Cook
2019-02-26 4:07 ` Masami Hiramatsu [this message]
2019-02-25 14:06 ` [RFC PATCH 3/4] tracing/probe: Add ustring type for user-space string Masami Hiramatsu
2019-02-25 14:06 ` [RFC PATCH 4/4] tracing/probe: Support user-space dereference Masami Hiramatsu
2019-02-26 21:38 ` [RFC PATCH 0/4] tracing/probes: uaccess: Add support user-space access Joel Fernandes
2019-02-27 7:41 ` Masami Hiramatsu
2019-02-27 8:00 ` Peter Zijlstra
2019-02-27 11:39 ` Masami Hiramatsu
2019-02-27 21:33 ` 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=20190226130720.189c882ce8355bb605d1ca9d@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=changbin.du@gmail.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=namit@vmware.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox