Skip to contentSkip to conversation

libbpf: fix potential NULL pointer dereference

PATCH Applied Ciara Loftus 2 participants 2 messages Apr 8, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 tools/lib/bpf/xsk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/lib/bpf/xsk.c +3 -1
index d24b5cc720ec..770040d1f893 100644
@@ -858,12 +858,14 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
 	struct xsk_socket *xsk;
 	struct xsk_ctx *ctx;
 	int err, ifindex;
-	bool unmap = umem->fill_save != fill;
+	bool unmap;
 	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;
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Ciara Loftus

Wait until after the UMEM is checked for null to dereference it.

Fixes 43f1bc1efff1 ("libbpf: Restore umem state after socket create failure")

Applied, thanks!