[net-next] bpf: dev_map_alloc() shouldn't return NULL
diff mbox

Message ID 20170722074004.3abeucov67n3sbqs@mwanda
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Dan Carpenter July 22, 2017, 7:40 a.m. UTC
We forgot to set the error code on two error paths which means that we
return ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is
not expecting that and will have a NULL dereference.

Fixes: 546ac1ffb70d ("bpf: add devmap, a map for storing net device references")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

Daniel Borkmann July 22, 2017, 10:09 a.m. UTC | #1
On 07/22/2017 09:40 AM, Dan Carpenter wrote:
> We forgot to set the error code on two error paths which means that we
> return ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is
> not expecting that and will have a NULL dereference.
>
> Fixes: 546ac1ffb70d ("bpf: add devmap, a map for storing net device references")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks!

Acked-by: Daniel Borkmann <daniel@iogearbox.net>
John Fastabend July 22, 2017, 7:07 p.m. UTC | #2
On 07/22/2017 12:40 AM, Dan Carpenter wrote:
> We forgot to set the error code on two error paths which means that we
> return ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is
> not expecting that and will have a NULL dereference.
> 
> Fixes: 546ac1ffb70d ("bpf: add devmap, a map for storing net device references")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> index 899364d097f5..d439ee0eadb1 100644
> --- a/kernel/bpf/devmap.c
> +++ b/kernel/bpf/devmap.c
> @@ -114,6 +114,7 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
>  	if (err)
>  		goto free_dtab;
>  
> +	err = -ENOMEM;
>  	/* A per cpu bitfield with a bit per possible net device */
>  	dtab->flush_needed = __alloc_percpu(
>  				BITS_TO_LONGS(attr->max_entries) *
> 

Thanks.

Acked-by: John Fastabend <john.fastabend@gmail.com>
David Miller July 24, 2017, 11:23 p.m. UTC | #3
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Sat, 22 Jul 2017 10:40:04 +0300

> We forgot to set the error code on two error paths which means that we
> return ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is
> not expecting that and will have a NULL dereference.
> 
> Fixes: 546ac1ffb70d ("bpf: add devmap, a map for storing net device references")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied, thanks Dan.

Patch
diff mbox

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 899364d097f5..d439ee0eadb1 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -114,6 +114,7 @@  static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
 	if (err)
 		goto free_dtab;
 
+	err = -ENOMEM;
 	/* A per cpu bitfield with a bit per possible net device */
 	dtab->flush_needed = __alloc_percpu(
 				BITS_TO_LONGS(attr->max_entries) *