mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] perf probe: Free string returned by synthesize_perf_probe_point() on failure in synthesize_perf_probe_command()
@ 2023-08-04 16:26 Arnaldo Carvalho de Melo
  2023-08-10 21:57 ` Ian Rogers
  2023-08-11  2:15 ` Masami Hiramatsu
  0 siblings, 2 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-08-04 16:26 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Adrian Hunter, Ian Rogers, Jiri Olsa, Namhyung Kim,
	Linux Kernel Mailing List

Building perf with EXTRA_CFLAGS="-fsanitize=address" a leak was detected
elsewhere and lead to an audit, where we found that
synthesize_perf_probe_command() may leak synthesize_perf_probe_point()
return on failure, fix it.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/lkml/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-event.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index c7bfeab610a3679a..2835d87cb97771f9 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2063,14 +2063,18 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
 			goto out;
 
 	tmp = synthesize_perf_probe_point(&pev->point);
-	if (!tmp || strbuf_addstr(&buf, tmp) < 0)
+	if (!tmp || strbuf_addstr(&buf, tmp) < 0) {
+		free(tmp);
 		goto out;
+	}
 	free(tmp);
 
 	for (i = 0; i < pev->nargs; i++) {
 		tmp = synthesize_perf_probe_arg(pev->args + i);
-		if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0)
+		if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) {
+			free(tmp);
 			goto out;
+		}
 		free(tmp);
 	}
 
-- 
2.37.1


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

* Re: [PATCH 1/1] perf probe: Free string returned by synthesize_perf_probe_point() on failure in synthesize_perf_probe_command()
  2023-08-04 16:26 [PATCH 1/1] perf probe: Free string returned by synthesize_perf_probe_point() on failure in synthesize_perf_probe_command() Arnaldo Carvalho de Melo
@ 2023-08-10 21:57 ` Ian Rogers
  2023-08-11  2:15 ` Masami Hiramatsu
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2023-08-10 21:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Masami Hiramatsu, Adrian Hunter, Jiri Olsa, Namhyung Kim,
	Linux Kernel Mailing List

On Fri, Aug 4, 2023 at 9:27 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>
> Building perf with EXTRA_CFLAGS="-fsanitize=address" a leak was detected
> elsewhere and lead to an audit, where we found that
> synthesize_perf_probe_command() may leak synthesize_perf_probe_point()
> return on failure, fix it.
>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Link: https://lore.kernel.org/lkml/
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/probe-event.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index c7bfeab610a3679a..2835d87cb97771f9 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -2063,14 +2063,18 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
>                         goto out;
>
>         tmp = synthesize_perf_probe_point(&pev->point);
> -       if (!tmp || strbuf_addstr(&buf, tmp) < 0)
> +       if (!tmp || strbuf_addstr(&buf, tmp) < 0) {
> +               free(tmp);
>                 goto out;
> +       }
>         free(tmp);
>
>         for (i = 0; i < pev->nargs; i++) {
>                 tmp = synthesize_perf_probe_arg(pev->args + i);
> -               if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0)
> +               if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) {
> +                       free(tmp);
>                         goto out;
> +               }
>                 free(tmp);
>         }
>
> --
> 2.37.1
>

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

* Re: [PATCH 1/1] perf probe: Free string returned by synthesize_perf_probe_point() on failure in synthesize_perf_probe_command()
  2023-08-04 16:26 [PATCH 1/1] perf probe: Free string returned by synthesize_perf_probe_point() on failure in synthesize_perf_probe_command() Arnaldo Carvalho de Melo
  2023-08-10 21:57 ` Ian Rogers
@ 2023-08-11  2:15 ` Masami Hiramatsu
  1 sibling, 0 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2023-08-11  2:15 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Adrian Hunter, Ian Rogers, Jiri Olsa, Namhyung Kim,
	Linux Kernel Mailing List

On Fri, 4 Aug 2023 13:26:54 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

> Building perf with EXTRA_CFLAGS="-fsanitize=address" a leak was detected
> elsewhere and lead to an audit, where we found that
> synthesize_perf_probe_command() may leak synthesize_perf_probe_point()
> return on failure, fix it.

This looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> 
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Link: https://lore.kernel.org/lkml/
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/util/probe-event.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index c7bfeab610a3679a..2835d87cb97771f9 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -2063,14 +2063,18 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
>  			goto out;
>  
>  	tmp = synthesize_perf_probe_point(&pev->point);
> -	if (!tmp || strbuf_addstr(&buf, tmp) < 0)
> +	if (!tmp || strbuf_addstr(&buf, tmp) < 0) {
> +		free(tmp);
>  		goto out;
> +	}
>  	free(tmp);
>  
>  	for (i = 0; i < pev->nargs; i++) {
>  		tmp = synthesize_perf_probe_arg(pev->args + i);
> -		if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0)
> +		if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) {
> +			free(tmp);
>  			goto out;
> +		}
>  		free(tmp);
>  	}
>  
> -- 
> 2.37.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

end of thread, other threads:[~2023-08-11  2:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04 16:26 [PATCH 1/1] perf probe: Free string returned by synthesize_perf_probe_point() on failure in synthesize_perf_probe_command() Arnaldo Carvalho de Melo
2023-08-10 21:57 ` Ian Rogers
2023-08-11  2:15 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®