diff options
author | Jiri Olsa <jolsa@redhat.com> | 2009-08-11 11:29:04 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-08-18 20:39:48 -0400 |
commit | eda1e328556565e211b7450250e40d6de751563a (patch) | |
tree | a0d4d6c056f3c4452a9a7d0e4b9af52e7a2d089d /kernel | |
parent | f2d84b65b9778e8a35dd904f7d3993f0a60c9756 (diff) |
tracing: handle broken names in ftrace filter
If one filter item (for set_ftrace_filter and set_ftrace_notrace) is being
setup by more than 1 consecutive writes (FTRACE_ITER_CONT flag), it won't
be handled corretly.
I used following program to test/verify:
[snip]
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int main(int argc, char **argv)
{
int fd, i;
char *file = argv[1];
if (-1 == (fd = open(file, O_WRONLY))) {
perror("open failed");
return -1;
}
for(i = 0; i < (argc - 2); i++) {
int len = strlen(argv[2+i]);
int cnt, off = 0;
while(len) {
cnt = write(fd, argv[2+i] + off, len);
len -= cnt;
off += cnt;
}
}
close(fd);
return 0;
}
[snip]
before change:
sh-4.0# echo > ./set_ftrace_filter
sh-4.0# /test ./set_ftrace_filter "sys" "_open "
sh-4.0# cat ./set_ftrace_filter
#### all functions enabled ####
sh-4.0#
after change:
sh-4.0# echo > ./set_ftrace_notrace
sh-4.0# test ./set_ftrace_notrace "sys" "_open "
sh-4.0# cat ./set_ftrace_notrace
sys_open
sh-4.0#
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
LKML-Reference: <20090811152904.GA26065@jolsa.lab.eng.brq.redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/trace/ftrace.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 1e1d23c26308..25edd5cc5935 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -2278,7 +2278,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, | |||
2278 | read++; | 2278 | read++; |
2279 | cnt--; | 2279 | cnt--; |
2280 | 2280 | ||
2281 | if (!(iter->flags & ~FTRACE_ITER_CONT)) { | 2281 | /* |
2282 | * If the parser haven't finished with the last write, | ||
2283 | * continue reading the user input without skipping spaces. | ||
2284 | */ | ||
2285 | if (!(iter->flags & FTRACE_ITER_CONT)) { | ||
2282 | /* skip white space */ | 2286 | /* skip white space */ |
2283 | while (cnt && isspace(ch)) { | 2287 | while (cnt && isspace(ch)) { |
2284 | ret = get_user(ch, ubuf++); | 2288 | ret = get_user(ch, ubuf++); |
@@ -2288,8 +2292,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, | |||
2288 | cnt--; | 2292 | cnt--; |
2289 | } | 2293 | } |
2290 | 2294 | ||
2295 | /* only spaces were written */ | ||
2291 | if (isspace(ch)) { | 2296 | if (isspace(ch)) { |
2292 | file->f_pos += read; | 2297 | *ppos += read; |
2293 | ret = read; | 2298 | ret = read; |
2294 | goto out; | 2299 | goto out; |
2295 | } | 2300 | } |
@@ -2319,12 +2324,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, | |||
2319 | if (ret) | 2324 | if (ret) |
2320 | goto out; | 2325 | goto out; |
2321 | iter->buffer_idx = 0; | 2326 | iter->buffer_idx = 0; |
2322 | } else | 2327 | } else { |
2323 | iter->flags |= FTRACE_ITER_CONT; | 2328 | iter->flags |= FTRACE_ITER_CONT; |
2329 | iter->buffer[iter->buffer_idx++] = ch; | ||
2330 | } | ||
2324 | 2331 | ||
2325 | 2332 | *ppos += read; | |
2326 | file->f_pos += read; | ||
2327 | |||
2328 | ret = read; | 2333 | ret = read; |
2329 | out: | 2334 | out: |
2330 | mutex_unlock(&ftrace_regex_lock); | 2335 | mutex_unlock(&ftrace_regex_lock); |