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]
Message-ID: <3d7c321e-6099-a7f4-bffe-06d4bf48536d@fb.com>
Date:   Sun, 31 Oct 2021 21:13:47 -0700
From:   Yonghong Song <yhs@...com>
To:     Yang Yingliang <yangyingliang@...wei.com>,
        <linux-kernel@...r.kernel.org>, <bpf@...r.kernel.org>
CC:     <linux-kselftest@...r.kernel.org>, <shuah@...nel.org>,
        <ast@...nel.org>
Subject: Re: [PATCH -next] bpf/benchs: Fix return value check of
 bpf_program__attach()



On 10/30/21 2:30 AM, Yang Yingliang wrote:
> If bpf_program__attach() fails, it never returns NULL,
> we should use libbpf_get_error() to check the return value.
> 
> Reported-by: Hulk Robot <hulkci@...wei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@...wei.com>

Thanks for the fix. LGTM with a nit below.

Acked-by: Yonghong Song <yhs@...com>

> ---
>   .../bpf/benchs/bench_bloom_filter_map.c       | 20 ++++++++++++++-----
>   1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> index 6eeeed2913e6..6879340b20c4 100644
> --- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> +++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> @@ -296,6 +296,7 @@ static struct bloom_filter_bench *setup_skeleton(void)
>   static void bloom_lookup_setup(void)
>   {
>   	struct bpf_link *link;
> +	int err;
>   
>   	ctx.use_array_map = true;
>   
> @@ -304,7 +305,8 @@ static void bloom_lookup_setup(void)
>   	populate_maps();
>   
>   	link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
> -	if (!link) {
> +	err = libbpf_get_error(link);
> +	if (err) {

There is no need to define 'int err', you can just do
	if (libbpf_get_error(link))

The same for a few 'int err' below.

>   		fprintf(stderr, "failed to attach program!\n");
>   		exit(1);
>   	}
> @@ -313,6 +315,7 @@ static void bloom_lookup_setup(void)
>   static void bloom_update_setup(void)
>   {
>   	struct bpf_link *link;
> +	int err;
>   
>   	ctx.use_array_map = true;
>   
> @@ -321,7 +324,8 @@ static void bloom_update_setup(void)
>   	populate_maps();
>   
>   	link = bpf_program__attach(ctx.skel->progs.bloom_update);
> -	if (!link) {
> +	err = libbpf_get_error(link);
> +	if (err) {
>   		fprintf(stderr, "failed to attach program!\n");
>   		exit(1);
>   	}
> @@ -330,6 +334,7 @@ static void bloom_update_setup(void)
>   static void false_positive_setup(void)
>   {
>   	struct bpf_link *link;
> +	int err;
>   
>   	ctx.use_hashmap = true;
>   	ctx.hashmap_use_bloom = true;
> @@ -340,7 +345,8 @@ static void false_positive_setup(void)
>   	populate_maps();
>   
>   	link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> -	if (!link) {
> +	err = libbpf_get_error(link);
> +	if (err) {
>   		fprintf(stderr, "failed to attach program!\n");
>   		exit(1);
>   	}
> @@ -349,6 +355,7 @@ static void false_positive_setup(void)
>   static void hashmap_with_bloom_setup(void)
>   {
>   	struct bpf_link *link;
> +	int err;
>   
>   	ctx.use_hashmap = true;
>   	ctx.hashmap_use_bloom = true;
> @@ -358,7 +365,8 @@ static void hashmap_with_bloom_setup(void)
>   	populate_maps();
>   
>   	link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> -	if (!link) {
> +	err = libbpf_get_error(link);
> +	if (err) {
>   		fprintf(stderr, "failed to attach program!\n");
>   		exit(1);
>   	}
> @@ -367,6 +375,7 @@ static void hashmap_with_bloom_setup(void)
>   static void hashmap_no_bloom_setup(void)
>   {
>   	struct bpf_link *link;
> +	int err;
>   
>   	ctx.use_hashmap = true;
>   
> @@ -375,7 +384,8 @@ static void hashmap_no_bloom_setup(void)
>   	populate_maps();
>   
>   	link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> -	if (!link) {
> +	err = libbpf_get_error(link);
> +	if (err) {
>   		fprintf(stderr, "failed to attach program!\n");
>   		exit(1);
>   	}
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ