mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Shuah Khan <shuah@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org,
	Andy Lutomirski <luto@amacapital.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	Changbin Du <changbin.du@gmail.com>, Jann Horn <jannh@google.com>,
	Kees Cook <keescook@chromium.org>,
	Andy Lutomirski <luto@kernel.org>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Nadav Amit <namit@vmware.com>,
	Joel Fernandes <joel@joelfernandes.org>,
	yhs@fb.com
Subject: Re: [PATCH v7 2/6] uaccess: Add non-pagefault user-space read functions
Date: Thu, 9 May 2019 23:20:04 +0900	[thread overview]
Message-ID: <20190509232004.7e354456abd654b225a3554a@kernel.org> (raw)
In-Reply-To: <20190509091408.GA90202@gmail.com>

Hi Ingo,

On Thu, 9 May 2019 11:14:08 +0200
Ingo Molnar <mingo@kernel.org> wrote:

> * Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > +static __always_inline long
> > +probe_read_common(void *dst, const void __user *src, size_t size)
> > +{
> > +	long ret;
> > +
> > +	pagefault_disable();
> > +	ret = __copy_from_user_inatomic(dst, src, size);
> > +	pagefault_enable();
> > +
> > +	return ret ? -EFAULT : 0;
> > +}
> 
> Empty line before return statement: good.
> 
> > +long __weak probe_user_read(void *dst, const void __user *src, size_t size)
> > +    __attribute__((alias("__probe_user_read")));
> > +
> > +long __probe_user_read(void *dst, const void __user *src, size_t size)
> > +{
> > +	long ret = -EFAULT;
> > +	mm_segment_t old_fs = get_fs();
> > +
> > +	set_fs(USER_DS);
> > +	if (access_ok(src, size))
> > +		ret = probe_read_common(dst, src, size);
> > +	set_fs(old_fs);
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(probe_user_read);
> 
> No empty line before return statement: not good.

OK, I'll fix that.

> 
> > +long strncpy_from_unsafe_user(char *dst, const void __user *unsafe_addr,
> > +			      long count)
> > +{
> > +	mm_segment_t old_fs = get_fs();
> > +	long ret;
> > +
> > +	if (unlikely(count <= 0))
> > +		return 0;
> > +
> > +	set_fs(USER_DS);
> > +	pagefault_disable();
> > +	ret = strncpy_from_user(dst, unsafe_addr, count);
> > +	pagefault_enable();
> > +	set_fs(old_fs);
> > +	if (ret >= count) {
> > +		ret = count;
> > +		dst[ret - 1] = '\0';
> > +	} else if (ret > 0)
> > +		ret++;
> > +	return ret;
> > +}
> 
> Ditto. Also unbalanced curly braces.

Yeah, thanks!

> 
> > +
> > +/**
> > + * strnlen_unsafe_user: - Get the size of a user string INCLUDING final NUL.
> > + * @unsafe_addr: The string to measure.
> > + * @count: Maximum count (including NUL character)
> > + *
> > + * Get the size of a NUL-terminated string in user space without pagefault.
> > + *
> > + * Returns the size of the string INCLUDING the terminating NUL.
> 
> These phrases exist:
> 
>  'Terminating NULL'
>  'NULL character'
> 
> And we also sometimes talk about 'nil' - but I don't think there's such 
> thing as a 'NUL character'?

OK, it should be "NUL" or "Null character" ( https://en.wikipedia.org/wiki/Null_character )

> 
> I realize that this was probably cloned from existing lib/strnlen_user.c 
> code, but still. ;-)
> 
> > + *
> > + * If the string is too long, returns a number larger than @count. User
> > + * has to check the return value against "> count".
> > + * On exception (or invalid count), returns 0.
> > + *
> > + * Unlike strnlen_user, this can be used from IRQ handler etc. because
> > + * it disables pagefaults.
> 
> 'can be used from IRQ handlers'

OK.

> 
> > + */
> > +long strnlen_unsafe_user(const void __user *unsafe_addr, long count)
> > +{
> > +	mm_segment_t old_fs = get_fs();
> > +	int ret;
> > +
> > +	set_fs(USER_DS);
> > +	pagefault_disable();
> > +	ret = strnlen_user(unsafe_addr, count);
> > +	pagefault_enable();
> > +	set_fs(old_fs);
> > +	return ret;
> > +}
> 
> Same problem as before.

OK, I'll fix that.

Thank you!

> 
> Thanks,
> 
> 	Ingo


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2019-05-09 14:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08 13:31 [PATCH v7 0/6] tracing/probes: uaccess: Add support user-space access Masami Hiramatsu
2019-05-08 13:32 ` [PATCH v7 1/6] x86/uaccess: Allow access_ok() in irq context if pagefault_disabled Masami Hiramatsu
2019-05-08 13:32 ` [PATCH v7 2/6] uaccess: Add non-pagefault user-space read functions Masami Hiramatsu
2019-05-09  9:14   ` Ingo Molnar
2019-05-09 14:20     ` Masami Hiramatsu [this message]
2019-05-08 13:32 ` [PATCH v7 3/6] tracing/probe: Add ustring type for user-space string Masami Hiramatsu
2019-05-09  9:15   ` Ingo Molnar
2019-05-09 14:25     ` Masami Hiramatsu
2019-05-08 13:32 ` [PATCH v7 4/6] tracing/probe: Support user-space dereference Masami Hiramatsu
2019-05-08 13:32 ` [PATCH v7 5/6] selftests/ftrace: Add user-memory access syntax testcase Masami Hiramatsu
2019-05-08 13:33 ` [PATCH v7 6/6] perf-probe: Add user memory access attribute support Masami Hiramatsu
2019-05-09  9:17   ` Ingo Molnar
2019-05-09 14:41     ` Masami Hiramatsu
2019-05-08 20:13 ` [PATCH v7 0/6] tracing/probes: uaccess: Add support user-space access Steven Rostedt

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=20190509232004.7e354456abd654b225a3554a@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=changbin.du@gmail.com \
    --cc=jannh@google.com \
    --cc=joel@joelfernandes.org \
    --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=shuah@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=yhs@fb.com \
    /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

Powered by JetHome