Commit 1394103f authored by Xie Yongji's avatar Xie Yongji Committed by Michael S. Tsirkin

vduse: Disallow injecting interrupt before DRIVER_OK is set

The interrupt callback should not be triggered before DRIVER_OK
is set. Otherwise, it might break the virtio device driver.
So let's add a check to avoid the unexpected behavior.

Fixes: c8a6153b ("vduse: Introduce VDUSE - vDPA Device in Userspace")
Signed-off-by: default avatarXie Yongji <xieyongji@bytedance.com>
Link: https://lore.kernel.org/r/20210923075722.98-1-xieyongji@bytedance.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 64222515
...@@ -966,6 +966,10 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, ...@@ -966,6 +966,10 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
break; break;
} }
case VDUSE_DEV_INJECT_CONFIG_IRQ: case VDUSE_DEV_INJECT_CONFIG_IRQ:
ret = -EINVAL;
if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK))
break;
ret = 0; ret = 0;
queue_work(vduse_irq_wq, &dev->inject); queue_work(vduse_irq_wq, &dev->inject);
break; break;
...@@ -1045,6 +1049,10 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd, ...@@ -1045,6 +1049,10 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
case VDUSE_VQ_INJECT_IRQ: { case VDUSE_VQ_INJECT_IRQ: {
u32 index; u32 index;
ret = -EINVAL;
if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK))
break;
ret = -EFAULT; ret = -EFAULT;
if (get_user(index, (u32 __user *)argp)) if (get_user(index, (u32 __user *)argp))
break; break;
......
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