fix various CVEs
[pve-qemu-kvm.git] / debian / patches / extra / 0004-vmsvga-move-fifo-sanity-checks-to-vmsvga_fifo_length.patch
blob8182db18ebb96d891ef548b43856500f93e57313
1 From 4aa79a8818711d475bd79b906cd7d060d4e8a441 Mon Sep 17 00:00:00 2001
2 From: Gerd Hoffmann <kraxel@redhat.com>
3 Date: Mon, 30 May 2016 09:09:18 +0200
4 Subject: [PATCH 4/9] vmsvga: move fifo sanity checks to vmsvga_fifo_length
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Sanity checks are applied when the fifo is enabled by the guest
10 (SVGA_REG_CONFIG_DONE write). Which doesn't help much if the guest
11 changes the fifo registers afterwards. Move the checks to
12 vmsvga_fifo_length so they are done each time qemu is about to read
13 from the fifo.
15 Fixes: CVE-2016-4454
16 Cc: P J P <ppandit@redhat.com>
17 Reported-by: 李强 <liqiang6-s@360.cn>
18 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
19 ---
20 hw/display/vmware_vga.c | 28 +++++++++++++++-------------
21 1 file changed, 15 insertions(+), 13 deletions(-)
23 diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
24 index 9354037..3ce1717 100644
25 --- a/hw/display/vmware_vga.c
26 +++ b/hw/display/vmware_vga.c
27 @@ -553,6 +553,21 @@ static inline int vmsvga_fifo_length(struct vmsvga_state_s *s)
28 if (!s->config || !s->enable) {
29 return 0;
32 + /* Check range and alignment. */
33 + if ((CMD(min) | CMD(max) | CMD(next_cmd) | CMD(stop)) & 3) {
34 + return 0;
35 + }
36 + if (CMD(min) < (uint8_t *) s->cmd->fifo - (uint8_t *) s->fifo) {
37 + return 0;
38 + }
39 + if (CMD(max) > SVGA_FIFO_SIZE) {
40 + return 0;
41 + }
42 + if (CMD(max) < CMD(min) + 10 * 1024) {
43 + return 0;
44 + }
46 num = CMD(next_cmd) - CMD(stop);
47 if (num < 0) {
48 num += CMD(max) - CMD(min);
49 @@ -1003,19 +1018,6 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)
50 case SVGA_REG_CONFIG_DONE:
51 if (value) {
52 s->fifo = (uint32_t *) s->fifo_ptr;
53 - /* Check range and alignment. */
54 - if ((CMD(min) | CMD(max) | CMD(next_cmd) | CMD(stop)) & 3) {
55 - break;
56 - }
57 - if (CMD(min) < (uint8_t *) s->cmd->fifo - (uint8_t *) s->fifo) {
58 - break;
59 - }
60 - if (CMD(max) > SVGA_FIFO_SIZE) {
61 - break;
62 - }
63 - if (CMD(max) < CMD(min) + 10 * 1024) {
64 - break;
65 - }
66 vga_dirty_log_stop(&s->vga);
68 s->config = !!value;
69 --
70 2.1.4