Blame SOURCES/kvm-cirrus-fix-oob-access-in-mode4and5-write-functions.patch

9bac43
From 63d5677cbe031c52b37af8d123c27fdcb0f73af3 Mon Sep 17 00:00:00 2001
9bac43
From: Gerd Hoffmann <kraxel@redhat.com>
9bac43
Date: Fri, 20 Oct 2017 07:19:25 +0200
9bac43
Subject: [PATCH 03/19] cirrus: fix oob access in mode4and5 write functions
9bac43
9bac43
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
9bac43
Message-id: <20171020071925.9483-5-kraxel@redhat.com>
9bac43
Patchwork-id: 77392
9bac43
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 4/4] cirrus: fix oob access in mode4and5 write functions
9bac43
Bugzilla: 1501301
9bac43
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
9bac43
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
9bac43
9bac43
Move dst calculation into the loop, so we apply the mask on each
9bac43
interation and will not overflow vga memory.
9bac43
9bac43
Cc: Prasad J Pandit <pjp@fedoraproject.org>
9bac43
Reported-by: Niu Guoxiang <niuguoxiang@huawei.com>
9bac43
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9bac43
Message-id: 20171011084314.21752-1-kraxel@redhat.com
9bac43
(cherry picked from commit eb38e1bc3740725ca29a535351de94107ec58d51)
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 hw/display/cirrus_vga.c | 6 ++----
9bac43
 1 file changed, 2 insertions(+), 4 deletions(-)
9bac43
9bac43
diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c
9bac43
index 15322b5..e53c6f2 100644
9bac43
--- a/hw/display/cirrus_vga.c
9bac43
+++ b/hw/display/cirrus_vga.c
9bac43
@@ -2038,15 +2038,14 @@ static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState * s,
9bac43
     unsigned val = mem_value;
9bac43
     uint8_t *dst;
9bac43
 
9bac43
-    dst = s->vga.vram_ptr + (offset &= s->cirrus_addr_mask);
9bac43
     for (x = 0; x < 8; x++) {
9bac43
+        dst = s->vga.vram_ptr + ((offset + x) & s->cirrus_addr_mask);
9bac43
 	if (val & 0x80) {
9bac43
 	    *dst = s->cirrus_shadow_gr1;
9bac43
 	} else if (mode == 5) {
9bac43
 	    *dst = s->cirrus_shadow_gr0;
9bac43
 	}
9bac43
 	val <<= 1;
9bac43
-	dst++;
9bac43
     }
9bac43
     memory_region_set_dirty(&s->vga.vram, offset, 8);
9bac43
 }
9bac43
@@ -2060,8 +2059,8 @@ static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState * s,
9bac43
     unsigned val = mem_value;
9bac43
     uint8_t *dst;
9bac43
 
9bac43
-    dst = s->vga.vram_ptr + (offset &= s->cirrus_addr_mask);
9bac43
     for (x = 0; x < 8; x++) {
9bac43
+        dst = s->vga.vram_ptr + ((offset + 2 * x) & s->cirrus_addr_mask & ~1);
9bac43
 	if (val & 0x80) {
9bac43
 	    *dst = s->cirrus_shadow_gr1;
9bac43
 	    *(dst + 1) = s->vga.gr[0x11];
9bac43
@@ -2070,7 +2069,6 @@ static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState * s,
9bac43
 	    *(dst + 1) = s->vga.gr[0x10];
9bac43
 	}
9bac43
 	val <<= 1;
9bac43
-	dst += 2;
9bac43
     }
9bac43
     memory_region_set_dirty(&s->vga.vram, offset, 16);
9bac43
 }
9bac43
-- 
9bac43
1.8.3.1
9bac43