1 From f1344659fd93ea0dfb9d8d1af25993e57584c773 Mon Sep 17 00:00:00 2001
2 From: "Michael S. Tsirkin" <mst@redhat.com>
3 Date: Thu, 3 Apr 2014 19:51:53 +0300
4 Subject: [PATCH] virtio: validate num_sg when mapping
9 Both virtio-block and virtio-serial read,
10 VirtQueueElements are read in as buffers, and passed to
11 virtqueue_map_sg(), where num_sg is taken from the wire and can force
12 writes to indicies beyond VIRTQUEUE_MAX_SIZE.
14 To fix, validate num_sg.
16 Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com>
17 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
18 Cc: Amit Shah <amit.shah@redhat.com>
19 Signed-off-by: Juan Quintela <quintela@redhat.com>
20 (cherry picked from commit 36cf2a37132c7f01fa9adb5f95f5312b27742fd4)
22 hw/virtio/virtio.c | 6 ++++++
23 1 file changed, 6 insertions(+)
25 diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
26 index 0072542..a70169a 100644
27 --- a/hw/virtio/virtio.c
28 +++ b/hw/virtio/virtio.c
29 @@ -430,6 +430,12 @@ void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
33 + if (num_sg >= VIRTQUEUE_MAX_SIZE) {
34 + error_report("virtio: map attempt out of bounds: %zd > %d",
35 + num_sg, VIRTQUEUE_MAX_SIZE);
39 for (i = 0; i < num_sg; i++) {
41 sg[i].iov_base = cpu_physical_memory_map(addr[i], &len, is_write);