Amit Shah
2013-Mar-06 08:13 UTC
[PATCH 1/1] virtio: rng: disallow multiple device registrations, fixes crashes
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 at redhat.com>
Reported-by: <yunzheng at redhat.com>
Signed-off-by: Amit Shah <amit.shah at redhat.com>
---
Also valid for stable?
drivers/char/hw_random/virtio-rng.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/char/hw_random/virtio-rng.c
b/drivers/char/hw_random/virtio-rng.c
index 10fd71c..6bf4d47 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -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;
}
@@ -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)
--
1.8.1.2
Rusty Russell
2013-Mar-07 01:06 UTC
[PATCH 1/1] virtio: rng: disallow multiple device registrations, fixes crashes
Amit Shah <amit.shah at redhat.com> writes:> 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 at redhat.com> > Reported-by: <yunzheng at redhat.com> > Signed-off-by: Amit Shah <amit.shah at redhat.com> > --- > > Also valid for stable?Yes. We could fix virtio-rng to allow multiple rngs, but of course it will fail anyway since hwrng wants unique names. And changing the name to be virtio-%u will probably break things, for no real upside. Applied, and Cc:stable added. Thanks, Rusty.
Reasonably Related Threads
- [PATCH 1/1] virtio: rng: disallow multiple device registrations, fixes crashes
- [PATCH] virtio-rng: support multiple virtio-rng devices
- [PATCH] virtio-rng: support multiple virtio-rng devices
- [kvm-devel] [Virtio-for-kvm] [PATCH 2/13] [Mostly resend] virtio additions
- [kvm-devel] [Virtio-for-kvm] [PATCH 2/13] [Mostly resend] virtio additions