Skip to content

Commit

Permalink
bpf, xskmap: fix crash in xsk_map_alloc error path handling
Browse files Browse the repository at this point in the history
If bpf_map_precharge_memlock() did not fail, then we set err to zero.
However, any subsequent failure from either alloc_percpu() or the
bpf_map_area_alloc() will return ERR_PTR(0) which in find_and_alloc_map()
will cause NULL pointer deref.

In devmap we have the convention that we return -EINVAL on page count
overflow, so keep the same logic here and just set err to -ENOMEM
after successful bpf_map_precharge_memlock().

Fixes: fbfc504 ("bpf: introduce new bpf AF_XDP map type BPF_MAP_TYPE_XSKMAP")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Björn Töpel <bjorn.topel@intel.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Daniel Borkmann authored and Alexei Starovoitov committed May 4, 2018
1 parent a5458aa commit e94fa1d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kernel/bpf/xskmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ static struct bpf_map *xsk_map_alloc(union bpf_attr *attr)
if (err)
goto free_m;

err = -ENOMEM;

m->flush_list = alloc_percpu(struct list_head);
if (!m->flush_list)
goto free_m;
Expand Down

0 comments on commit e94fa1d

Please sign in to comment.