Commit 6f3cf440 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Ingo Molnar

kprobe-tracer: Check new event/group name

Check new event/group name is same syntax as a C symbol. In other
words, checking the name is as like as other tracepoint events.

This can prevent user to create an event with useless name (e.g.
foo|bar, foo*bar).
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
LKML-Reference: <20091216222408.14459.68790.stgit@dhcp-100-2-132.bos.redhat.com>
[ v2: minor cleanups ]
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 96c96612
...@@ -282,6 +282,18 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs); ...@@ -282,6 +282,18 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs);
static int kretprobe_dispatcher(struct kretprobe_instance *ri, static int kretprobe_dispatcher(struct kretprobe_instance *ri,
struct pt_regs *regs); struct pt_regs *regs);
/* Check the name is good for event/group */
static int check_event_name(const char *name)
{
if (!isalpha(*name) && *name != '_')
return 0;
while (*++name != '\0') {
if (!isalpha(*name) && !isdigit(*name) && *name != '_')
return 0;
}
return 1;
}
/* /*
* Allocate new trace_probe and initialize it (including kprobes). * Allocate new trace_probe and initialize it (including kprobes).
*/ */
...@@ -293,10 +305,11 @@ static struct trace_probe *alloc_trace_probe(const char *group, ...@@ -293,10 +305,11 @@ static struct trace_probe *alloc_trace_probe(const char *group,
int nargs, int is_return) int nargs, int is_return)
{ {
struct trace_probe *tp; struct trace_probe *tp;
int ret = -ENOMEM;
tp = kzalloc(SIZEOF_TRACE_PROBE(nargs), GFP_KERNEL); tp = kzalloc(SIZEOF_TRACE_PROBE(nargs), GFP_KERNEL);
if (!tp) if (!tp)
return ERR_PTR(-ENOMEM); return ERR_PTR(ret);
if (symbol) { if (symbol) {
tp->symbol = kstrdup(symbol, GFP_KERNEL); tp->symbol = kstrdup(symbol, GFP_KERNEL);
...@@ -312,14 +325,20 @@ static struct trace_probe *alloc_trace_probe(const char *group, ...@@ -312,14 +325,20 @@ static struct trace_probe *alloc_trace_probe(const char *group,
else else
tp->rp.kp.pre_handler = kprobe_dispatcher; tp->rp.kp.pre_handler = kprobe_dispatcher;
if (!event) if (!event || !check_event_name(event)) {
ret = -EINVAL;
goto error; goto error;
}
tp->call.name = kstrdup(event, GFP_KERNEL); tp->call.name = kstrdup(event, GFP_KERNEL);
if (!tp->call.name) if (!tp->call.name)
goto error; goto error;
if (!group) if (!group || !check_event_name(group)) {
ret = -EINVAL;
goto error; goto error;
}
tp->call.system = kstrdup(group, GFP_KERNEL); tp->call.system = kstrdup(group, GFP_KERNEL);
if (!tp->call.system) if (!tp->call.system)
goto error; goto error;
...@@ -330,7 +349,7 @@ static struct trace_probe *alloc_trace_probe(const char *group, ...@@ -330,7 +349,7 @@ static struct trace_probe *alloc_trace_probe(const char *group,
kfree(tp->call.name); kfree(tp->call.name);
kfree(tp->symbol); kfree(tp->symbol);
kfree(tp); kfree(tp);
return ERR_PTR(-ENOMEM); return ERR_PTR(ret);
} }
static void free_probe_arg(struct probe_arg *arg) static void free_probe_arg(struct probe_arg *arg)
...@@ -695,10 +714,10 @@ static int create_trace_probe(int argc, char **argv) ...@@ -695,10 +714,10 @@ static int create_trace_probe(int argc, char **argv)
if (!event) { if (!event) {
/* Make a new event name */ /* Make a new event name */
if (symbol) if (symbol)
snprintf(buf, MAX_EVENT_NAME_LEN, "%c@%s%+ld", snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_%ld",
is_return ? 'r' : 'p', symbol, offset); is_return ? 'r' : 'p', symbol, offset);
else else
snprintf(buf, MAX_EVENT_NAME_LEN, "%c@0x%p", snprintf(buf, MAX_EVENT_NAME_LEN, "%c_0x%p",
is_return ? 'r' : 'p', addr); is_return ? 'r' : 'p', addr);
event = buf; event = buf;
} }
......
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