[RFC PATCH 01/15] virtio_config: Add return value to virtio_device_ready()
From: Xie Yongji
Date: Mon May 17 2021 - 05:35:05 EST
We might get invalid status from untrusted device. Let's remove
BUG_ON and add return value to virtio_device_ready() to handle
this case gracefully.
Signed-off-by: Xie Yongji <xieyongji@xxxxxxxxxxxxx>
---
include/linux/virtio_config.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 8519b3ae5d52..0e61cd89ac1d 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -225,12 +225,16 @@ int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs,
* Note: vqs are enabled automatically after probe returns.
*/
static inline
-void virtio_device_ready(struct virtio_device *dev)
+int virtio_device_ready(struct virtio_device *dev)
{
unsigned status = dev->config->get_status(dev);
- BUG_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
+ if (status & VIRTIO_CONFIG_S_DRIVER_OK)
+ return -EINVAL;
+
dev->config->set_status(dev, status | VIRTIO_CONFIG_S_DRIVER_OK);
+
+ return 0;
}
static inline
--
2.11.0