mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
hwrng: virtio - prevent use-after-free after a failed restore
remove_common() frees the driver data during freeze, but does not clear
vdev->priv, which points to freed memory. If probe_common() then fails
during restore, a later remove or freeze can dereference the dangling
pointer.
Clear vdev->priv on the probe_common() error cleanup path and before
freeing the driver data in remove_common(). Also reset the device and
return early from remove_common() if vdev->priv is already NULL for a
safe teardown after a failed restore.
Fixes: 08e53fbdb8 ("virtio-rng: support multiple virtio-rng devices")
Cc: stable@vger.kernel.org
Signed-off-by: Thorsten Blum <blum@kernel.org>
Reviewed-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20261016103640.4989-2-blum@kernel.org>
This commit is contained in:
parent
57c1c0d172
commit
0f7bf47f5a
|
|
@ -190,6 +190,7 @@ static int probe_common(struct virtio_device *vdev)
|
|||
err_find:
|
||||
ida_free(&rng_index_ida, index);
|
||||
err_ida:
|
||||
vdev->priv = NULL;
|
||||
kfree(vi);
|
||||
return err;
|
||||
}
|
||||
|
|
@ -198,6 +199,11 @@ static void remove_common(struct virtio_device *vdev)
|
|||
{
|
||||
struct virtrng_info *vi = vdev->priv;
|
||||
|
||||
if (!vi) {
|
||||
virtio_reset_device(vdev);
|
||||
return;
|
||||
}
|
||||
|
||||
vi->hwrng_removed = true;
|
||||
vi->data_avail = 0;
|
||||
vi->data_idx = 0;
|
||||
|
|
@ -207,6 +213,7 @@ static void remove_common(struct virtio_device *vdev)
|
|||
virtio_reset_device(vdev);
|
||||
vdev->config->del_vqs(vdev);
|
||||
ida_free(&rng_index_ida, vi->index);
|
||||
vdev->priv = NULL;
|
||||
kfree(vi);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user