Skip to content

Commit

Permalink
vsock/virtio: update credit only if socket is not closed
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Michael S. Tsirkin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
stefano-garzarella authored and kuba-moo committed Feb 8, 2021
1 parent af8085f commit ce7536b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/vmw_vsock/virtio_transport_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,6 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,

vsk = vsock_sk(sk);

space_available = virtio_transport_space_update(sk, pkt);

lock_sock(sk);

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

space_available = virtio_transport_space_update(sk, pkt);

/* Update CID in case it has changed after a transport reset event */
vsk->local_addr.svm_cid = dst.svm_cid;

Expand Down

0 comments on commit ce7536b

Please sign in to comment.