Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1578193

Re: [RFC][PATCH] tracing: Have traceprobe_probes_write() not access userspace unnecessarily

From Namhyung Kim <namhyung@kernel.org>
Newsgroups linux.kernel
Subject Re: [RFC][PATCH] tracing: Have traceprobe_probes_write() not access userspace unnecessarily
Date 2017-02-10 07:30 +0100
Message-ID <t9cSt-8en-3@gated-at.bofh.it> (permalink)
References <t960G-3Z2-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Feb 09, 2017 at 06:04:58PM -0500, Steven Rostedt 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.
> 
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  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
> 

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[RFC][PATCH] tracing: Have traceprobe_probes_write() not access  userspace unnecessarily Steven Rostedt <rostedt@goodmis.org> - 2017-02-10 00:10 +0100
  Re: [RFC][PATCH] tracing: Have traceprobe_probes_write() not access  userspace unnecessarily Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-10 07:00 +0100
    Re: [RFC][PATCH] tracing: Have traceprobe_probes_write() not access  userspace unnecessarily Ingo Molnar <mingo@kernel.org> - 2017-02-10 09:00 +0100
      Re: [RFC][PATCH] tracing: Have traceprobe_probes_write() not access  userspace unnecessarily Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-10 11:40 +0100
        Re: [RFC][PATCH] tracing: Have traceprobe_probes_write() not access  userspace unnecessarily Steven Rostedt <rostedt@goodmis.org> - 2017-02-10 15:10 +0100
      [PATCH V2 1/2] tracing/probes: Fix a warning message to show correct maximum length Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-10 14:30 +0100
        Re: [PATCH V2 1/2] tracing/probes: Fix a warning message to show  correct maximum length Steven Rostedt <rostedt@goodmis.org> - 2017-02-10 17:20 +0100
      [PATCH V2 2/2] tracing/probe: Show subsystem name in messages Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-10 14:30 +0100
        Re: [PATCH V2 2/2] tracing/probe: Show subsystem name in messages Namhyung Kim <namhyung@kernel.org> - 2017-02-10 17:10 +0100
          Re: [PATCH V2 2/2] tracing/probe: Show subsystem name in messages Steven Rostedt <rostedt@goodmis.org> - 2017-02-10 17:20 +0100
            Re: [PATCH V2 2/2] tracing/probe: Show subsystem name in messages Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-10 23:40 +0100
            [PATCH V3] tracing/probe: Show subsystem name in messages Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-10 23:40 +0100
  Re: [RFC][PATCH] tracing: Have traceprobe_probes_write() not access  userspace unnecessarily Namhyung Kim <namhyung@kernel.org> - 2017-02-10 07:30 +0100

csiph-web