From: tip-bot for Li Zefan <lizf@cn.fujitsu.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
tzanussi@gmail.com, lizf@cn.fujitsu.com, fweisbec@gmail.com,
rostedt@goodmis.org, tglx@linutronix.de, mingo@elte.hu
Subject: [tip:tracing/core] tracing/filters: allow user-input to be integer-like string
Date: Tue, 21 Apr 2009 10:08:23 GMT [thread overview]
Message-ID: <tip-f66578a7637b87810cbb9041c4e3a77fd2fa4706@git.kernel.org> (raw)
In-Reply-To: <49ED8DEB.6000700@cn.fujitsu.com>
Commit-ID: f66578a7637b87810cbb9041c4e3a77fd2fa4706
Gitweb: http://git.kernel.org/tip/f66578a7637b87810cbb9041c4e3a77fd2fa4706
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Tue, 21 Apr 2009 17:12:11 +0800
Committer: Ingo Molnar <mingo@elte.hu>
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 <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: Ingo Molnar <mingo@elte.hu>
---
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;
}
next prev parent reply other threads:[~2009-04-21 10:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-21 9:11 [PATCH 1/3] tracing/filters: don't remove old filters when failed to write subsys->filter Li Zefan
2009-04-21 9:12 ` [PATCH 2/3] tracing/filters: allow user-input to be integer-like string Li Zefan
2009-04-21 10:08 ` tip-bot for Li Zefan [this message]
2009-04-21 9:12 ` [PATCH 3/3] tracing/filters: disallow newline as delimeter Li Zefan
2009-04-21 9:57 ` Ingo Molnar
2009-04-21 10:06 ` Li Zefan
2009-04-21 10:07 ` Ingo Molnar
2009-04-21 10:14 ` Li Zefan
2009-04-21 10:16 ` Ingo Molnar
2009-04-22 5:21 ` Tom Zanussi
2009-04-22 8:09 ` Ingo Molnar
2009-04-23 5:18 ` Tom Zanussi
2009-04-21 10:08 ` [tip:tracing/core] tracing/filters: don't remove old filters when failed to write subsys->filter tip-bot for Li Zefan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-f66578a7637b87810cbb9041c4e3a77fd2fa4706@git.kernel.org \
--to=lizf@cn.fujitsu.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tzanussi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).