bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* (no subject)
@ 2020-06-09 11:38 Gaurav Singh
  2020-06-09 11:38 ` [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Gaurav Singh
  2020-06-09 11:54 ` your mail Greg KH
  0 siblings, 2 replies; 7+ messages in thread
From: Gaurav Singh @ 2020-06-09 11:38 UTC (permalink / raw)
  To: gaurav1086, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, David S. Miller, Jakub Kicinski,
	Jesper Dangaard Brouer,
	open list:BPF (Safe dynamic programs and tools),
	open list:BPF (Safe dynamic programs and tools),
	open list

Please find the patch below.

Thanks and regards,
Gaurav.

From Gaurav Singh <gaurav1086@gmail.com> # This line is ignored.
From: Gaurav Singh <gaurav1086@gmail.com>
Reply-To: 
Subject: 
In-Reply-To: 



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

* [PATCH] bpf: alloc_record_per_cpu Add null check after malloc
  2020-06-09 11:38 Gaurav Singh
@ 2020-06-09 11:38 ` Gaurav Singh
  2020-06-09 11:55   ` Greg KH
  2020-06-09 11:54 ` your mail Greg KH
  1 sibling, 1 reply; 7+ messages in thread
From: Gaurav Singh @ 2020-06-09 11:38 UTC (permalink / raw)
  To: gaurav1086, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, David S. Miller, Jakub Kicinski,
	Jesper Dangaard Brouer,
	open list:BPF (Safe dynamic programs and tools),
	open list:BPF (Safe dynamic programs and tools),
	open list

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 samples/bpf/xdp_rxq_info_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c
index 4fe47502ebed..490b07b7df78 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);
 	if (!array) {
 		fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
 		exit(EXIT_FAIL_MEM);
 	}
+	memset(array, 0, size);
 	return array;
 }
 
-- 
2.17.1


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

* Re: your mail
  2020-06-09 11:38 Gaurav Singh
  2020-06-09 11:38 ` [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Gaurav Singh
@ 2020-06-09 11:54 ` Greg KH
  1 sibling, 0 replies; 7+ messages in thread
From: Greg KH @ 2020-06-09 11:54 UTC (permalink / raw)
  To: Gaurav Singh
  Cc: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, John Fastabend, KP Singh,
	David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
	open list:BPF (Safe dynamic programs and tools),
	open list:BPF (Safe dynamic programs and tools),
	open list

On Tue, Jun 09, 2020 at 07:38:38AM -0400, Gaurav Singh wrote:
> Please find the patch below.
> 
> Thanks and regards,
> Gaurav.
> 
> >From Gaurav Singh <gaurav1086@gmail.com> # This line is ignored.
> From: Gaurav Singh <gaurav1086@gmail.com>
> Reply-To: 
> Subject: 
> In-Reply-To: 
> 
> 

I think something went wrong in your submission, just use 'git
send-email' to send the patch out.

thanks,

greg k-h

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

* Re: [PATCH] bpf: alloc_record_per_cpu Add null check after malloc
  2020-06-09 11:38 ` [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Gaurav Singh
@ 2020-06-09 11:55   ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2020-06-09 11:55 UTC (permalink / raw)
  To: Gaurav Singh
  Cc: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, John Fastabend, KP Singh,
	David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
	open list:BPF (Safe dynamic programs and tools),
	open list:BPF (Safe dynamic programs and tools),
	open list

On Tue, Jun 09, 2020 at 07:38:39AM -0400, Gaurav Singh wrote:
> Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
> ---
>  samples/bpf/xdp_rxq_info_user.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

I know I don't take patches without any changelog text, maybe other
maintainers are more lax...

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

* Re: [PATCH] bpf: alloc_record_per_cpu Add null check after malloc
  2020-06-09 12:08 [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Gaurav Singh
@ 2020-06-09 12:23 ` Jesper Dangaard Brouer
  0 siblings, 0 replies; 7+ messages in thread
From: Jesper Dangaard Brouer @ 2020-06-09 12:23 UTC (permalink / raw)
  To: Gaurav Singh
  Cc: Alexei Starovoitov, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	KP Singh, open list:XDP (eXpress Data Path),
	open list:XDP (eXpress Data Path),
	open list

On Tue,  9 Jun 2020 08:08:03 -0400
Gaurav Singh <gaurav1086@gmail.com> wrote:

> The memset call is made right after malloc call. To fix this, add the null check right after malloc and then do memset.
> 

Did you read the section about how long lines should be in desc?


> Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
> ---
>  samples/bpf/xdp_rxq_info_user.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c
> index 4fe47502ebed..490b07b7df78 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);
>  	if (!array) {
>  		fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
>  		exit(EXIT_FAIL_MEM);
>  	}
> +	memset(array, 0, size);
>  	return array;
>  }

Looking at code, this bug happen in more places. Please fix up all locations.

I think this fix should go through the "bpf" tree.
Please read:
 https://github.com/torvalds/linux/blob/master/Documentation/bpf/bpf_devel_QA.rst

-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer


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

* [PATCH] bpf: alloc_record_per_cpu Add null check after malloc
@ 2020-06-09 12:08 Gaurav Singh
  2020-06-09 12:23 ` Jesper Dangaard Brouer
  0 siblings, 1 reply; 7+ messages in thread
From: Gaurav Singh @ 2020-06-09 12:08 UTC (permalink / raw)
  To: gaurav1086, Alexei Starovoitov, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	KP Singh, open list:XDP (eXpress Data Path),
	open list:XDP (eXpress Data Path),
	open list

The memset call is made right after malloc call. To fix this, add the null check right after malloc and then do memset.

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 samples/bpf/xdp_rxq_info_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c
index 4fe47502ebed..490b07b7df78 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);
 	if (!array) {
 		fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
 		exit(EXIT_FAIL_MEM);
 	}
+	memset(array, 0, size);
 	return array;
 }
 
-- 
2.17.1


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

* Re: [PATCH] bpf: alloc_record_per_cpu Add null check after malloc
       [not found] <CAFAFadDVe1Au2eJ8ho_cK1riwf9FDaGck3o+VEcKpqRgO5qXdA@mail.gmail.com>
@ 2020-06-09  6:50 ` Jesper Dangaard Brouer
  0 siblings, 0 replies; 7+ messages in thread
From: Jesper Dangaard Brouer @ 2020-06-09  6:50 UTC (permalink / raw)
  To: gaurav singh
  Cc: brouer, ast, daniel, davem, kuba, hawk, john.fastabend, kafai,
	songliubraving, yhs, andriin, kpsingh, netdev, bpf, linux-kernel

On Sat, 6 Jun 2020 19:59:48 -0400
gaurav singh <gaurav1086@gmail.com> wrote:

> Hi,
> 
> The memset call is made right after malloc call. To fix this, add the null
> check right after malloc and then do memset.
> 
> Please find the patch below.

The fix in your patch seem correct (although there are more places),
but the way you send/submit the patch is wrong.  The patch itself also
mangle whitespaces.

You can read the guide:

 https://www.kernel.org/doc/html/latest/process/submitting-patches.html
 https://www.kernel.org/doc/html/latest/process/index.html

--Jesper


> Thanks and regards,
> Gaurav.
> 
> 
> From 552b7df0e12572737929c60478b5dca2a40f4ad9 Mon Sep 17 00:00:00 2001
> From: Gaurav Singh <gaurav1086@gmail.com>
> Date: Sat, 6 Jun 2020 19:57:48 -0400
> Subject: [PATCH] bpf: alloc_record_per_cpu Add null check after malloc
> 
> Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
> ---
>  samples/bpf/xdp_rxq_info_user.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/samples/bpf/xdp_rxq_info_user.c
> b/samples/bpf/xdp_rxq_info_user.c
> index 4fe47502ebed..490b07b7df78 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);
>   if (!array) {
>   fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
>   exit(EXIT_FAIL_MEM);
>   }
> + memset(array, 0, size);
>   return array;
>  }
> 



-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer


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

end of thread, other threads:[~2020-06-09 12:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09 11:38 Gaurav Singh
2020-06-09 11:38 ` [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Gaurav Singh
2020-06-09 11:55   ` Greg KH
2020-06-09 11:54 ` your mail Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2020-06-09 12:08 [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Gaurav Singh
2020-06-09 12:23 ` Jesper Dangaard Brouer
     [not found] <CAFAFadDVe1Au2eJ8ho_cK1riwf9FDaGck3o+VEcKpqRgO5qXdA@mail.gmail.com>
2020-06-09  6:50 ` Jesper Dangaard Brouer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).