All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: fix potential memory leak
@ 2019-11-20 18:09 Ian Rogers
  2019-11-21 14:47 ` Arnaldo Carvalho de Melo
  2019-11-23  8:14 ` [tip: perf/core] perf parse: Fix potential memory leak when handling tracepoint errors tip-bot2 for Ian Rogers
  0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2019-11-20 18:09 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Andi Kleen, Jin Yao, linux-kernel, clang-built-linux
  Cc: Stephane Eranian, Ian Rogers

An error may be in place when tracepoint_error is called, use
parse_events__handle_error to avoid a memory leak and to capture the
first and last error. Error detected by LLVM's libFuzzer using the
following event:

$ perf stat -e 'msr/event/,f:e'
event syntax error: 'msr/event/,f:e'
                     \___ can't access trace events

Error:  No permissions to read /sys/kernel/debug/tracing/events/f/e
Hint:   Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing/'

Initial error:
event syntax error: 'msr/event/,f:e'
                                \___ no value assigned for term
Run 'perf list' for a list of valid events

 Usage: perf stat [<options>] [<command>]

    -e, --event <event>   event selector. use 'perf list' to list available events

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/parse-events.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6bae9d6edc12..ecef5b8037b4 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -511,6 +511,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
 static void tracepoint_error(struct parse_events_error *e, int err,
 			     const char *sys, const char *name)
 {
+	const char *str;
 	char help[BUFSIZ];
 
 	if (!e)
@@ -524,18 +525,18 @@ static void tracepoint_error(struct parse_events_error *e, int err,
 
 	switch (err) {
 	case EACCES:
-		e->str = strdup("can't access trace events");
+		str = "can't access trace events";
 		break;
 	case ENOENT:
-		e->str = strdup("unknown tracepoint");
+		str = "unknown tracepoint";
 		break;
 	default:
-		e->str = strdup("failed to add tracepoint");
+		str = "failed to add tracepoint";
 		break;
 	}
 
 	tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
-	e->help = strdup(help);
+	parse_events__handle_error(e, 0, strdup(str), strdup(help));
 }
 
 static int add_tracepoint(struct list_head *list, int *idx,
-- 
2.24.0.432.g9d3f5f5b63-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf tools: fix potential memory leak
  2019-11-20 18:09 [PATCH] perf tools: fix potential memory leak Ian Rogers
@ 2019-11-21 14:47 ` Arnaldo Carvalho de Melo
  2019-11-23  8:14 ` [tip: perf/core] perf parse: Fix potential memory leak when handling tracepoint errors tip-bot2 for Ian Rogers
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-11-21 14:47 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Andi Kleen, Jin Yao, linux-kernel,
	clang-built-linux, Stephane Eranian

Em Wed, Nov 20, 2019 at 10:09:25AM -0800, Ian Rogers escreveu:
> An error may be in place when tracepoint_error is called, use
> parse_events__handle_error to avoid a memory leak and to capture the
> first and last error. Error detected by LLVM's libFuzzer using the
> following event:
> 
> $ perf stat -e 'msr/event/,f:e'
> event syntax error: 'msr/event/,f:e'
>                      \___ can't access trace events
> 
> Error:  No permissions to read /sys/kernel/debug/tracing/events/f/e
> Hint:   Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing/'
> 
> Initial error:
> event syntax error: 'msr/event/,f:e'
>                                 \___ no value assigned for term
> Run 'perf list' for a list of valid events
> 
>  Usage: perf stat [<options>] [<command>]
> 
>     -e, --event <event>   event selector. use 'perf list' to list available events

Thanks, applied.

- Arnaldo
 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/parse-events.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 6bae9d6edc12..ecef5b8037b4 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -511,6 +511,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
>  static void tracepoint_error(struct parse_events_error *e, int err,
>  			     const char *sys, const char *name)
>  {
> +	const char *str;
>  	char help[BUFSIZ];
>  
>  	if (!e)
> @@ -524,18 +525,18 @@ static void tracepoint_error(struct parse_events_error *e, int err,
>  
>  	switch (err) {
>  	case EACCES:
> -		e->str = strdup("can't access trace events");
> +		str = "can't access trace events";
>  		break;
>  	case ENOENT:
> -		e->str = strdup("unknown tracepoint");
> +		str = "unknown tracepoint";
>  		break;
>  	default:
> -		e->str = strdup("failed to add tracepoint");
> +		str = "failed to add tracepoint";
>  		break;
>  	}
>  
>  	tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
> -	e->help = strdup(help);
> +	parse_events__handle_error(e, 0, strdup(str), strdup(help));
>  }
>  
>  static int add_tracepoint(struct list_head *list, int *idx,
> -- 
> 2.24.0.432.g9d3f5f5b63-goog

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: perf/core] perf parse: Fix potential memory leak when handling tracepoint errors
  2019-11-20 18:09 [PATCH] perf tools: fix potential memory leak Ian Rogers
  2019-11-21 14:47 ` Arnaldo Carvalho de Melo
@ 2019-11-23  8:14 ` tip-bot2 for Ian Rogers
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Ian Rogers @ 2019-11-23  8:14 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Ian Rogers, Alexander Shishkin, Andi Kleen, Jin Yao, Jiri Olsa,
	Mark Rutland, Namhyung Kim, Peter Zijlstra, Stephane Eranian,
	clang-built-linux, Arnaldo Carvalho de Melo, x86, LKML

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     4584f084aa9d8033d5911935837dbee7b082d0e9
Gitweb:        https://git.kernel.org/tip/4584f084aa9d8033d5911935837dbee7b082d0e9
Author:        Ian Rogers <irogers@google.com>
AuthorDate:    Wed, 20 Nov 2019 10:09:25 -08:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Fri, 22 Nov 2019 10:48:14 -03:00

perf parse: Fix potential memory leak when handling tracepoint errors

An error may be in place when tracepoint_error is called, use
parse_events__handle_error to avoid a memory leak and to capture the
first and last error. Error detected by LLVM's libFuzzer using the
following event:

$ perf stat -e 'msr/event/,f:e'
event syntax error: 'msr/event/,f:e'
                     \___ can't access trace events

Error:  No permissions to read /sys/kernel/debug/tracing/events/f/e
Hint:   Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing/'

Initial error:
event syntax error: 'msr/event/,f:e'
                                \___ no value assigned for term
Run 'perf list' for a list of valid events

 Usage: perf stat [<options>] [<command>]

    -e, --event <event>   event selector. use 'perf list' to list available events

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: clang-built-linux@googlegroups.com
Link: http://lore.kernel.org/lkml/20191120180925.21787-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/parse-events.c |  9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6c313c4..ed7c008 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -511,6 +511,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
 static void tracepoint_error(struct parse_events_error *e, int err,
 			     const char *sys, const char *name)
 {
+	const char *str;
 	char help[BUFSIZ];
 
 	if (!e)
@@ -524,18 +525,18 @@ static void tracepoint_error(struct parse_events_error *e, int err,
 
 	switch (err) {
 	case EACCES:
-		e->str = strdup("can't access trace events");
+		str = "can't access trace events";
 		break;
 	case ENOENT:
-		e->str = strdup("unknown tracepoint");
+		str = "unknown tracepoint";
 		break;
 	default:
-		e->str = strdup("failed to add tracepoint");
+		str = "failed to add tracepoint";
 		break;
 	}
 
 	tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
-	e->help = strdup(help);
+	parse_events__handle_error(e, 0, strdup(str), strdup(help));
 }
 
 static int add_tracepoint(struct list_head *list, int *idx,

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-23  8:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 18:09 [PATCH] perf tools: fix potential memory leak Ian Rogers
2019-11-21 14:47 ` Arnaldo Carvalho de Melo
2019-11-23  8:14 ` [tip: perf/core] perf parse: Fix potential memory leak when handling tracepoint errors tip-bot2 for Ian Rogers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.