]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
xsk: Fix possible segfault in xsk umem diagnostics
authorMagnus Karlsson <magnus.karlsson@intel.com>
Wed, 2 Sep 2020 08:52:23 +0000 (10:52 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 2 Sep 2020 14:49:40 +0000 (16:49 +0200)
Fix possible segfault in the xsk diagnostics code when dumping
information about the umem. This can happen when a umem has been
created, but the socket has not been bound yet. In this case, the xsk
buffer pool does not exist yet and we cannot dump the information
that was moved from the umem to the buffer pool. Fix this by testing
for the existence of the buffer pool and if not there, do not dump any
of that information.

Fixes: c2d3d6a47462 ("xsk: Move queue_id, dev and need_wakeup to buffer pool")
Fixes: 7361f9c3d719 ("xsk: Move fill and completion rings to buffer pool")
Reported-by: syzbot+3f04d36b7336f7868066@syzkaller.appspotmail.com
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/1599036743-26454-1-git-send-email-magnus.karlsson@intel.com
net/xdp/xsk_diag.c

index 5bd8ea9d206ad31c4bb51c32f035da34535a43bc..c014217f5fa7d92aba92b2682416d208f8a53fdf 100644 (file)
@@ -59,22 +59,20 @@ static int xsk_diag_put_umem(const struct xdp_sock *xs, struct sk_buff *nlskb)
        du.num_pages = umem->npgs;
        du.chunk_size = umem->chunk_size;
        du.headroom = umem->headroom;
-       du.ifindex = pool->netdev ? pool->netdev->ifindex : 0;
-       du.queue_id = pool->queue_id;
+       du.ifindex = (pool && pool->netdev) ? pool->netdev->ifindex : 0;
+       du.queue_id = pool ? pool->queue_id : 0;
        du.flags = 0;
        if (umem->zc)
                du.flags |= XDP_DU_F_ZEROCOPY;
        du.refs = refcount_read(&umem->users);
 
        err = nla_put(nlskb, XDP_DIAG_UMEM, sizeof(du), &du);
-
-       if (!err && pool->fq)
+       if (!err && pool && pool->fq)
                err = xsk_diag_put_ring(pool->fq,
                                        XDP_DIAG_UMEM_FILL_RING, nlskb);
-       if (!err && pool->cq) {
-               err = xsk_diag_put_ring(pool->cq, XDP_DIAG_UMEM_COMPLETION_RING,
-                                       nlskb);
-       }
+       if (!err && pool && pool->cq)
+               err = xsk_diag_put_ring(pool->cq,
+                                       XDP_DIAG_UMEM_COMPLETION_RING, nlskb);
        return err;
 }