Commit ce7536bc authored by Stefano Garzarella's avatar Stefano Garzarella Committed by Jakub Kicinski

vsock/virtio: update credit only if socket is not closed

If the socket is closed or is being released, some resources used by
virtio_transport_space_update() such as 'vsk->trans' may be released.

To avoid a use after free bug we should only update the available credit
when we are sure the socket is still open and we have the lock held.

Fixes: 06a8fc78 ("VSOCK: Introduce virtio_vsock_common.ko")
Signed-off-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Link: https://lore.kernel.org/r/20210208144454.84438-1-sgarzare@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent af8085f3
...@@ -1130,8 +1130,6 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, ...@@ -1130,8 +1130,6 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
vsk = vsock_sk(sk); vsk = vsock_sk(sk);
space_available = virtio_transport_space_update(sk, pkt);
lock_sock(sk); lock_sock(sk);
/* Check if sk has been closed before lock_sock */ /* Check if sk has been closed before lock_sock */
...@@ -1142,6 +1140,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, ...@@ -1142,6 +1140,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
goto free_pkt; goto free_pkt;
} }
space_available = virtio_transport_space_update(sk, pkt);
/* Update CID in case it has changed after a transport reset event */ /* Update CID in case it has changed after a transport reset event */
vsk->local_addr.svm_cid = dst.svm_cid; vsk->local_addr.svm_cid = dst.svm_cid;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment