Skip to contentSkip to conversation

virtio: validate the existence of handle_output before calling it

PATCH Superseded Jason Wang 3 participants 6 messages Feb 12, 2015 – Feb 16, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 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. Fix this by validate its existence before.

Cc Anthony Liguori <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/virtio/virtio.c +4 -0
index d735343..ffc22e8 100644
@@ -761,6 +761,10 @@ void virtio_queue_notify_vq(VirtQueue *vq)
 {
     if (vq->vring.desc) {
         VirtIODevice *vdev = vq->vdev;
+
+        if (!vq->handle_output) {
+            return;
+        }
         trace_virtio_queue_notify(vdev, vq - vdev->vq, vq);
         vq->handle_output(vdev, vq);
     }
Signature · 1 line
1.9.1
#1 lore raw
Quoted 17 lines · On Thu, 12 Feb 2015 11:05:17 +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. Fix this by validate its existence before.

Cc Anthony Liguori <[email protected]>
Cc Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/virtio/virtio.c +0 -0
index d735343..ffc22e8 100644

hw/virtio/virtio.c void virtio_queue_notify_vq(VirtQueue *vq) · line 767

Quoted 7 lines
hw/virtio/virtio.c +4 -0
@@ -761,6 +761,10 @@ void virtio_queue_notify_vq(VirtQueue *vq)
 {
     if (vq->vring.desc) {
         VirtIODevice *vdev = vq->vdev;
+
+        if (!vq->handle_output) {
+            return;
+        }

Maybe better to just change line 762 to:

     if (vq->vring.desc && vq->handle_output) {

-d

Quoted 7 lines
hw/virtio/virtio.c +0 -0
         trace_virtio_queue_notify(vdev, vq - vdev->vq, vq);
         vq->handle_output(vdev, vq);
     }
Signature · 1 line
1.9.1
author
#2 lore raw
Quoted 29 lines · Don Koch
Quoted 18 lines · On Thu, 12 Feb 2015 11:05:17 +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. Fix this by validate its existence before.

Cc Anthony Liguori <[email protected]>
Cc Michael S. Tsirkin <[email protected]>

---

  hw/virtio/virtio.c | 4 ++++
  1 file changed, 4 insertions(+)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index d735343..ffc22e8 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -761,6 +761,10 @@ void virtio_queue_notify_vq(VirtQueue *vq)

Quoted 7 lines
  {
      if (vq->vring.desc) {
          VirtIODevice *vdev = vq->vdev;

+
+ if (!vq->handle_output) {
+ return;
+ }

Quoted 4 lines

Maybe better to just change line 762 to:

     if (vq->vring.desc && vq->handle_output) {

-d

Yes, better.

Quoted 9 lines
Quoted 9 lines

          trace_virtio_queue_notify(vdev, vq - vdev->vq, vq);
          vq->handle_output(vdev, vq);
      }

--
1.9.1

author
#4 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Jason Wang

We don't validate the existence of handle_output which may let a
buggy
guest to trigger a SIGSEV easily. Fix this by validate its existence before.

Quoted 8 lines
Quoted 4 lines
Cc Anthony Liguori <[email protected]>
Cc Michael S. Tsirkin <[email protected]>

Which queue was causing this?

Paolo

The queue that was not used by the device. Though qemu does not use them, but it allows guest to do some basic programming. e.g: (for 1q virtio-net)

1) write 10 to queue_sel
2) setup an arbitrary pfn
3) then notify queue 10

Reviewed-by
#5 lore raw
Quoted 19 lines · Jason Wang
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Jason Wang

We don't validate the existence of handle_output which may let a buggy guest to trigger a SIGSEV easily. Fix this by validate its existence before.

Quoted 8 lines
Quoted 4 lines
Cc Anthony Liguori <[email protected]>
Cc Michael S. Tsirkin <[email protected]>

Which queue was causing this?

Paolo

Quoted 7 lines

The queue that was not used by the device. Though qemu does not use them, but it allows guest to do some basic programming. e.g: (for 1q virtio-net)

1) write 10 to queue_sel
2) setup an arbitrary pfn
3) then notify queue 10

Oh, I see.