]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
vfio/pci: Fix unsigned comparison overflow
authorAlex Williamson <alex.williamson@redhat.com>
Mon, 22 Feb 2016 23:02:29 +0000 (16:02 -0700)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 16 Jun 2017 20:13:00 +0000 (16:13 -0400)
Signed versus unsigned comparisons are implicitly cast to unsigned,
which result in a couple possible overflows.  For instance (start +
count) might overflow and wrap, getting through our validation test.
Also when unwinding setup, -1 being compared as unsigned doesn't
produce the intended stop condition.  Fix both of these and also fix
vfio_msi_set_vector_signal() to validate parameters before using the
vector index, though none of the callers should pass bad indexes
anymore.

OraBug: 26223261
Reported-by: Eric Auger <eric.auger@linaro.org>
Reviewed-by: Eric Auger <eric.auger@linaro.org>
Tested-by: Eric Auger <eric.auger@linaro.org>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
(cherry picked from commit b95d9305e8cb8d432ca02da1b759fef59bc50ace)
Reviewed-by: Shannon Nelson <shannon.nelson@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
drivers/vfio/pci/vfio_pci_intrs.c

index d4f3979c32b75634cbc447ebb0e1e228117313f8..444898763797254b5a6bed48a7d071fe02a88af8 100644 (file)
@@ -309,14 +309,14 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
                                      int vector, int fd, bool msix)
 {
        struct pci_dev *pdev = vdev->pdev;
-       int irq = msix ? vdev->msix[vector].vector : pdev->irq + vector;
-       char *name = msix ? "vfio-msix" : "vfio-msi";
        struct eventfd_ctx *trigger;
-       int ret;
+       int irq, ret;
 
-       if (vector >= vdev->num_ctx)
+       if (vector < 0 || vector >= vdev->num_ctx)
                return -EINVAL;
 
+       irq = msix ? vdev->msix[vector].vector : pdev->irq + vector;
+
        if (vdev->ctx[vector].trigger) {
                free_irq(irq, vdev->ctx[vector].trigger);
                kfree(vdev->ctx[vector].name);
@@ -327,8 +327,9 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
        if (fd < 0)
                return 0;
 
-       vdev->ctx[vector].name = kasprintf(GFP_KERNEL, "%s[%d](%s)",
-                                          name, vector, pci_name(pdev));
+       vdev->ctx[vector].name = kasprintf(GFP_KERNEL, "vfio-msi%s[%d](%s)",
+                                          msix ? "x" : "", vector,
+                                          pci_name(pdev));
        if (!vdev->ctx[vector].name)
                return -ENOMEM;
 
@@ -370,7 +371,7 @@ static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start,
 {
        int i, j, ret = 0;
 
-       if (start + count > vdev->num_ctx)
+       if (start >= vdev->num_ctx || start + count > vdev->num_ctx)
                return -EINVAL;
 
        for (i = 0, j = start; i < count && !ret; i++, j++) {
@@ -379,7 +380,7 @@ static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start,
        }
 
        if (ret) {
-               for (--j; j >= start; j--)
+               for (--j; j >= (int)start; j--)
                        vfio_msi_set_vector_signal(vdev, j, -1, msix);
        }