From: Dan Carpenter Date: Fri, 25 Aug 2017 20:27:14 +0000 (+0300) Subject: bpf: fix oops on allocation failure X-Git-Tag: v4.14-rc1~130^2~115 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=f740c34ee5cf62e1fff5ebec6d0e63efcc3cdfe9;p=linux.git bpf: fix oops on allocation failure "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 Acked-by: Daniel Borkmann Acked-by: Alexei Starovoitov Acked-by: John Fastabend Signed-off-by: David S. Miller --- diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c index bcc326a2e5ce..db0d99d2fe18 100644 --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c @@ -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);