netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] bpf: fix oops on allocation failure
@ 2017-08-25 20:27 Dan Carpenter
  2017-08-25 20:47 ` Daniel Borkmann
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dan Carpenter @ 2017-08-25 20:27 UTC (permalink / raw)
  To: Alexei Starovoitov, John Fastabend
  Cc: Daniel Borkmann, netdev, kernel-janitors

"err" is set to zero if bpf_map_area_alloc() fails so it means we return
ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is not
expecting NULL returns and will oops.

Fixes: 174a79ff9515 ("bpf: sockmap with sk redirect support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 78b2bb9370ac..a11b9f52ea4a 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -497,6 +497,7 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
 	if (err)
 		goto free_stab;
 
+	err = -ENOMEM;
 	stab->sock_map = bpf_map_area_alloc(stab->map.max_entries *
 					    sizeof(struct sock *),
 					    stab->map.numa_node);

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

* Re: [PATCH net-next] bpf: fix oops on allocation failure
  2017-08-25 20:27 [PATCH net-next] bpf: fix oops on allocation failure Dan Carpenter
@ 2017-08-25 20:47 ` Daniel Borkmann
  2017-08-28 15:58   ` John Fastabend
  2017-08-26  1:05 ` Alexei Starovoitov
  2017-08-28 22:23 ` David Miller
  2 siblings, 1 reply; 5+ messages in thread
From: Daniel Borkmann @ 2017-08-25 20:47 UTC (permalink / raw)
  To: Dan Carpenter, Alexei Starovoitov, John Fastabend; +Cc: netdev, kernel-janitors

On 08/25/2017 10:27 PM, Dan Carpenter wrote:
> "err" is set to zero if bpf_map_area_alloc() fails so it means we return
> ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is not
> expecting NULL returns and will oops.
>
> Fixes: 174a79ff9515 ("bpf: sockmap with sk redirect support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

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

* Re: [PATCH net-next] bpf: fix oops on allocation failure
  2017-08-25 20:27 [PATCH net-next] bpf: fix oops on allocation failure Dan Carpenter
  2017-08-25 20:47 ` Daniel Borkmann
@ 2017-08-26  1:05 ` Alexei Starovoitov
  2017-08-28 22:23 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2017-08-26  1:05 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Alexei Starovoitov, John Fastabend, Daniel Borkmann, netdev,
	kernel-janitors

On Fri, Aug 25, 2017 at 11:27:14PM +0300, Dan Carpenter wrote:
> "err" is set to zero if bpf_map_area_alloc() fails so it means we return
> ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is not
> expecting NULL returns and will oops.
> 
> Fixes: 174a79ff9515 ("bpf: sockmap with sk redirect support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

good catch. Thanks!
Acked-by: Alexei Starovoitov <ast@kernel.org>


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

* Re: [PATCH net-next] bpf: fix oops on allocation failure
  2017-08-25 20:47 ` Daniel Borkmann
@ 2017-08-28 15:58   ` John Fastabend
  0 siblings, 0 replies; 5+ messages in thread
From: John Fastabend @ 2017-08-28 15:58 UTC (permalink / raw)
  To: Daniel Borkmann, Dan Carpenter, Alexei Starovoitov
  Cc: netdev, kernel-janitors

On 08/25/2017 01:47 PM, Daniel Borkmann wrote:
> On 08/25/2017 10:27 PM, Dan Carpenter wrote:
>> "err" is set to zero if bpf_map_area_alloc() fails so it means we return
>> ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is not
>> expecting NULL returns and will oops.
>>
>> Fixes: 174a79ff9515 ("bpf: sockmap with sk redirect support")
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Acked-by: Daniel Borkmann <daniel@iogearbox.net>

Thanks.

Acked-by: John Fastabend <john.fastabend@gmail.com>

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

* Re: [PATCH net-next] bpf: fix oops on allocation failure
  2017-08-25 20:27 [PATCH net-next] bpf: fix oops on allocation failure Dan Carpenter
  2017-08-25 20:47 ` Daniel Borkmann
  2017-08-26  1:05 ` Alexei Starovoitov
@ 2017-08-28 22:23 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2017-08-28 22:23 UTC (permalink / raw)
  To: dan.carpenter; +Cc: ast, john.fastabend, daniel, netdev, kernel-janitors

From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Fri, 25 Aug 2017 23:27:14 +0300

> "err" is set to zero if bpf_map_area_alloc() fails so it means we return
> ERR_PTR(0) which is NULL.  The caller, find_and_alloc_map(), is not
> expecting NULL returns and will oops.
> 
> Fixes: 174a79ff9515 ("bpf: sockmap with sk redirect support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied.

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

end of thread, other threads:[~2017-08-28 22:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-25 20:27 [PATCH net-next] bpf: fix oops on allocation failure Dan Carpenter
2017-08-25 20:47 ` Daniel Borkmann
2017-08-28 15:58   ` John Fastabend
2017-08-26  1:05 ` Alexei Starovoitov
2017-08-28 22:23 ` David Miller

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).