Skip to content

Commit

Permalink
virtio: rng: disallow multiple device registrations, fixes crashes
Browse files Browse the repository at this point in the history
The code currently only supports one virtio-rng device at a time.
Invoking guests with multiple devices causes the guest to blow up.

Check if we've already registered and initialised the driver.  Also
cleanup in case of registration errors or hot-unplug so that a new
device can be used.

Reported-by: Peter Krempa <pkrempa@redhat.com>
Reported-by: <yunzheng@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: stable@kernel.org
  • Loading branch information
Amit Shah authored and Rusty Russell committed Mar 8, 2013
1 parent f7f154f commit e84e7a5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions drivers/char/hw_random/virtio-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,22 @@ static int probe_common(struct virtio_device *vdev)
{
int err;

if (vq) {
/* We only support one device for now */
return -EBUSY;
}
/* We expect a single virtqueue. */
vq = virtio_find_single_vq(vdev, random_recv_done, "input");
if (IS_ERR(vq))
return PTR_ERR(vq);
if (IS_ERR(vq)) {
err = PTR_ERR(vq);
vq = NULL;
return err;
}

err = hwrng_register(&virtio_hwrng);
if (err) {
vdev->config->del_vqs(vdev);
vq = NULL;
return err;
}

Expand All @@ -112,6 +120,7 @@ static void remove_common(struct virtio_device *vdev)
busy = false;
hwrng_unregister(&virtio_hwrng);
vdev->config->del_vqs(vdev);
vq = NULL;
}

static int virtrng_probe(struct virtio_device *vdev)
Expand Down

0 comments on commit e84e7a5

Please sign in to comment.