From: Michael S. Tsirkin Date: Wed, 4 Mar 2015 16:44:22 +0000 (+0000) Subject: virtio: validate num_sg when mapping X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f25df9882827c8e488fe3f36cc7796b99302391b;p=qemu-upstream-4.2-testing.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 Signed-off-by: Stefano Stabellini --- diff --git a/hw/virtio.c b/hw/virtio.c index e1365a3f7..068c24dc1 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -396,6 +396,12 @@ void virtqueue_map_sg(struct iovec *sg, target_phys_addr_t *addr, unsigned int i; target_phys_addr_t 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);