vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock
authorStefano Garzarella <sgarzare@redhat.com>
Fri, 5 Jul 2019 11:04:52 +0000 (13:04 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Oct 2020 07:48:11 +0000 (09:48 +0200)
commitd87ebcd52eeeed8923c3eba266fd1907fbd067c6
tree86cf001106ffb658ca84984660a0e9aa46b7163e
parent716527d016c783b7bde0896b641c342c08809703
vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock

[ Upstream commit 9c7a5582f5d720dc35cfcc42ccaded69f0642e4a ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/vmw_vsock/virtio_transport.c