]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
bpf: fix oops on allocation failure
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 25 Aug 2017 20:27:14 +0000 (23:27 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Aug 2017 22:23:34 +0000 (15:23 -0700)
"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>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/sockmap.c

index bcc326a2e5cebd23759179f37496976b213f7902..db0d99d2fe1846cc19b202b42df4031fc7f4d5f3 100644 (file)
@@ -523,6 +523,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);