From: Michael S. Tsirkin Date: Thu, 3 Apr 2014 16:51:53 +0000 (+0300) Subject: virtio: validate num_sg when mapping X-Git-Tag: v1.7.2~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68801b7be1ddabe3495f68145b1202049b1486c2;p=thirdparty%2Fqemu.git virtio: validate num_sg when mapping CVE-2013-4535 CVE-2013-4536 Both virtio-block and virtio-serial read, VirtQueueElements are read in as buffers, and passed to virtqueue_map_sg(), where num_sg is taken from the wire and can force writes to indicies beyond VIRTQUEUE_MAX_SIZE. To fix, validate num_sg. Reported-by: Michael Roth Signed-off-by: Michael S. Tsirkin Cc: Amit Shah Signed-off-by: Juan Quintela (cherry picked from commit 36cf2a37132c7f01fa9adb5f95f5312b27742fd4) Signed-off-by: Michael Roth --- diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 705fad9166d..c2c9b5a1ab8 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -427,6 +427,12 @@ void virtqueue_map_sg(struct iovec *sg, hwaddr *addr, unsigned int i; hwaddr len; + if (num_sg >= VIRTQUEUE_MAX_SIZE) { + error_report("virtio: map attempt out of bounds: %zd > %d", + num_sg, VIRTQUEUE_MAX_SIZE); + exit(1); + } + for (i = 0; i < num_sg; i++) { len = sg[i].iov_len; sg[i].iov_base = cpu_physical_memory_map(addr[i], &len, is_write);