Commit ba8665d7dd95eb6093ee06f8f624b6acb1e73206

Authored by Masami Hiramatsu
Committed by Ingo Molnar
1 parent 5cbd080561

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>

Showing 1 changed file with 19 additions and 7 deletions Side-by-side Diff

kernel/trace/trace_kprobe.c
... ... @@ -483,7 +483,8 @@
483 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 489 int ret = 0;
489 490 unsigned long param;
... ... @@ -543,7 +544,7 @@
543 544 if (!id)
544 545 return -ENOMEM;
545 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 548 if (ret)
548 549 kfree(id);
549 550 else {
... ... @@ -560,6 +561,16 @@
560 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 574 /* Return 1 if name is reserved or already used by another argument */
564 575 static int conflict_field_name(const char *name,
565 576 struct probe_arg *args, int narg)
566 577  
... ... @@ -698,13 +709,14 @@
698 709 }
699 710  
700 711 tp->args[i].name = kstrdup(argv[i], GFP_KERNEL);
701   -
702   - /* Parse fetch argument */
703   - if (strlen(arg) > MAX_ARGSTR_LEN) {
704   - pr_info("Argument%d(%s) is too long.\n", i, arg);
705   - ret = -ENOSPC;
  712 + if (!tp->args[i].name) {
  713 + pr_info("Failed to allocate argument%d name '%s'.\n",
  714 + i, argv[i]);
  715 + ret = -ENOMEM;
706 716 goto error;
707 717 }
  718 +
  719 + /* Parse fetch argument */
708 720 ret = parse_probe_arg(arg, &tp->args[i].fetch, is_return);
709 721 if (ret) {
710 722 pr_info("Parse error at argument%d. (%d)\n", i, ret);