Blame 0009-virtio-add-check-for-descriptor-s-mapped-address.patch

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