Skip to contentSkip to conversation

virtio: add check for descriptor's mapped address

PATCH In review P J P 3 participants 3 messages Sep 19, 2016 – Sep 20, 2016

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH v3 1/1 virtio: add check for descriptor's mapped address

From: Prasad J Pandit <[email protected]>

virtio back end uses set of buffers to facilitate I/O operations. If its size is too large, 'cpu_physical_memory_map' could return a null address. This would result in a null dereference while un-mapping descriptors. Add check to avoid it.

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

Update per:
-> https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg04329.html

hw/virtio/virtio.c +5 -0
index 15ee3a7..a4ebf8c 100644
@@ -472,6 +472,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
         }
 
         iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
+        if (!iov[num_sg].iov_base) {
+            error_report("virtio: bogus descriptor or out of resources");
+            exit(1);
+        }
+
         iov[num_sg].iov_len = len;
         addr[num_sg] = pa;
 
Signature · 1 line
2.5.5
Reviewed-by on v3 1/1
#1 lore raw
Quoted 23 lines · P J P

From: Prasad J Pandit <[email protected]>

virtio back end uses set of buffers to facilitate I/O operations. If its size is too large, 'cpu_physical_memory_map' could return a null address. This would result in a null dereference while un-mapping descriptors. Add check to avoid it.

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

Update per:
-> https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg04329.html

hw/virtio/virtio.c +0 -0
index 15ee3a7..a4ebf8c 100644
@@ -472,6 +472,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
         }

hw/virtio/virtio.c static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove · line 482

Quoted 10 lines
hw/virtio/virtio.c +5 -0
 
         iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
+        if (!iov[num_sg].iov_base) {
+            error_report("virtio: bogus descriptor or out of resources");
+            exit(1);
+        }
+
         iov[num_sg].iov_len = len;
         addr[num_sg] = pa;
 
Reviewed-by on v3 1/1
#2 lore raw
In reply to P J P
Quoted 7 lines · P J P

From: Prasad J Pandit <[email protected]>

virtio back end uses set of buffers to facilitate I/O operations. If its size is too large, 'cpu_physical_memory_map' could return a null address. This would result in a null dereference while un-mapping descriptors. Add check to avoid it.

Quoted 8 lines
---
 hw/virtio/virtio.c | 5 +++++
 1 file changed, 5 insertions(+)

Update per:
-> https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg04329.html