tracing: FTRACE_ITER_CONT handling fix
PATCH 1/1 tracing: FTRACE_ITER_CONT handling fix
Hi,
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_notracesys_open
sh-4.0#
wbr,
jirka
---
kernel/trace/ftrace.c +11 -6
@@ -2233,7 +2233,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, read++; cnt--; -if (!(iter->flags & ~FTRACE_ITER_CONT )) { +/* +* If the parser haven't finished with the last write, +* continue reading the user input without skipping spaces. +*/ +if (!(iter->flags &FTRACE_ITER_CONT )) {/* skip white space */ while (cnt &&isspace (ch)) { ret =get_user (ch, ubuf++);
@@ -2243,8 +2247,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, cnt--; } +/* only spaces were written */ if (isspace (ch)) { - file->f_pos += read; + *ppos += read; ret = read; goto out; }
@@ -2273,12 +2278,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,if (ret) goto out; iter->buffer_idx =0 ; - }else + }else { iter->flags |=FTRACE_ITER_CONT ; + iter->buffer[iter->buffer_idx++] = ch; + } - - file->f_pos += read; - + *ppos += read; ret = read; out:mutex_unlock (&ftrace_regex_lock);
Quoted 39 lines · Jiri Olsa
Hi,
if one filter item (for
set_ftrace_filterandset_ftrace_notrace) is being setup by more than 1 consecutive writes (FTRACE_ITER_CONTflag), 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; }
Quoted 1 line
[snip]
BTW, you did not need to make such a test, just doing:
# echo sys_open | dd of=set_ftrace_filter bs=2
works as well.
Quoted 15 lines
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_notracesys_open
sh-4.0#
Quoted 5 lines
wbr,
jirkaSigned-off-by Jiri Olsa <[email protected]>
Thanks, applied!
-- Steve
Quoted 48 lines
---
kernel/trace/ftrace.c +11
-6@@ -2233,7 +2233,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, read++; cnt--; -if (!(iter->flags & ~FTRACE_ITER_CONT )) { +/* +* If the parser haven't finished with the last write, +* continue reading the user input without skipping spaces. +*/ +if (!(iter->flags &FTRACE_ITER_CONT )) {/* skip white space */ while (cnt &&isspace (ch)) { ret =get_user (ch, ubuf++);@@ -2243,8 +2247,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, cnt--; } +/* only spaces were written */ if (isspace (ch)) { - file->f_pos += read; + *ppos += read; ret = read; goto out; }@@ -2273,12 +2278,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,if (ret) goto out; iter->buffer_idx =0 ; - }else + }else { iter->flags |=FTRACE_ITER_CONT ; + iter->buffer[iter->buffer_idx++] = ch; + } - - file->f_pos += read; - + *ppos += read; ret = read; out:mutex_unlock (&ftrace_regex_lock);
Quoted 44 lines · Steven Rostedt
Quoted 39 lines · Jiri Olsa
Hi,
if one filter item (for
set_ftrace_filterandset_ftrace_notrace) is being setup by more than 1 consecutive writes (FTRACE_ITER_CONTflag), 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; }Quoted 1 line
[snip]
Quoted 6 lines
BTW, you did not need to make such a test, just doing:
# echo sys_open | dd of=set_ftrace_filter bs=2works as well.
cool :) thanks
jirka
Quoted 74 lines
Quoted 16 lines
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_notracesys_open
sh-4.0#Quoted 5 lines
wbr,
jirkaSigned-off-by Jiri Olsa <[email protected]>Thanks, applied!
-- Steve
Quoted 48 lines
---
kernel/trace/ftrace.c +11
-6@@ -2233,7 +2233,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, read++; cnt--; -if (!(iter->flags & ~FTRACE_ITER_CONT )) { +/* +* If the parser haven't finished with the last write, +* continue reading the user input without skipping spaces. +*/ +if (!(iter->flags &FTRACE_ITER_CONT )) {/* skip white space */ while (cnt &&isspace (ch)) { ret =get_user (ch, ubuf++);@@ -2243,8 +2247,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, cnt--; } +/* only spaces were written */ if (isspace (ch)) { - file->f_pos += read; + *ppos += read; ret = read; goto out; }@@ -2273,12 +2278,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,if (ret) goto out; iter->buffer_idx =0 ; - }else + }else { iter->flags |=FTRACE_ITER_CONT ; + iter->buffer[iter->buffer_idx++] = ch; + } - - file->f_pos += read; - + *ppos += read; ret = read; out:mutex_unlock (&ftrace_regex_lock);
Steven Rostedt
maintainer[GIT PULL][2.6.31] tracing: handle broken names in ftrace filter
In reply to Jiri OlsaIngo,
Please pull the latest tip/tracing/urgent tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/urgent
Jiri Olsa (1):
tracing: handle broken names in ftrace filter
----
kernel/trace/ftrace.c | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-) --------------------------- commit eda1e328556565e211b7450250e40d6de751563a Author: Jiri Olsa <[email protected]> Date: Tue Aug 11 17:29:04 2009 +0200
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 <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>kernel/trace/ftrace.c +11 -6
@@ -2278,7 +2278,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, read++; cnt--; -if (!(iter->flags & ~FTRACE_ITER_CONT )) { +/* +* If the parser haven't finished with the last write, +* continue reading the user input without skipping spaces. +*/ +if (!(iter->flags &FTRACE_ITER_CONT )) {/* skip white space */ while (cnt &&isspace (ch)) { ret =get_user (ch, ubuf++);
@@ -2288,8 +2292,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, cnt--; } +/* only spaces were written */ if (isspace (ch)) { - file->f_pos += read; + *ppos += read; ret = read; goto out; }
@@ -2319,12 +2324,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,if (ret) goto out; iter->buffer_idx =0 ; - }else + }else { iter->flags |=FTRACE_ITER_CONT ; + iter->buffer[iter->buffer_idx++] = ch; + } - - file->f_pos += read; - + *ppos += read; ret = read; out:mutex_unlock (&ftrace_regex_lock);
Re: [GIT PULL][2.6.31] tracing: handle broken names in ftrace filter
Quoted 9 lines · Steven Rostedt
Ingo,
Please pull the latest tip/tracing/urgent tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/urgent
Quoted 6 lines
Jiri Olsa (1):
tracing: handle broken names in ftrace filter----
kernel/trace/ftrace.c | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-)
Pulled, thanks Steve!
Ingo
[tip:tracing/urgent] tracing: handle broken names in ftrace filter
In reply to Jiri OlsaCommit-ID: eda1e328556565e211b7450250e40d6de751563a Gitweb: http://git.kernel.org/tip/eda1e328556565e211b7450250e40d6de751563a Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 11 Aug 2009 17:29:04 +0200 Committer: Steven Rostedt <[email protected]> CommitDate: Tue, 18 Aug 2009 20:39:48 -0400
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_notracesys_open
sh-4.0#
LKML-Reference: <[email protected]>
--- kernel/trace/ftrace.c | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-)
kernel/trace/ftrace.c +11 -6
@@ -2278,7 +2278,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, read++; cnt--; -if (!(iter->flags & ~FTRACE_ITER_CONT )) { +/* +* If the parser haven't finished with the last write, +* continue reading the user input without skipping spaces. +*/ +if (!(iter->flags &FTRACE_ITER_CONT )) {/* skip white space */ while (cnt &&isspace (ch)) { ret =get_user (ch, ubuf++);
@@ -2288,8 +2292,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, cnt--; } +/* only spaces were written */ if (isspace (ch)) { - file->f_pos += read; + *ppos += read; ret = read; goto out; }
@@ -2319,12 +2324,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,if (ret) goto out; iter->buffer_idx =0 ; - }else + }else { iter->flags |=FTRACE_ITER_CONT ; + iter->buffer[iter->buffer_idx++] = ch; + } - - file->f_pos += read; - + *ppos += read; ret = read; out:mutex_unlock (&ftrace_regex_lock);