virtio: validate the existence of handle_output before calling it
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.
--- hw/virtio/virtio.c | 4 ++++ 1 file changed, 4 insertions(+)
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 ; + }trace_virtio_queue_notify (vdev, vq - vdev->vq, vq); vq->handle_output (vdev, vq); }
Signature · 1 line
1.9.1
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_outputwhich 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]>Signed-off-by Jason Wang <[email protected]>--- hw/virtio/virtio.c | 4 ++++ 1 file changed, 4 insertions(+)hw/virtio/virtio.c +0
-0
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
-0trace_virtio_queue_notify (vdev, vq - vdev->vq, vq); vq->handle_output (vdev, vq); }Signature · 1 line
1.9.1
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_outputwhich 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]>Signed-off-by Jason Wang <[email protected]>---
hw/virtio/virtio.c | 4 ++++ 1 file changed, 4 insertions(+)diff --git
a/hw/virtio/virtio.cb/hw/virtio/virtio.cindex d735343..ffc22e8 100644
---a/hw/virtio/virtio.c
+++b/hw/virtio/virtio.c
@@ -761,6 +761,10 @@ voidvirtio_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
Quoted 8 lines · Jason Wang
We don't validate the existence of
handle_outputwhich 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]>Signed-off-by Jason Wang <[email protected]>
Which queue was causing this?
Paolo
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Jason Wang
We don't validate the existence of
handle_outputwhich 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]>Signed-off-by Jason Wang <[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
Paolo Bonzini
Reviewed-byQuoted 19 lines · Jason Wang
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Jason Wang
We don't validate the existence of
handle_outputwhich 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]>Signed-off-by Jason Wang <[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.