Skip to content

Commit

Permalink
bpf: fix sock_map_alloc() error path
Browse files Browse the repository at this point in the history
In case user program provides silly parameters, we want
a map_alloc() handler to return an error, not a NULL pointer,
otherwise we crash later in find_and_alloc_map()

Fixes: 1aa12bd ("bpf: sockmap, add sock close() hook to remove socks")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Eric Dumazet authored and Alexei Starovoitov committed Feb 14, 2018
1 parent 9a3efb6 commit 952fad8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kernel/bpf/sockmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ static struct smap_psock *smap_init_psock(struct sock *sock,
static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
{
struct bpf_stab *stab;
int err = -EINVAL;
u64 cost;
int err;

if (!capable(CAP_NET_ADMIN))
return ERR_PTR(-EPERM);
Expand All @@ -547,6 +547,7 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)

/* make sure page count doesn't overflow */
cost = (u64) stab->map.max_entries * sizeof(struct sock *);
err = -EINVAL;
if (cost >= U32_MAX - PAGE_SIZE)
goto free_stab;

Expand Down

0 comments on commit 952fad8

Please sign in to comment.