If writing subsys->filter returns EINVAL or ENOSPC, the original
filters in subsys/ and subsys/events/ will be removed. This is
definitely wrong.
Signed-off-by: Li Zefan <[email protected]>
---
kernel/trace/trace_events.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index aabf6ea..38cb568 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -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;
}
--
1.5.4.rc3
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().
Signed-off-by: Li Zefan <[email protected]>
---
kernel/trace/trace_events_filter.c | 26 ++++++++++++--------------
1 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index e0fcfd2..6541828 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -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;
}
--
1.5.4.rc3
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.
Signed-off-by: Li Zefan <[email protected]>
---
kernel/trace/trace_events_filter.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 6541828..0cc6229 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -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;
--
1.5.4.rc3
* Li Zefan <[email protected]> wrote:
> 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
Ingo Molnar wrote:
> * Li Zefan <[email protected]> wrote:
>
>> 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?
>
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
* Li Zefan <[email protected]> wrote:
> Ingo Molnar wrote:
> > * Li Zefan <[email protected]> wrote:
> >
> >> 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?
> >
>
> 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
Same argument though, no?
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 ]
Signed-off-by: Li Zefan <[email protected]>
Cc: Tom Zanussi <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/trace/trace_events.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 672b195..9ea55a7 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -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;
}
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 ]
Signed-off-by: Li Zefan <[email protected]>
Cc: Tom Zanussi <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/trace/trace_events_filter.c | 26 ++++++++++++--------------
1 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index e0fcfd2..6541828 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -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;
}
Ingo Molnar wrote:
> * Li Zefan <[email protected]> wrote:
>
>> Ingo Molnar wrote:
>>> * Li Zefan <[email protected]> wrote:
>>>
>>>> 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?
>>>
>> 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
>
> Same argument though, no?
>
Then I have no strong opinion on this. I'm fine to drop this patch.
* Li Zefan <[email protected]> wrote:
> Ingo Molnar wrote:
> > * Li Zefan <[email protected]> wrote:
> >
> >> Ingo Molnar wrote:
> >>> * Li Zefan <[email protected]> wrote:
> >>>
> >>>> 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?
> >>>
> >> 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
> >
> > 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)
Ingo
On Tue, 2009-04-21 at 12:16 +0200, Ingo Molnar wrote:
> * Li Zefan <[email protected]> wrote:
>
> > Ingo Molnar wrote:
> > > * Li Zefan <[email protected]> wrote:
> > >
> > >> Ingo Molnar wrote:
> > >>> * Li Zefan <[email protected]> wrote:
> > >>>
> > >>>> 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?
> > >>>
> > >> 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
> > >
> > > 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
>
> Ingo
* Tom Zanussi <[email protected]> wrote:
> On Tue, 2009-04-21 at 12:16 +0200, Ingo Molnar wrote:
> > * Li Zefan <[email protected]> wrote:
> >
> > > Ingo Molnar wrote:
> > > > * Li Zefan <[email protected]> wrote:
> > > >
> > > >> Ingo Molnar wrote:
> > > >>> * Li Zefan <[email protected]> wrote:
> > > >>>
> > > >>>> 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?
> > > >>>
> > > >> 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
> > > >
> > > > 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...
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
On Wed, 2009-04-22 at 10:09 +0200, Ingo Molnar wrote:
> * Tom Zanussi <[email protected]> wrote:
>
> > On Tue, 2009-04-21 at 12:16 +0200, Ingo Molnar wrote:
> > > * Li Zefan <[email protected]> wrote:
> > >
> > > > Ingo Molnar wrote:
> > > > > * Li Zefan <[email protected]> wrote:
> > > > >
> > > > >> Ingo Molnar wrote:
> > > > >>> * Li Zefan <[email protected]> wrote:
> > > > >>>
> > > > >>>> 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?
> > > > >>>
> > > > >> 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
> > > > >
> > > > > 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...
>
> 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
> Ingo