]> git.baikalelectronics.ru Git - kernel.git/commit
vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock
authorStefano Garzarella <sgarzare@redhat.com>
Fri, 28 Jun 2019 12:36:57 +0000 (14:36 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 2 Jul 2019 02:09:07 +0000 (19:09 -0700)
commitf3670f9448b57e059b09bf7abfd99849cbc2ab82
tree751056c1fd00c2a684c72588d76dece559e7067e
parent6ecbab320ab55cfd85748d447fcaed184010c604
vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock

Some callbacks used by the upper layers can run while we are in the
.remove(). A potential use-after-free can happen, because we free
the_virtio_vsock without knowing if the callbacks are over or not.

To solve this issue we move the assignment of the_virtio_vsock at the
end of .probe(), when we finished all the initialization, and at the
beginning of .remove(), before to release resources.
For the same reason, we do the same also for the vdev->priv.

We use RCU to be sure that all callbacks that use the_virtio_vsock
ended before freeing it. This is not required for callbacks that
use vdev->priv, because after the vdev->config->del_vqs() we are sure
that they are ended and will no longer be invoked.

We also take the mutex during the .remove() to avoid that .probe() can
run while we are resetting the device.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/vmw_vsock/virtio_transport.c