From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
Namhyung Kim <namhyung@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [RFC][PATCH] tracing: Have traceprobe_probes_write() not access userspace unnecessarily
Date: Fri, 10 Feb 2017 14:50:06 +0900 [thread overview]
Message-ID: <20170210145006.b387236e4b6813a09d55162b@kernel.org> (raw)
In-Reply-To: <20170209180458.5c829ab2@gandalf.local.home>
On Thu, 9 Feb 2017 18:04:58 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
>
> The code in traceprobe_probes_write() reads up to 4096 bytes from userpace
> for each line. If userspace passes in several lines to execute, the code
> will do a large read for each line, even though, it is highly likely that
> the first read from userspace received all of the lines at one.
>
> I changed the logic to do a single read from userspace, and to only read
> from userspace again if not all of the read from userspace made it in.
>
> I tested this by adding printk()s and writing files that would test -1, ==,
> and +1 the buffer size, to make sure that there's no overflows and that if a
> single line is written with +1 the buffer size, that it fails properly.
>
Thanks Steve!
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
BTW, this can conflict with my previous patch.
https://lkml.org/lkml/2017/2/6/1048
https://lkml.org/lkml/2017/2/7/203
I'll update this. Ingo, Can I send these patch to Steve?
Thank you,
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
> kernel/trace/trace_probe.c | 48 ++++++++++++++++++++++++++++------------------
> 1 file changed, 29 insertions(+), 19 deletions(-)
>
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index 8c0553d..2a06f1f 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -647,7 +647,7 @@ ssize_t traceprobe_probes_write(struct file *file, const char __user *buffer,
> size_t count, loff_t *ppos,
> int (*createfn)(int, char **))
> {
> - char *kbuf, *tmp;
> + char *kbuf, *buf, *tmp;
> int ret = 0;
> size_t done = 0;
> size_t size;
> @@ -667,27 +667,37 @@ ssize_t traceprobe_probes_write(struct file *file, const char __user *buffer,
> goto out;
> }
> kbuf[size] = '\0';
> - tmp = strchr(kbuf, '\n');
> + buf = kbuf;
> + do {
> + tmp = strchr(buf, '\n');
> + if (tmp) {
> + *tmp = '\0';
> + size = tmp - buf + 1;
> + } else {
> + size = strlen(buf);
> + if (done + size < count) {
> + if (buf != kbuf)
> + break;
> + pr_warn("Line length is too long: Should be less than %d\n",
> + WRITE_BUFSIZE);
> + ret = -EINVAL;
> + goto out;
> + }
> + }
> + done += size;
>
> - if (tmp) {
> - *tmp = '\0';
> - size = tmp - kbuf + 1;
> - } else if (done + size < count) {
> - pr_warn("Line length is too long: Should be less than %d\n",
> - WRITE_BUFSIZE);
> - ret = -EINVAL;
> - goto out;
> - }
> - done += size;
> - /* Remove comments */
> - tmp = strchr(kbuf, '#');
> + /* Remove comments */
> + tmp = strchr(buf, '#');
>
> - if (tmp)
> - *tmp = '\0';
> + if (tmp)
> + *tmp = '\0';
>
> - ret = traceprobe_command(kbuf, createfn);
> - if (ret)
> - goto out;
> + ret = traceprobe_command(buf, createfn);
> + if (ret)
> + goto out;
> + buf += size;
> +
> + } while (done < count);
> }
> ret = done;
>
> --
> 2.9.3
>
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2017-02-10 5:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-09 23:04 [RFC][PATCH] tracing: Have traceprobe_probes_write() not access userspace unnecessarily Steven Rostedt
2017-02-10 5:50 ` Masami Hiramatsu [this message]
2017-02-10 7:53 ` Ingo Molnar
2017-02-10 10:37 ` Masami Hiramatsu
2017-02-10 14:05 ` Steven Rostedt
2017-02-10 13:21 ` [PATCH V2 1/2] tracing/probes: Fix a warning message to show correct maximum length Masami Hiramatsu
2017-02-10 16:04 ` Steven Rostedt
2017-02-15 15:10 ` Masami Hiramatsu
2017-02-15 15:31 ` Steven Rostedt
2017-02-10 13:23 ` [PATCH V2 2/2] tracing/probe: Show subsystem name in messages Masami Hiramatsu
2017-02-10 16:01 ` Namhyung Kim
2017-02-10 16:17 ` Steven Rostedt
2017-02-10 22:35 ` Masami Hiramatsu
2017-02-10 22:36 ` [PATCH V3] " Masami Hiramatsu
2017-02-10 6:20 ` [RFC][PATCH] tracing: Have traceprobe_probes_write() not access userspace unnecessarily Namhyung Kim
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=20170210145006.b387236e4b6813a09d55162b@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.vnet.ibm.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