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] [day] [month] [year] [list]
Date:   Fri, 12 Apr 2019 16:14:00 +0000
From:   Song Liu <songliubraving@...com>
To:     Arnaldo Carvalho de Melo <acme@...nel.org>
CC:     Ingo Molnar <mingo@...nel.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        "Jiri Olsa" <jolsa@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
        Clark Williams <williams@...hat.com>,
        LKML <linux-kernel@...r.kernel.org>,
        "linux-perf-users@...r.kernel.org" <linux-perf-users@...r.kernel.org>,
        "Gustavo A. R. Silva" <gustavo@...eddedor.com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...hat.com>,
        "Peter Zijlstra" <peterz@...radead.org>,
        Arnaldo Carvalho de Melo <acme@...hat.com>
Subject: Re: [PATCH 3/7] perf header: Fix lock/unlock imbalances when
 processing BPF/BTF info



> On Apr 12, 2019, at 7:22 AM, Arnaldo Carvalho de Melo <acme@...nel.org> wrote:
> 
> From: "Gustavo A. R. Silva" <gustavo@...eddedor.com>
> 
> Fix lock/unlock imbalances by refactoring the code a bit and adding
> calls to up_write() before return.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@...eddedor.com>
> Acked-by: Song Liu <songliubraving@...com>
> Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
> Cc: Jiri Olsa <jolsa@...hat.com>
> Cc: Namhyung Kim <namhyung@...nel.org>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Addresses-Coverity-ID: 1444315 ("Missing unlock")
> Addresses-Coverity-ID: 1444316 ("Missing unlock")
> Fixes: a70a1123174a ("perf bpf: Save BTF information as headers to perf.data")
> Fixes: 606f972b1361 ("perf bpf: Save bpf_prog_info information as headers to perf.data")
> Link: http://lkml.kernel.org/r/20190408173355.GA10501@embeddedor
> [ Simplified the exit path to have just one up_write() + return ]
> Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>

Acked-by: Song Liu <songliubraving@...com>


> ---
> tools/perf/util/header.c | 22 +++++++++++++---------
> 1 file changed, 13 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index b9e693825873..2d2af2ac2b1e 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -2606,6 +2606,7 @@ static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused)
> 		perf_env__insert_bpf_prog_info(env, info_node);
> 	}
> 
> +	up_write(&env->bpf_progs.lock);
> 	return 0;
> out:
> 	free(info_linear);
> @@ -2623,7 +2624,9 @@ static int process_bpf_prog_info(struct feat_fd *ff __maybe_unused, void *data _
> static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
> {
> 	struct perf_env *env = &ff->ph->env;
> +	struct btf_node *node = NULL;
> 	u32 count, i;
> +	int err = -1;
> 
> 	if (ff->ph->needs_swap) {
> 		pr_warning("interpreting btf from systems with endianity is not yet supported\n");
> @@ -2636,31 +2639,32 @@ static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)
> 	down_write(&env->bpf_progs.lock);
> 
> 	for (i = 0; i < count; ++i) {
> -		struct btf_node *node;
> 		u32 id, data_size;
> 
> 		if (do_read_u32(ff, &id))
> -			return -1;
> +			goto out;
> 		if (do_read_u32(ff, &data_size))
> -			return -1;
> +			goto out;
> 
> 		node = malloc(sizeof(struct btf_node) + data_size);
> 		if (!node)
> -			return -1;
> +			goto out;
> 
> 		node->id = id;
> 		node->data_size = data_size;
> 
> -		if (__do_read(ff, node->data, data_size)) {
> -			free(node);
> -			return -1;
> -		}
> +		if (__do_read(ff, node->data, data_size))
> +			goto out;
> 
> 		perf_env__insert_btf(env, node);
> +		node = NULL;
> 	}
> 
> +	err = 0;
> +out:
> 	up_write(&env->bpf_progs.lock);
> -	return 0;
> +	free(node);
> +	return err;
> }
> 
> struct feature_ops {
> -- 
> 2.20.1
> 

Powered by blists - more mailing lists