lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YPCbV92iVme1WdFs@kernel.org>
Date:   Thu, 15 Jul 2021 17:32:23 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Riccardo Mancini <rickyman7@...il.com>
Cc:     Ian Rogers <irogers@...gle.com>,
        Namhyung Kim <namhyung@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Mark Rutland <mark.rutland@....com>,
        Jiri Olsa <jolsa@...hat.com>, linux-kernel@...r.kernel.org,
        linux-perf-users@...r.kernel.org
Subject: Re: [PATCH 15/20] perf trace: free malloc'd trace fields on exit

Em Thu, Jul 15, 2021 at 06:07:20PM +0200, Riccardo Mancini escreveu:
> ASan reports several memory leaks running the perf test
> "88: Check open filename arg using perf trace + vfs_getname".
> The first of these leaks is related to struct trace fields never being
> deallocated.
> 
> This patch adds the function trace__exit, which is called at the end of
> cmd_trace, replacing the existing deallocation, which is now moved
> inside the new function.
> This function deallocates:
>  - ev_qualifier
>  - ev_qualifier_ids.entries
>  - syscalls.table
>  - sctbl
>  - perfconfig_events
> 
> In order to prevent errors in case any of this field is never
> initialized, this patch also adds initialization to NULL to these
> fields.
> 
> Signed-off-by: Riccardo Mancini <rickyman7@...il.com>
> ---
>  tools/perf/builtin-trace.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index 7ec18ff57fc4ae35..fe26d87ca8ccc14d 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -4701,6 +4701,15 @@ static int trace__config(const char *var, const char *value, void *arg)
>  	return err;
>  }
>  
> +static void trace__exit(struct trace *trace)
> +{
> +	strlist__delete(trace->ev_qualifier);
> +	free(trace->ev_qualifier_ids.entries);
> +	free(trace->syscalls.table);
> +	syscalltbl__delete(trace->sctbl);
> +	zfree(&trace->perfconfig_events);
> +}
> +
>  int cmd_trace(int argc, const char **argv)
>  {
>  	const char *trace_usage[] = {
> @@ -4731,6 +4740,12 @@ int cmd_trace(int argc, const char **argv)
>  		.kernel_syscallchains = false,
>  		.max_stack = UINT_MAX,
>  		.max_events = ULONG_MAX,
> +		.ev_qualifier = NULL,
> +		.sctbl = NULL,
> +		.ev_qualifier_ids = {
> +			.entries = NULL,
> +			.nr = 0,
> +		},
>  	};
>  	const char *map_dump_str = NULL;
>  	const char *output_name = NULL;

The above hunk is not needed, as all non explicitely initialized members
will be zeroed, so to reduce patch size I'm dropping it.

Thanks, applied.

- Arnaldo


> @@ -5135,6 +5150,6 @@ int cmd_trace(int argc, const char **argv)
>  	if (output_name != NULL)
>  		fclose(trace.output);
>  out:
> -	zfree(&trace.perfconfig_events);
> +	trace__exit(&trace);
>  	return err;
>  }
> -- 
> 2.31.1
> 

-- 

- Arnaldo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ