carlwgeorge / rpms / qemu

Forked from rpms/qemu a year ago
Clone
808a2e2
From: Prasad J Pandit <pjp@fedoraproject.org>
808a2e2
Date: Mon, 19 Sep 2016 23:55:45 +0530
808a2e2
Subject: [PATCH] virtio: add check for descriptor's mapped address
808a2e2
808a2e2
virtio back end uses set of buffers to facilitate I/O operations.
808a2e2
If its size is too large, 'cpu_physical_memory_map' could return
808a2e2
a null address. This would result in a null dereference while
808a2e2
un-mapping descriptors. Add check to avoid it.
808a2e2
808a2e2
Reported-by: Qinghao Tang <luodalongde@gmail.com>
808a2e2
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
808a2e2
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
808a2e2
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
808a2e2
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
808a2e2
(cherry picked from commit 973e7170dddefb491a48df5cba33b2ae151013a0)
808a2e2
---
808a2e2
 hw/virtio/virtio.c | 5 +++++
808a2e2
 1 file changed, 5 insertions(+)
808a2e2
808a2e2
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
808a2e2
index 20c4f39..3a470fc 100644
808a2e2
--- a/hw/virtio/virtio.c
808a2e2
+++ b/hw/virtio/virtio.c
808a2e2
@@ -472,6 +472,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
808a2e2
         }
808a2e2
 
808a2e2
         iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
808a2e2
+        if (!iov[num_sg].iov_base) {
808a2e2
+            error_report("virtio: bogus descriptor or out of resources");
808a2e2
+            exit(1);
808a2e2
+        }
808a2e2
+
808a2e2
         iov[num_sg].iov_len = len;
808a2e2
         addr[num_sg] = pa;
808a2e2