Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vsock: cope with memory allocation failure at socket creation time

In the unlikely event that the kmalloc call in vmci_transport_socket_init()
fails, we end-up calling vmci_transport_destruct() with a NULL vmci_trans()
and oopsing.

This change addresses the above explicitly checking for zero vmci_trans()
at destruction time.

Reported-by: Xiumei Mu <xmu@redhat.com>
Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Jorgen Hansen <jhansen@vmware.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Paolo Abeni and committed by
David S. Miller
225d9464 c09551c6

+4
+4
net/vmw_vsock/vmci_transport.c
··· 1651 1651 1652 1652 static void vmci_transport_destruct(struct vsock_sock *vsk) 1653 1653 { 1654 + /* transport can be NULL if we hit a failure at init() time */ 1655 + if (!vmci_trans(vsk)) 1656 + return; 1657 + 1654 1658 /* Ensure that the detach callback doesn't use the sk/vsk 1655 1659 * we are about to destruct. 1656 1660 */