Commit a75e0032 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'vfio-v4.9-rc4' of git://github.com/awilliam/linux-vfio

Pull VFIO fix from Alex Williamson:
 "SET_IRQS ioctl parameter sanitization (Vlad Tsyrklevich)"

* tag 'vfio-v4.9-rc4' of git://github.com/awilliam/linux-vfio:
  vfio/pci: Fix integer overflows, bitmask check
parents 0c183d92 05692d70
...@@ -829,8 +829,9 @@ static long vfio_pci_ioctl(void *device_data, ...@@ -829,8 +829,9 @@ static long vfio_pci_ioctl(void *device_data,
} else if (cmd == VFIO_DEVICE_SET_IRQS) { } else if (cmd == VFIO_DEVICE_SET_IRQS) {
struct vfio_irq_set hdr; struct vfio_irq_set hdr;
size_t size;
u8 *data = NULL; u8 *data = NULL;
int ret = 0; int max, ret = 0;
minsz = offsetofend(struct vfio_irq_set, count); minsz = offsetofend(struct vfio_irq_set, count);
...@@ -838,23 +839,31 @@ static long vfio_pci_ioctl(void *device_data, ...@@ -838,23 +839,31 @@ static long vfio_pci_ioctl(void *device_data,
return -EFAULT; return -EFAULT;
if (hdr.argsz < minsz || hdr.index >= VFIO_PCI_NUM_IRQS || if (hdr.argsz < minsz || hdr.index >= VFIO_PCI_NUM_IRQS ||
hdr.count >= (U32_MAX - hdr.start) ||
hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK | hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK |
VFIO_IRQ_SET_ACTION_TYPE_MASK)) VFIO_IRQ_SET_ACTION_TYPE_MASK))
return -EINVAL; return -EINVAL;
if (!(hdr.flags & VFIO_IRQ_SET_DATA_NONE)) { max = vfio_pci_get_irq_count(vdev, hdr.index);
size_t size; if (hdr.start >= max || hdr.start + hdr.count > max)
int max = vfio_pci_get_irq_count(vdev, hdr.index); return -EINVAL;
if (hdr.flags & VFIO_IRQ_SET_DATA_BOOL) switch (hdr.flags & VFIO_IRQ_SET_DATA_TYPE_MASK) {
size = sizeof(uint8_t); case VFIO_IRQ_SET_DATA_NONE:
else if (hdr.flags & VFIO_IRQ_SET_DATA_EVENTFD) size = 0;
size = sizeof(int32_t); break;
else case VFIO_IRQ_SET_DATA_BOOL:
return -EINVAL; size = sizeof(uint8_t);
break;
case VFIO_IRQ_SET_DATA_EVENTFD:
size = sizeof(int32_t);
break;
default:
return -EINVAL;
}
if (hdr.argsz - minsz < hdr.count * size || if (size) {
hdr.start >= max || hdr.start + hdr.count > max) if (hdr.argsz - minsz < hdr.count * size)
return -EINVAL; return -EINVAL;
data = memdup_user((void __user *)(arg + minsz), data = memdup_user((void __user *)(arg + minsz),
......
...@@ -256,7 +256,7 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix) ...@@ -256,7 +256,7 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
if (!is_irq_none(vdev)) if (!is_irq_none(vdev))
return -EINVAL; return -EINVAL;
vdev->ctx = kzalloc(nvec * sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL); vdev->ctx = kcalloc(nvec, sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL);
if (!vdev->ctx) if (!vdev->ctx)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment