diff options
| author | Amit Shah <amit.shah@redhat.com> | 2013-03-07 19:30:18 -0500 |
|---|---|---|
| committer | Rusty Russell <rusty@rustcorp.com.au> | 2013-03-07 19:30:43 -0500 |
| commit | e84e7a56a3aa2963db506299e29a5f3f09377f9b (patch) | |
| tree | 3c368fc922977af1760932c55fcfb69e20126cfa | |
| parent | f7f154f1246ccc5a0a7e9ce50932627d60a0c878 (diff) | |
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@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
| -rw-r--r-- | drivers/char/hw_random/virtio-rng.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index 10fd71ccf587..6bf4d47324eb 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) | |||
| 92 | { | 92 | { |
| 93 | int err; | 93 | int err; |
| 94 | 94 | ||
| 95 | if (vq) { | ||
| 96 | /* We only support one device for now */ | ||
| 97 | return -EBUSY; | ||
| 98 | } | ||
| 95 | /* We expect a single virtqueue. */ | 99 | /* We expect a single virtqueue. */ |
| 96 | vq = virtio_find_single_vq(vdev, random_recv_done, "input"); | 100 | vq = virtio_find_single_vq(vdev, random_recv_done, "input"); |
| 97 | if (IS_ERR(vq)) | 101 | if (IS_ERR(vq)) { |
| 98 | return PTR_ERR(vq); | 102 | err = PTR_ERR(vq); |
| 103 | vq = NULL; | ||
| 104 | return err; | ||
| 105 | } | ||
| 99 | 106 | ||
| 100 | err = hwrng_register(&virtio_hwrng); | 107 | err = hwrng_register(&virtio_hwrng); |
| 101 | if (err) { | 108 | if (err) { |
| 102 | vdev->config->del_vqs(vdev); | 109 | vdev->config->del_vqs(vdev); |
| 110 | vq = NULL; | ||
| 103 | return err; | 111 | return err; |
| 104 | } | 112 | } |
| 105 | 113 | ||
| @@ -112,6 +120,7 @@ static void remove_common(struct virtio_device *vdev) | |||
| 112 | busy = false; | 120 | busy = false; |
| 113 | hwrng_unregister(&virtio_hwrng); | 121 | hwrng_unregister(&virtio_hwrng); |
| 114 | vdev->config->del_vqs(vdev); | 122 | vdev->config->del_vqs(vdev); |
| 123 | vq = NULL; | ||
| 115 | } | 124 | } |
| 116 | 125 | ||
| 117 | static int virtrng_probe(struct virtio_device *vdev) | 126 | static int virtrng_probe(struct virtio_device *vdev) |
