diff options
author | Masami Hiramatsu <mhiramat@redhat.com> | 2009-11-30 19:19:20 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-12-01 02:19:59 -0500 |
commit | ba8665d7dd95eb6093ee06f8f624b6acb1e73206 (patch) | |
tree | 8f5f92a2bb5c115a6d69b9d552804cea7027a60f /kernel/trace/trace_kprobe.c | |
parent | 5cbd08056142dcb2aea0dca7261afcb810a63c55 (diff) |
trace_kprobes: Fix a memory leak bug and check kstrdup() return value
Fix a memory leak case in create_trace_probe(). When an argument
is too long (> MAX_ARGSTR_LEN), it just jumps to error path. In
that case tp->args[i].name is not released.
This also fixes a bug to check kstrdup()'s return value.
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
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: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
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: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091201001919.10235.56455.stgit@harusame>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace/trace_kprobe.c')
-rw-r--r-- | kernel/trace/trace_kprobe.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 72d0c65c8676..aff5f80b59b8 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -483,7 +483,8 @@ static int parse_probe_vars(char *arg, struct fetch_func *ff, int is_return) | |||
483 | return ret; | 483 | return ret; |
484 | } | 484 | } |
485 | 485 | ||
486 | static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | 486 | /* Recursive argument parser */ |
487 | static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | ||
487 | { | 488 | { |
488 | int ret = 0; | 489 | int ret = 0; |
489 | unsigned long param; | 490 | unsigned long param; |
@@ -543,7 +544,7 @@ static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | |||
543 | if (!id) | 544 | if (!id) |
544 | return -ENOMEM; | 545 | return -ENOMEM; |
545 | id->offset = offset; | 546 | id->offset = offset; |
546 | ret = parse_probe_arg(arg, &id->orig, is_return); | 547 | ret = __parse_probe_arg(arg, &id->orig, is_return); |
547 | if (ret) | 548 | if (ret) |
548 | kfree(id); | 549 | kfree(id); |
549 | else { | 550 | else { |
@@ -560,6 +561,16 @@ static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | |||
560 | return ret; | 561 | return ret; |
561 | } | 562 | } |
562 | 563 | ||
564 | /* String length checking wrapper */ | ||
565 | static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | ||
566 | { | ||
567 | if (strlen(arg) > MAX_ARGSTR_LEN) { | ||
568 | pr_info("Argument is too long.: %s\n", arg); | ||
569 | return -ENOSPC; | ||
570 | } | ||
571 | return __parse_probe_arg(arg, ff, is_return); | ||
572 | } | ||
573 | |||
563 | /* Return 1 if name is reserved or already used by another argument */ | 574 | /* Return 1 if name is reserved or already used by another argument */ |
564 | static int conflict_field_name(const char *name, | 575 | static int conflict_field_name(const char *name, |
565 | struct probe_arg *args, int narg) | 576 | struct probe_arg *args, int narg) |
@@ -698,13 +709,14 @@ static int create_trace_probe(int argc, char **argv) | |||
698 | } | 709 | } |
699 | 710 | ||
700 | tp->args[i].name = kstrdup(argv[i], GFP_KERNEL); | 711 | tp->args[i].name = kstrdup(argv[i], GFP_KERNEL); |
701 | 712 | if (!tp->args[i].name) { | |
702 | /* Parse fetch argument */ | 713 | pr_info("Failed to allocate argument%d name '%s'.\n", |
703 | if (strlen(arg) > MAX_ARGSTR_LEN) { | 714 | i, argv[i]); |
704 | pr_info("Argument%d(%s) is too long.\n", i, arg); | 715 | ret = -ENOMEM; |
705 | ret = -ENOSPC; | ||
706 | goto error; | 716 | goto error; |
707 | } | 717 | } |
718 | |||
719 | /* Parse fetch argument */ | ||
708 | ret = parse_probe_arg(arg, &tp->args[i].fetch, is_return); | 720 | ret = parse_probe_arg(arg, &tp->args[i].fetch, is_return); |
709 | if (ret) { | 721 | if (ret) { |
710 | pr_info("Parse error at argument%d. (%d)\n", i, ret); | 722 | pr_info("Parse error at argument%d. (%d)\n", i, ret); |