[PATCH 3/3] tracing: don't set parser->cont if it has reached the end of input buffer
From: changbin . du
Date: Tue Jan 09 2018 - 05:04:55 EST
From: Changbin Du <changbin.du@xxxxxxxxx>
We should not set parser->cont if it has reached the end of input buffer.
And since some callers (like ftrace_graph_write()) treat it as an error
condition if trace_parser_cont() returns true.
For example, if userspace set 'set_ftrace_filter' by writing:
write(3, "abcdefg", 7)
Then in the kernel function ftrace_regex_write(), ftrace_process_regex()
will not be executed. The result is that the given filter will not be
applied at all.
ftrace_regex_write() {
...
read = trace_get_user(parser, ubuf, cnt, ppos);
if (read >= 0 && trace_parser_loaded(parser) &&
!trace_parser_cont(parser)) {
ret = ftrace_process_regex(iter, parser->buffer,
parser->idx, enable);
...
}
...
}
Signed-off-by: Changbin Du <changbin.du@xxxxxxxxx>
---
kernel/trace/trace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index e1baca0..79fdce2 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1269,7 +1269,8 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
parser->buffer[parser->idx] = 0;
parser->cont = false;
} else if (parser->idx < parser->size - 2) {
- parser->cont = true;
+ parser->cont = !!cnt;
+
parser->buffer[parser->idx++] = ch;
/* Make sure the parsed string always terminates with '\0'. */
parser->buffer[parser->idx] = 0;
--
2.7.4