diff options
author | Ciara Loftus <ciara.loftus@intel.com> | 2021-04-08 05:20:09 +0000 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2021-04-08 23:36:46 +0200 |
commit | afd0be7299533bb2e2b09104399d8a467ecbd2c5 (patch) | |
tree | c6daed3ba58f8fff559c91d57623889d1aac7b71 /tools | |
parent | 1ffbc7ea91606e4abd10eb60de5367f1c86daf5e (diff) | |
download | linux-afd0be7299533bb2e2b09104399d8a467ecbd2c5.tar.bz2 |
libbpf: Fix potential NULL pointer dereference
Wait until after the UMEM is checked for null to dereference it.
Fixes: 43f1bc1efff1 ("libbpf: Restore umem state after socket create failure")
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210408052009.7844-1-ciara.loftus@intel.com
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lib/bpf/xsk.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c index d24b5cc720ec..007fe5d59438 100644 --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c @@ -852,18 +852,19 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr, struct xsk_ring_cons *comp, const struct xsk_socket_config *usr_config) { + bool unmap, rx_setup_done = false, tx_setup_done = false; void *rx_map = NULL, *tx_map = NULL; struct sockaddr_xdp sxdp = {}; struct xdp_mmap_offsets off; struct xsk_socket *xsk; struct xsk_ctx *ctx; int err, ifindex; - bool unmap = umem->fill_save != fill; - bool rx_setup_done = false, tx_setup_done = false; if (!umem || !xsk_ptr || !(rx || tx)) return -EFAULT; + unmap = umem->fill_save != fill; + xsk = calloc(1, sizeof(*xsk)); if (!xsk) return -ENOMEM; |