summaryrefslogtreecommitdiffstats
path: root/drivers/virtio
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2017-03-23 01:07:16 -0400
committerMichael S. Tsirkin <mst@redhat.com>2017-03-28 13:40:53 -0400
commitde85ec8b07f82c8c84de7687f769e74bf4c26a1e (patch)
tree72ce8462675d94d2e82723dc84583f644c5e190d /drivers/virtio
parentc02ed2e75ef4c74e41e421acb4ef1494671585e8 (diff)
virtio_pci: fix out of bound access for msix_names
Fedora has received multiple reports of crashes when running 4.11 as a guest https://bugzilla.redhat.com/show_bug.cgi?id=1430297 https://bugzilla.redhat.com/show_bug.cgi?id=1434462 https://bugzilla.kernel.org/show_bug.cgi?id=194911 https://bugzilla.redhat.com/show_bug.cgi?id=1433899 The crashes are not always consistent but they are generally some flavor of oops or GPF in virtio related code. Multiple people have done bisections (Thank you Thorsten Leemhuis and Richard W.M. Jones) and found this commit to be at fault 07ec51480b5eb1233f8c1b0f5d7a7c8d1247c507 is the first bad commit commit 07ec51480b5eb1233f8c1b0f5d7a7c8d1247c507 Author: Christoph Hellwig <hch@lst.de> Date: Sun Feb 5 18:15:19 2017 +0100 virtio_pci: use shared interrupts for virtqueues The issue seems to be an out of bounds access to the msix_names array corrupting kernel memory. Fixes: 07ec51480b5e ("virtio_pci: use shared interrupts for virtqueues") Reported-by: Laura Abbott <labbott@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Tested-by: Richard W.M. Jones <rjones@redhat.com> Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
Diffstat (limited to 'drivers/virtio')
-rw-r--r--drivers/virtio/virtio_pci_common.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index df548a6fb844..590534910dc6 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -147,7 +147,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
147{ 147{
148 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 148 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
149 const char *name = dev_name(&vp_dev->vdev.dev); 149 const char *name = dev_name(&vp_dev->vdev.dev);
150 int i, err = -ENOMEM, allocated_vectors, nvectors; 150 int i, j, err = -ENOMEM, allocated_vectors, nvectors;
151 unsigned flags = PCI_IRQ_MSIX; 151 unsigned flags = PCI_IRQ_MSIX;
152 bool shared = false; 152 bool shared = false;
153 u16 msix_vec; 153 u16 msix_vec;
@@ -212,7 +212,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
212 if (!vp_dev->msix_vector_map) 212 if (!vp_dev->msix_vector_map)
213 goto out_disable_config_irq; 213 goto out_disable_config_irq;
214 214
215 allocated_vectors = 1; /* vector 0 is the config interrupt */ 215 allocated_vectors = j = 1; /* vector 0 is the config interrupt */
216 for (i = 0; i < nvqs; ++i) { 216 for (i = 0; i < nvqs; ++i) {
217 if (!names[i]) { 217 if (!names[i]) {
218 vqs[i] = NULL; 218 vqs[i] = NULL;
@@ -236,18 +236,19 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
236 continue; 236 continue;
237 } 237 }
238 238
239 snprintf(vp_dev->msix_names[i + 1], 239 snprintf(vp_dev->msix_names[j],
240 sizeof(*vp_dev->msix_names), "%s-%s", 240 sizeof(*vp_dev->msix_names), "%s-%s",
241 dev_name(&vp_dev->vdev.dev), names[i]); 241 dev_name(&vp_dev->vdev.dev), names[i]);
242 err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec), 242 err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec),
243 vring_interrupt, IRQF_SHARED, 243 vring_interrupt, IRQF_SHARED,
244 vp_dev->msix_names[i + 1], vqs[i]); 244 vp_dev->msix_names[j], vqs[i]);
245 if (err) { 245 if (err) {
246 /* don't free this irq on error */ 246 /* don't free this irq on error */
247 vp_dev->msix_vector_map[i] = VIRTIO_MSI_NO_VECTOR; 247 vp_dev->msix_vector_map[i] = VIRTIO_MSI_NO_VECTOR;
248 goto out_remove_vqs; 248 goto out_remove_vqs;
249 } 249 }
250 vp_dev->msix_vector_map[i] = msix_vec; 250 vp_dev->msix_vector_map[i] = msix_vec;
251 j++;
251 252
252 /* 253 /*
253 * Use a different vector for each queue if they are available, 254 * Use a different vector for each queue if they are available,