Skip to contentSkip to conversation

virtio: validate the existence of handle_output before calling it

PATCH In review Jason Wang 3 participants 3 messages Mar 12, 2015 – Mar 13, 2015

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH v2 1/1 virtio: validate the existence of handle_output before calling it

We don't validate the existence of handle_output which may let a buggy guest to trigger a SIGSEV easily. E.g:

1) write 10 to queue_sel to a virtio net device with only 1 queue
2) setup an arbitrary pfn
3) then notify queue 10

Fixing this by validating the existence of handle_output before.

---
Changes from V1:
- check the existence of both vring.desc and handle_output in the same line
- describe the reproducer in the commit log

---
 hw/virtio/virtio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +2 -1
index 3c6e430..17c1260 100644
@@ -759,8 +759,9 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
 
 void virtio_queue_notify_vq(VirtQueue *vq)
 {
-    if (vq->vring.desc) {
+    if (vq->vring.desc && vq->handle_output) {
         VirtIODevice *vdev = vq->vdev;
+
         trace_virtio_queue_notify(vdev, vq - vdev->vq, vq);
         vq->handle_output(vdev, vq);
     }
Signature · 1 line
2.1.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · On Thu, 12 Mar 2015 17:50:18 +0800 Jason Wang <[email protected]> wrote:

We don't validate the existence of handle_output which may let a buggy guest to trigger a SIGSEV easily. E.g:

1) write 10 to queue_sel to a virtio net device with only 1 queue
2) setup an arbitrary pfn
3) then notify queue 10

Quoted 6 lines

Fixing this by validating the existence of handle_output before.

---

Quoted 27 lines

Changes from V1:
- check the existence of both vring.desc and handle_output in the same line
- describe the reproducer in the commit log

---
 hw/virtio/virtio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +2 -1
index 3c6e430..17c1260 100644
@@ -759,8 +759,9 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
 
 void virtio_queue_notify_vq(VirtQueue *vq)
 {
-    if (vq->vring.desc) {
+    if (vq->vring.desc && vq->handle_output) {
         VirtIODevice *vdev = vq->vdev;
+
         trace_virtio_queue_notify(vdev, vq - vdev->vq, vq);
         vq->handle_output(vdev, vq);
     }
Signature · 1 line
2.1.0
Reviewed-by on v2 1/1
#2 lore raw
In reply to Jason Wang
Quoted 7 lines · Jason Wang

We don't validate the existence of handle_output which may let a buggy guest to trigger a SIGSEV easily. E.g:

1) write 10 to queue_sel to a virtio net device with only 1 queue
2) setup an arbitrary pfn
3) then notify queue 10

Quoted 5 lines

Fixing this by validating the existence of handle_output before.

Quoted 28 lines

---
Changes from V1:
- check the existence of both vring.desc and handle_output in the same line
- describe the reproducer in the commit log

---
 hw/virtio/virtio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +2 -1
index 3c6e430..17c1260 100644
@@ -759,8 +759,9 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
 
 void virtio_queue_notify_vq(VirtQueue *vq)
 {
-    if (vq->vring.desc) {
+    if (vq->vring.desc && vq->handle_output) {
         VirtIODevice *vdev = vq->vdev;
+
         trace_virtio_queue_notify(vdev, vq - vdev->vq, vq);
         vq->handle_output(vdev, vq);
     }
Signature · 1 line
2.1.0