tracing/filters: don't remove old filters when failed to write subsys->filter
PATCH 1/3 tracing/filters: don't remove old filters when failed to write subsys->filter
If writing subsys->filter returns EINVAL or ENOSPC, the original filters in subsys/ and subsys/events/ will be removed. This is definitely wrong.
--- kernel/trace/trace_events.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
kernel/trace/trace_events.c +0 -1
@@ -600,7 +600,6 @@ subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, err =filter_add_subsystem_pred (system, pred);if (err <0 ) { -filter_free_subsystem_preds (system);filter_free_pred (pred);return err; }
Signature · 1 line
1.5.4.rc3
PATCH 2/3 tracing/filters: allow user-input to be integer-like string
Suppose we would like to trace all tasks named '123', but this will fail:
# echo 'parent_comm == 123' > events/sched/sched_process_fork/filter bash: echo: write error: Invalid argument
Don't guess the type of the filter pred in filter_parse(), but instead we check it in __filter_add_pred().
--- kernel/trace/trace_events_filter.c | 26 ++++++++++++-------------- 1 files changed, 12 insertions(+), 14 deletions(-)
kernel/trace/trace_events_filter.c +12 -14
@@ -313,6 +313,7 @@ static int __filter_add_pred(struct ftrace_event_call *call, {struct ftrace_event_field *field;filter_pred_fn_t fn; +unsigned long long val; field =find_event_field (call, pred->field_name);if (!field)
@@ -322,14 +323,13 @@ static int __filter_add_pred(struct ftrace_event_call *call, pred->offset = field->offset;if (is_string_field (field->type)) { -if (!pred->str_len) -return -EINVAL ; fn = filter_pred_string; pred->str_len = field->size;return filter_add_pred_fn (call, pred, fn); }else { -if (pred->str_len) +if (strict_strtoull (pred->str_val,0 , &val))return -EINVAL ; + pred->val = val; }switch (field->size) {
@@ -413,12 +413,16 @@ int filter_add_subsystem_pred(struct event_subsystem *system,return 0 ; } +/* +* The filter format can be +* - 0, which means remove all filter preds +* - [||/&&] <field> ==/!= <val> +*/ int filter_parse (char **pbuf,struct filter_pred *pred) { -char *tmp, *tok, *val_str =NULL ; +char *tok, *val_str =NULL ;int tok_n =0 ; -/* field ==/!= number, or/and field ==/!= number, number */ while ((tok =strsep (pbuf," \n" ))) {if (tok_n ==0 ) {if (!strcmp (tok,"0" )) {
@@ -478,19 +482,13 @@ int filter_parse(char **pbuf, struct filter_pred *pred)return -EINVAL ; } +strcpy (pred->str_val, val_str); + pred->str_len =strlen (val_str); + pred->field_name =kstrdup (pred->field_name,GFP_KERNEL );if (!pred->field_name)return -ENOMEM ; - pred->str_len =0 ; - pred->val =simple_strtoull (val_str, &tmp,0 ); -if (tmp == val_str) { -strncpy (pred->str_val, val_str,MAX_FILTER_STR_VAL ); - pred->str_len =strlen (val_str); - pred->str_val[pred->str_len] ='\0' ; - }else if (*tmp !='\0' ) -return -EINVAL ; -return 0 ; }
Signature · 1 line
1.5.4.rc3
[tip:tracing/core] tracing/filters: allow user-input to be integer-like string
Commit-ID: f66578a7637b87810cbb9041c4e3a77fd2fa4706 Gitweb: http://git.kernel.org/tip/f66578a7637b87810cbb9041c4e3a77fd2fa4706 Author: Li Zefan <[email protected]> AuthorDate: Tue, 21 Apr 2009 17:12:11 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 21 Apr 2009 11:58:28 +0200
tracing/filters: allow user-input to be integer-like string
Suppose we would like to trace all tasks named '123', but this will fail:
# echo 'parent_comm == 123' > events/sched/sched_process_fork/filter bash: echo: write error: Invalid argument
Don't guess the type of the filter pred in filter_parse(), but instead we check it in __filter_add_pred().
[ Impact: extend allowed filter field string values ]
LKML-Reference: <[email protected]>
--- kernel/trace/trace_events_filter.c | 26 ++++++++++++-------------- 1 files changed, 12 insertions(+), 14 deletions(-)
kernel/trace/trace_events_filter.c +12 -14
@@ -313,6 +313,7 @@ static int __filter_add_pred(struct ftrace_event_call *call, {struct ftrace_event_field *field;filter_pred_fn_t fn; +unsigned long long val; field =find_event_field (call, pred->field_name);if (!field)
@@ -322,14 +323,13 @@ static int __filter_add_pred(struct ftrace_event_call *call, pred->offset = field->offset;if (is_string_field (field->type)) { -if (!pred->str_len) -return -EINVAL ; fn = filter_pred_string; pred->str_len = field->size;return filter_add_pred_fn (call, pred, fn); }else { -if (pred->str_len) +if (strict_strtoull (pred->str_val,0 , &val))return -EINVAL ; + pred->val = val; }switch (field->size) {
@@ -413,12 +413,16 @@ int filter_add_subsystem_pred(struct event_subsystem *system,return 0 ; } +/* +* The filter format can be +* - 0, which means remove all filter preds +* - [||/&&] <field> ==/!= <val> +*/ int filter_parse (char **pbuf,struct filter_pred *pred) { -char *tmp, *tok, *val_str =NULL ; +char *tok, *val_str =NULL ;int tok_n =0 ; -/* field ==/!= number, or/and field ==/!= number, number */ while ((tok =strsep (pbuf," \n" ))) {if (tok_n ==0 ) {if (!strcmp (tok,"0" )) {
@@ -478,19 +482,13 @@ int filter_parse(char **pbuf, struct filter_pred *pred)return -EINVAL ; } +strcpy (pred->str_val, val_str); + pred->str_len =strlen (val_str); + pred->field_name =kstrdup (pred->field_name,GFP_KERNEL );if (!pred->field_name)return -ENOMEM ; - pred->str_len =0 ; - pred->val =simple_strtoull (val_str, &tmp,0 ); -if (tmp == val_str) { -strncpy (pred->str_val, val_str,MAX_FILTER_STR_VAL ); - pred->str_len =strlen (val_str); - pred->str_val[pred->str_len] ='\0' ; - }else if (*tmp !='\0' ) -return -EINVAL ; -return 0 ; }
PATCH 3/3 tracing/filters: disallow newline as delimeter
In reply to Li ZefanI guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
--- kernel/trace/trace_events_filter.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
kernel/trace/trace_events_filter.c +3 -1
@@ -423,7 +423,9 @@ int filter_parse(char **pbuf, struct filter_pred *pred)char *tok, *val_str =NULL ;int tok_n =0 ; -while ((tok =strsep (pbuf," \n" ))) { +strstrip (*pbuf); + +while ((tok =strsep (pbuf," " ))) {if (tok_n ==0 ) {if (!strcmp (tok,"0" )) { pred->clear =1 ;
Signature · 1 line
1.5.4.rc3
Re: [PATCH 3/3] tracing/filters: disallow newline as delimeter
Quoted 3 lines · Li Zefan
I guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
Hm, how about:
( echo 'x'
echo '|| y' ) > filter
type of scripts? Shouldnt the parser be permissive in general?
Ingo
Re: [PATCH 3/3] tracing/filters: disallow newline as delimeter
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Li Zefan
I guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
Quoted 7 lines
Hm, how about:
( echo 'x'
echo '|| y' ) > filtertype of scripts? Shouldnt the parser be permissive in general?
This patch doesn't forbid this usage: ;)
( echo 'parent_comm == a'
echo '|| parent_comm == b' ) > filter
This patch does forbid this usage:
( echo 'parent_comm'
echo '=='
echo 'a' ) > filter
--
Zefan
Re: [PATCH 3/3] tracing/filters: disallow newline as delimeter
Quoted 17 lines · Li Zefan
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Li Zefan
I guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
Quoted 7 lines
Hm, how about:
( echo 'x'
echo '|| y' ) > filtertype of scripts? Shouldnt the parser be permissive in general?
This patch doesn't forbid this usage: ;)
Quoted 8 lines
( echo '
parent_comm== a'
echo '||parent_comm== b' ) > filterThis patch does forbid this usage:
( echo '
parent_comm'
echo '=='
echo 'a' ) > filter
Same argument though, no?
Ingo
Re: [PATCH 3/3] tracing/filters: disallow newline as delimeter
Quoted 20 lines · Ingo Molnar
Quoted 18 lines · Li Zefan
Quoted 5 lines · Ingo Molnar
Quoted 3 lines · Li Zefan
I guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
Quoted 7 lines
Hm, how about:
( echo 'x'
echo '|| y' ) > filtertype of scripts? Shouldnt the parser be permissive in general?
This patch doesn't forbid this usage: ;)
( echo '
parent_comm== a'
echo '||parent_comm== b' ) > filter
Quoted 8 lines
Quoted 5 lines
This patch does forbid this usage:
( echo '
parent_comm'
echo '=='
echo 'a' ) > filterSame argument though, no?
Then I have no strong opinion on this. I'm fine to drop this patch.
Re: [PATCH 3/3] tracing/filters: disallow newline as delimeter
Quoted 23 lines · Li Zefan
Quoted 22 lines · Ingo Molnar
Quoted 20 lines · Li Zefan
Quoted 5 lines · Ingo Molnar
Quoted 3 lines · Li Zefan
I guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
Quoted 7 lines
Hm, how about:
( echo 'x'
echo '|| y' ) > filtertype of scripts? Shouldnt the parser be permissive in general?
This patch doesn't forbid this usage: ;)
( echo '
parent_comm== a'
echo '||parent_comm== b' ) > filterThis patch does forbid this usage:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
( echo '
parent_comm'
echo '=='
echo 'a' ) > filterSame argument though, no?
Then I have no strong opinion on this. I'm fine to drop this patch.
I've applied the other two - no strong opinion either about this patch. Tom, what do you think? (there's also some new parser in the works i suspect)
Ingo
Re: [PATCH 3/3] tracing/filters: disallow newline as delimeter
Quoted 29 lines · Ingo Molnar
Quoted 27 lines · Li Zefan
Quoted 26 lines · Ingo Molnar
Quoted 23 lines · Li Zefan
Quoted 5 lines · Ingo Molnar
Quoted 3 lines · Li Zefan
I guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
Quoted 7 lines
Hm, how about:
( echo 'x'
echo '|| y' ) > filtertype of scripts? Shouldnt the parser be permissive in general?
This patch doesn't forbid this usage: ;)
( echo '
parent_comm== a'
echo '||parent_comm== b' ) > filterThis patch does forbid this usage:
( echo '
parent_comm'
echo '=='
echo 'a' ) > filter
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Same argument though, no?
Then I have no strong opinion on this. I'm fine to drop this patch.
I've applied the other two - no strong opinion either about this patch. Tom, what do you think? (there's also some new parser in the works i suspect)
I think it works ok as it is, so dropping this patch would be fine with me.
I am working on a new parser; I'd hoped to have it finished by now, but I seem to be continually distracted lately. :-( At this point I have a parser that basically works; the main thing it still needs and what I'm working on now is a way to allow it to be easily extended to support special-case handling for special types e.g. if a predicate field refers to something that's a dev_t, the user should be able to specify 'device == /dev/sda' or 'device == sda' or 'device == (8,1)' or 'device == 8:1', so it should be relatively easy to add that kind of support to the parser when there's a need for it.
Once that's done, I'll hook it all up and post it as soon as I can, at the end of the week hopefully...
Tom
Quoted 2 lines
Ingo
Re: [PATCH 3/3] tracing/filters: disallow newline as delimeter
Quoted 53 lines · Tom Zanussi
Quoted 29 lines · Ingo Molnar
Quoted 27 lines · Li Zefan
Quoted 26 lines · Ingo Molnar
Quoted 23 lines · Li Zefan
Quoted 5 lines · Ingo Molnar
Quoted 3 lines · Li Zefan
I guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
Quoted 7 lines
Hm, how about:
( echo 'x'
echo '|| y' ) > filtertype of scripts? Shouldnt the parser be permissive in general?
This patch doesn't forbid this usage: ;)
( echo '
parent_comm== a'
echo '||parent_comm== b' ) > filterThis patch does forbid this usage:
( echo '
parent_comm'
echo '=='
echo 'a' ) > filterQuoted 8 lines
Quoted 4 lines
Quoted 2 lines
Same argument though, no?
Then I have no strong opinion on this. I'm fine to drop this patch.
I've applied the other two - no strong opinion either about this patch. Tom, what do you think? (there's also some new parser in the works i suspect)
I think it works ok as it is, so dropping this patch would be fine with me.
I am working on a new parser; I'd hoped to have it finished by now, but I seem to be continually distracted lately. :-( At this point I have a parser that basically works; the main thing it still needs and what I'm working on now is a way to allow it to be easily extended to support special-case handling for special types e.g. if a predicate field refers to something that's a
dev_t, the user should be able to specify 'device ==/dev/sda' or 'device == sda' or 'device == (8,1)' or 'device == 8:1', so it should be relatively easy to add that kind of support to the parser when there's a need for it.
Quoted 2 lines
Once that's done, I'll hook it all up and post it as soon as I can, at the end of the week hopefully...
Nice! :-)
If your current lineup works you might want to post that straight away even without the type extensions, if you think there's value in testing/reviewing those bits independently. It generally works better to have gradual patches. (we can find bugs sooner, review is easier, etc.)
Ingo
Re: [PATCH 3/3] tracing/filters: disallow newline as delimeter
Quoted 58 lines · Ingo Molnar
Quoted 53 lines · Tom Zanussi
Quoted 29 lines · Ingo Molnar
Quoted 27 lines · Li Zefan
Quoted 26 lines · Ingo Molnar
Quoted 23 lines · Li Zefan
Quoted 5 lines · Ingo Molnar
Quoted 3 lines · Li Zefan
I guess because user input is often ended with '\n' (like "echo xxx"), thus '\n' is used as a delimeter besides ' ', but we can just strip tailing spaces.
Quoted 7 lines
Hm, how about:
( echo 'x'
echo '|| y' ) > filtertype of scripts? Shouldnt the parser be permissive in general?
This patch doesn't forbid this usage: ;)
( echo '
parent_comm== a'
echo '||parent_comm== b' ) > filterThis patch does forbid this usage:
( echo '
parent_comm'
echo '=='
echo 'a' ) > filterQuoted 8 lines
Quoted 4 lines
Quoted 2 lines
Same argument though, no?
Then I have no strong opinion on this. I'm fine to drop this patch.
I've applied the other two - no strong opinion either about this patch. Tom, what do you think? (there's also some new parser in the works i suspect)
I think it works ok as it is, so dropping this patch would be fine with me.
I am working on a new parser; I'd hoped to have it finished by now, but I seem to be continually distracted lately. :-( At this point I have a parser that basically works; the main thing it still needs and what I'm working on now is a way to allow it to be easily extended to support special-case handling for special types e.g. if a predicate field refers to something that's a
dev_t, the user should be able to specify 'device ==/dev/sda' or 'device == sda' or 'device == (8,1)' or 'device == 8:1', so it should be relatively easy to add that kind of support to the parser when there's a need for it.Quoted 2 lines
Once that's done, I'll hook it all up and post it as soon as I can, at the end of the week hopefully...
Quoted 8 lines
Nice! :-)
If your current lineup works you might want to post that straight away even without the type extensions, if you think there's value in testing/reviewing those bits independently. It generally works better to have gradual patches. (we can find bugs sooner, review is easier, etc.)
Sure, I understand. I wasn't planning on adding any type extensions with the initial parser, just restructuring the code so that adding them wouldn't require a lot of restructuring later. So, yeah, just the basic parser once I get it into a postable state, very soon, and anything else for later...
Tom
Quoted 1 line
Ingo
Commit-ID: e8082f3f5a17d7a7bfc7dd1050a3f958dc034e9a Gitweb: http://git.kernel.org/tip/e8082f3f5a17d7a7bfc7dd1050a3f958dc034e9a Author: Li Zefan <[email protected]> AuthorDate: Tue, 21 Apr 2009 17:11:46 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 21 Apr 2009 11:58:27 +0200
tracing/filters: don't remove old filters when failed to write subsys->filter
If writing subsys->filter returns EINVAL or ENOSPC, the original filters in subsys/ and subsys/events/ will be removed. This is definitely wrong.
[ Impact: fix filter setting semantics on error condition ]
LKML-Reference: <[email protected]>
--- kernel/trace/trace_events.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
kernel/trace/trace_events.c +0 -1
@@ -600,7 +600,6 @@ subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, err =filter_add_subsystem_pred (system, pred);if (err <0 ) { -filter_free_subsystem_preds (system);filter_free_pred (pred);return err; }