Skip to contentSkip to conversation

virtio_vdpa: reject invalid vq indices

PATCH In review Vincent Whitchurch 3 participants 3 messages Jul 1, 2021 – Jul 5, 2021 virtio core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio_vdpa: reject invalid vq indices

Do not call vDPA drivers' callbacks with vq indicies larger than what the drivers indicate that they support. vDPA drivers do not bounds check the indices.

---
 drivers/virtio/virtio_vdpa.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/virtio/virtio_vdpa.c +3 -0
index e28acf482e0c..e9b9dd03f44a 100644
@@ -149,6 +149,9 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	if (!name)
 		return NULL;
 
+	if (index >= vdpa->nvqs)
+		return ERR_PTR(-ENOENT);
+
 	/* Queue shouldn't already be set up. */
 	if (ops->get_vq_ready(vdpa, index))
 		return ERR_PTR(-ENOENT);
Signature · 1 line
2.28.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Vincent Whitchurch

Do not call vDPA drivers' callbacks with vq indicies larger than what the drivers indicate that they support. vDPA drivers do not bounds check the indices.

Quoted 9 lines
---
  drivers/virtio/virtio_vdpa.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/virtio/virtio_vdpa.c +0 -0
index e28acf482e0c..e9b9dd03f44a 100644

drivers/virtio/virtio_vdpa.c virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, · line 157

Quoted 9 lines
drivers/virtio/virtio_vdpa.c +3 -0
@@ -149,6 +149,9 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
  	if (!name)
  		return NULL;
 
+	if (index >= vdpa->nvqs)
+		return ERR_PTR(-ENOENT);
+
  	/* Queue shouldn't already be set up. */
  	if (ops->get_vq_ready(vdpa, index))
  		return ERR_PTR(-ENOENT);

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reviewed-by on v1 1/1
#2 lore raw
In reply to Vincent Whitchurch
Quoted 26 lines · Vincent Whitchurch

Do not call vDPA drivers' callbacks with vq indicies larger than what the drivers indicate that they support. vDPA drivers do not bounds check the indices.

---
drivers/virtio/virtio_vdpa.c | 3 +++

1 file changed, 3 insertions(+)
drivers/virtio/virtio_vdpa.c +3 -0
index e28acf482e0c..e9b9dd03f44a 100644
@@ -149,6 +149,9 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	if (!name)
 		return NULL;
 
+	if (index >= vdpa->nvqs)
+		return ERR_PTR(-ENOENT);
+
 	/* Queue shouldn't already be set up. */
 	if (ops->get_vq_ready(vdpa, index))
 		return ERR_PTR(-ENOENT);
Signature · 1 line
2.28.0