Commit f66578a7 authored by Li Zefan's avatar Li Zefan Committed by Ingo Molnar

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: default avatarLi Zefan <lizf@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49ED8DEB.6000700@cn.fujitsu.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent e8082f3f
...@@ -313,6 +313,7 @@ static int __filter_add_pred(struct ftrace_event_call *call, ...@@ -313,6 +313,7 @@ static int __filter_add_pred(struct ftrace_event_call *call,
{ {
struct ftrace_event_field *field; struct ftrace_event_field *field;
filter_pred_fn_t fn; filter_pred_fn_t fn;
unsigned long long val;
field = find_event_field(call, pred->field_name); field = find_event_field(call, pred->field_name);
if (!field) if (!field)
...@@ -322,14 +323,13 @@ static int __filter_add_pred(struct ftrace_event_call *call, ...@@ -322,14 +323,13 @@ static int __filter_add_pred(struct ftrace_event_call *call,
pred->offset = field->offset; pred->offset = field->offset;
if (is_string_field(field->type)) { if (is_string_field(field->type)) {
if (!pred->str_len)
return -EINVAL;
fn = filter_pred_string; fn = filter_pred_string;
pred->str_len = field->size; pred->str_len = field->size;
return filter_add_pred_fn(call, pred, fn); return filter_add_pred_fn(call, pred, fn);
} else { } else {
if (pred->str_len) if (strict_strtoull(pred->str_val, 0, &val))
return -EINVAL; return -EINVAL;
pred->val = val;
} }
switch (field->size) { switch (field->size) {
...@@ -413,12 +413,16 @@ int filter_add_subsystem_pred(struct event_subsystem *system, ...@@ -413,12 +413,16 @@ int filter_add_subsystem_pred(struct event_subsystem *system,
return 0; 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) int filter_parse(char **pbuf, struct filter_pred *pred)
{ {
char *tmp, *tok, *val_str = NULL; char *tok, *val_str = NULL;
int tok_n = 0; int tok_n = 0;
/* field ==/!= number, or/and field ==/!= number, number */
while ((tok = strsep(pbuf, " \n"))) { while ((tok = strsep(pbuf, " \n"))) {
if (tok_n == 0) { if (tok_n == 0) {
if (!strcmp(tok, "0")) { if (!strcmp(tok, "0")) {
...@@ -478,19 +482,13 @@ int filter_parse(char **pbuf, struct filter_pred *pred) ...@@ -478,19 +482,13 @@ int filter_parse(char **pbuf, struct filter_pred *pred)
return -EINVAL; return -EINVAL;
} }
strcpy(pred->str_val, val_str);
pred->str_len = strlen(val_str);
pred->field_name = kstrdup(pred->field_name, GFP_KERNEL); pred->field_name = kstrdup(pred->field_name, GFP_KERNEL);
if (!pred->field_name) if (!pred->field_name)
return -ENOMEM; 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; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment