aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (VMware) <rostedt@goodmis.org>2017-02-09 17:53:50 -0500
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2017-02-15 09:00:55 -0500
commit1f9b3546cf4c273b6d809003244d05cf0460a5e9 (patch)
tree67b22717ba453ac9afbf9bd84ae261cd4ae05772
parent4c7384131c8d343c0bf79abac3b3e78596d85b10 (diff)
tracing: Have traceprobe_probes_write() not access userspace unnecessarily
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 once. 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. Link: http://lkml.kernel.org/r/20170209180458.5c829ab2@gandalf.local.home Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Acked-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--kernel/trace/trace_probe.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 8c0553d9afd3..2a06f1fa7001 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,
647 size_t count, loff_t *ppos, 647 size_t count, loff_t *ppos,
648 int (*createfn)(int, char **)) 648 int (*createfn)(int, char **))
649{ 649{
650 char *kbuf, *tmp; 650 char *kbuf, *buf, *tmp;
651 int ret = 0; 651 int ret = 0;
652 size_t done = 0; 652 size_t done = 0;
653 size_t size; 653 size_t size;
@@ -667,27 +667,37 @@ ssize_t traceprobe_probes_write(struct file *file, const char __user *buffer,
667 goto out; 667 goto out;
668 } 668 }
669 kbuf[size] = '\0'; 669 kbuf[size] = '\0';
670 tmp = strchr(kbuf, '\n'); 670 buf = kbuf;
671 do {
672 tmp = strchr(buf, '\n');
673 if (tmp) {
674 *tmp = '\0';
675 size = tmp - buf + 1;
676 } else {
677 size = strlen(buf);
678 if (done + size < count) {
679 if (buf != kbuf)
680 break;
681 pr_warn("Line length is too long: Should be less than %d\n",
682 WRITE_BUFSIZE);
683 ret = -EINVAL;
684 goto out;
685 }
686 }
687 done += size;
671 688
672 if (tmp) { 689 /* Remove comments */
673 *tmp = '\0'; 690 tmp = strchr(buf, '#');
674 size = tmp - kbuf + 1;
675 } else if (done + size < count) {
676 pr_warn("Line length is too long: Should be less than %d\n",
677 WRITE_BUFSIZE);
678 ret = -EINVAL;
679 goto out;
680 }
681 done += size;
682 /* Remove comments */
683 tmp = strchr(kbuf, '#');
684 691
685 if (tmp) 692 if (tmp)
686 *tmp = '\0'; 693 *tmp = '\0';
687 694
688 ret = traceprobe_command(kbuf, createfn); 695 ret = traceprobe_command(buf, createfn);
689 if (ret) 696 if (ret)
690 goto out; 697 goto out;
698 buf += size;
699
700 } while (done < count);
691 } 701 }
692 ret = done; 702 ret = done;
693 703