|
@@ -1073,7 +1073,7 @@ int mtty_get_region_info(struct mdev_device *mdev,
|
|
|
{
|
|
|
unsigned int size = 0;
|
|
|
struct mdev_state *mdev_state;
|
|
|
- int bar_index;
|
|
|
+ u32 bar_index;
|
|
|
|
|
|
if (!mdev)
|
|
|
return -EINVAL;
|
|
@@ -1082,8 +1082,11 @@ int mtty_get_region_info(struct mdev_device *mdev,
|
|
|
if (!mdev_state)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- mutex_lock(&mdev_state->ops_lock);
|
|
|
bar_index = region_info->index;
|
|
|
+ if (bar_index >= VFIO_PCI_NUM_REGIONS)
|
|
|
+ return -EINVAL;
|
|
|
+
|
|
|
+ mutex_lock(&mdev_state->ops_lock);
|
|
|
|
|
|
switch (bar_index) {
|
|
|
case VFIO_PCI_CONFIG_REGION_INDEX:
|
|
@@ -1180,7 +1183,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
|
|
|
|
|
|
memcpy(&mdev_state->dev_info, &info, sizeof(info));
|
|
|
|
|
|
- return copy_to_user((void __user *)arg, &info, minsz);
|
|
|
+ if (copy_to_user((void __user *)arg, &info, minsz))
|
|
|
+ return -EFAULT;
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
case VFIO_DEVICE_GET_REGION_INFO:
|
|
|
{
|
|
@@ -1201,7 +1207,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
|
|
|
if (ret)
|
|
|
return ret;
|
|
|
|
|
|
- return copy_to_user((void __user *)arg, &info, minsz);
|
|
|
+ if (copy_to_user((void __user *)arg, &info, minsz))
|
|
|
+ return -EFAULT;
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
case VFIO_DEVICE_GET_IRQ_INFO:
|
|
@@ -1221,10 +1230,10 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd,
|
|
|
if (ret)
|
|
|
return ret;
|
|
|
|
|
|
- if (info.count == -1)
|
|
|
- return -EINVAL;
|
|
|
+ if (copy_to_user((void __user *)arg, &info, minsz))
|
|
|
+ return -EFAULT;
|
|
|
|
|
|
- return copy_to_user((void __user *)arg, &info, minsz);
|
|
|
+ return 0;
|
|
|
}
|
|
|
case VFIO_DEVICE_SET_IRQS:
|
|
|
{
|