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: <de636159-a33e-cfa9-0d8f-e9c81873588f@iogearbox.net>
Date:   Thu, 11 Jun 2020 16:12:51 +0200
From:   Daniel Borkmann <daniel@...earbox.net>
To:     Gaurav Singh <gaurav1086@...il.com>,
        Alexei Starovoitov <ast@...nel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Jesper Dangaard Brouer <hawk@...nel.org>,
        John Fastabend <john.fastabend@...il.com>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        Andrii Nakryiko <andriin@...com>,
        KP Singh <kpsingh@...omium.org>,
        "open list:XDP (eXpress Data Path)" <netdev@...r.kernel.org>,
        "open list:XDP (eXpress Data Path)" <bpf@...r.kernel.org>,
        open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] xdp_rxq_info_user: Add null check after malloc

On 6/10/20 5:01 AM, Gaurav Singh wrote:
> Signed-off-by: Gaurav Singh <gaurav1086@...il.com>
> 
> The memset call is made right after malloc call which
> can return a NULL pointer upon failure causing a
> segmentation fault. Fix this by adding a null check
> right after malloc() and then do memset().

The SoB should come after the commit message here.

> ---
>   samples/bpf/xdp_rxq_info_user.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c
> index 4fe47502ebed..2d03c84a4cca 100644
> --- a/samples/bpf/xdp_rxq_info_user.c
> +++ b/samples/bpf/xdp_rxq_info_user.c
> @@ -202,11 +202,11 @@ static struct datarec *alloc_record_per_cpu(void)
>   
>   	size = sizeof(struct datarec) * nr_cpus;
>   	array = malloc(size);
> -	memset(array, 0, size);

All these below are candidates for calloc(), can we just use that instead and
simplify the below.

>   	if (!array) {
>   		fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
>   		exit(EXIT_FAIL_MEM);
>   	}
> +	memset(array, 0, size);
>   	return array;
>   }
>   
> @@ -218,11 +218,11 @@ static struct record *alloc_record_per_rxq(void)
>   
>   	size = sizeof(struct record) * nr_rxqs;
>   	array = malloc(size);
> -	memset(array, 0, size);
>   	if (!array) {
>   		fprintf(stderr, "Mem alloc error (nr_rxqs:%u)\n", nr_rxqs);
>   		exit(EXIT_FAIL_MEM);
>   	}
> +	memset(array, 0, size);
>   	return array;
>   }
>   
> @@ -233,11 +233,11 @@ static struct stats_record *alloc_stats_record(void)
>   	int i;
>   
>   	rec = malloc(sizeof(*rec));
> -	memset(rec, 0, sizeof(*rec));
>   	if (!rec) {
>   		fprintf(stderr, "Mem alloc error\n");
>   		exit(EXIT_FAIL_MEM);
>   	}
> +	memset(rec, 0, sizeof(*rec));
>   	rec->rxq = alloc_record_per_rxq();
>   	for (i = 0; i < nr_rxqs; i++)
>   		rec->rxq[i].cpu = alloc_record_per_cpu();
> 

Thanks,
Daniel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ