[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 55/56] virtio: error out if guest exceeds virtqueue
From: |
Michael Roth |
Subject: |
[Qemu-stable] [PATCH 55/56] virtio: error out if guest exceeds virtqueue size |
Date: |
Mon, 8 Aug 2016 16:04:26 -0500 |
From: Stefan Hajnoczi <address@hidden>
A broken or malicious guest can submit more requests than the virtqueue
size permits, causing unbounded memory allocation in QEMU.
The guest can submit requests without bothering to wait for completion
and is therefore not bound by virtqueue size. This requires reusing
vring descriptors in more than one request, which is not allowed by the
VIRTIO 1.0 specification.
In "3.2.1 Supplying Buffers to The Device", the VIRTIO 1.0 specification
says:
1. The driver places the buffer into free descriptor(s) in the
descriptor table, chaining as necessary
and
Note that the above code does not take precautions against the
available ring buffer wrapping around: this is not possible since the
ring buffer is the same size as the descriptor table, so step (1) will
prevent such a condition.
This implies that placing more buffers into the virtqueue than the
descriptor table size is not allowed.
QEMU is missing the check to prevent this case. Processing a request
allocates a VirtQueueElement leading to unbounded memory allocation
controlled by the guest.
Exit with an error if the guest provides more requests than the
virtqueue size permits. This bounds memory allocation and makes the
buggy guest visible to the user.
This patch fixes CVE-2016-5403 and was reported by Zhenhao Hong from 360
Marvel Team, China.
Reported-by: Zhenhao Hong <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
(cherry picked from commit afd9096eb1882f23929f5b5c177898ed231bac66)
Signed-off-by: Michael Roth <address@hidden>
---
hw/virtio/virtio.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 90f86cf..8ed260a 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -561,6 +561,11 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
max = vq->vring.num;
+ if (vq->inuse >= vq->vring.num) {
+ error_report("Virtqueue size exceeded");
+ exit(1);
+ }
+
i = head = virtqueue_get_head(vq, vq->last_avail_idx++);
if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
vring_set_avail_event(vq, vq->last_avail_idx);
--
1.9.1
- [Qemu-stable] [PATCH 42/56] virtio: set low features early on load, (continued)
- [Qemu-stable] [PATCH 42/56] virtio: set low features early on load, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 43/56] Revert "virtio-net: unbreak self announcement and guest offloads after migration", Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 47/56] util: Fix MIN_NON_ZERO, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 48/56] block/iscsi: fix rounding in iscsi_allocationmap_set, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 50/56] nbd: More debug typo fixes, use correct formats, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 04/56] tools: kvm_stat: Powerpc related fixes, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 49/56] Fix some typos found by codespell, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 52/56] nbd: Limit nbdflags to 16 bits, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 53/56] pcie: fix link active status bit migration, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 51/56] nbd: Don't use *_to_cpup() functions, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 55/56] virtio: error out if guest exceeds virtqueue size,
Michael Roth <=
- [Qemu-stable] [PATCH 54/56] target-i386: fix typo in xsetbv implementation, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 06/56] usb:xhci: no DMA on HC reset, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 56/56] ide: fix halted IO segfault at reset, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 08/56] target-i386: key sfence availability on CPUID_SSE, not CPUID_SSE2, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 07/56] target-mips: fix call to memset in soft reset code, Michael Roth, 2016/08/08
- [Qemu-stable] [PATCH 05/56] exec.c: Ensure right alignment also for file backed ram, Michael Roth, 2016/08/08
- Re: [Qemu-stable] [PATCH 00/56] Patch Round-up for stable 2.6.1, freeze on 2016-08-12, Cole Robinson, 2016/08/08
- Re: [Qemu-stable] [PATCH 00/56] Patch Round-up for stable 2.6.1, freeze on 2016-08-12, Michael Roth, 2016/08/09