Skip to content

Commit ce7536b

Browse files
stefano-garzarellakuba-moo
authored andcommitted
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: 06a8fc7 ("VSOCK: Introduce virtio_vsock_common.ko") Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Link: https://lore.kernel.org/r/20210208144454.84438-1-sgarzare@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent af8085f commit ce7536b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎net/vmw_vsock/virtio_transport_common.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,8 +1130,6 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
11301130

11311131
vsk = vsock_sk(sk);
11321132

1133-
space_available = virtio_transport_space_update(sk, pkt);
1134-
11351133
lock_sock(sk);
11361134

11371135
/* Check if sk has been closed before lock_sock */
@@ -1142,6 +1140,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
11421140
goto free_pkt;
11431141
}
11441142

1143+
space_available = virtio_transport_space_update(sk, pkt);
1144+
11451145
/* Update CID in case it has changed after a transport reset event */
11461146
vsk->local_addr.svm_cid = dst.svm_cid;
11471147

0 commit comments

Comments
 (0)