Blame SOURCES/kvm-vga-stop-passing-pointers-to-vga_draw_line-functions.patch

4a2fec
From 26b9a8ca080307b0d01799f96f944fb32e1619f0 Mon Sep 17 00:00:00 2001
4a2fec
From: Gerd Hoffmann <kraxel@redhat.com>
4a2fec
Date: Thu, 5 Oct 2017 09:11:41 +0200
4a2fec
Subject: [PATCH 10/34] vga: stop passing pointers to vga_draw_line* functions
4a2fec
4a2fec
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
4a2fec
Message-id: <20171005091141.30358-2-kraxel@redhat.com>
4a2fec
Patchwork-id: 76814
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 1/1] vga: stop passing pointers to vga_draw_line* functions
4a2fec
Bugzilla: 1486643
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
Instead pass around the address (aka offset into vga memory).
4a2fec
Add vga_read_* helper functions which apply vbe_size_mask to
4a2fec
the address, to make sure the address stays within the valid
4a2fec
range, similar to the cirrus blitter fixes (commits ffaf857778
4a2fec
and 026aeffcb4).
4a2fec
4a2fec
Impact:  DoS for privileged guest users.  qemu crashes with
4a2fec
a segfault, when hitting the guard page after vga memory
4a2fec
allocation, while reading vga memory for display updates.
4a2fec
4a2fec
Fixes: CVE-2017-13672
4a2fec
Cc: P J P <ppandit@redhat.com>
4a2fec
Reported-by: David Buchanan <d@vidbuchanan.co.uk>
4a2fec
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
4a2fec
Message-id: 20170828122906.18993-1-kraxel@redhat.com
4a2fec
(cherry picked from commit 3d90c6254863693a6b13d918d2b8682e08bbc681)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/display/vga-helpers.h | 202 ++++++++++++++++++++++++++---------------------
4a2fec
 hw/display/vga.c         |   5 +-
4a2fec
 hw/display/vga_int.h     |   1 +
4a2fec
 3 files changed, 114 insertions(+), 94 deletions(-)
4a2fec
4a2fec
diff --git a/hw/display/vga-helpers.h b/hw/display/vga-helpers.h
4a2fec
index 94f6de2..5a752b3 100644
4a2fec
--- a/hw/display/vga-helpers.h
4a2fec
+++ b/hw/display/vga-helpers.h
4a2fec
@@ -95,20 +95,46 @@ static void vga_draw_glyph9(uint8_t *d, int linesize,
4a2fec
     } while (--h);
4a2fec
 }
4a2fec
 
4a2fec
+static inline uint8_t vga_read_byte(VGACommonState *vga, uint32_t addr)
4a2fec
+{
4a2fec
+    return vga->vram_ptr[addr & vga->vbe_size_mask];
4a2fec
+}
4a2fec
+
4a2fec
+static inline uint16_t vga_read_word_le(VGACommonState *vga, uint32_t addr)
4a2fec
+{
4a2fec
+    uint32_t offset = addr & vga->vbe_size_mask & ~1;
4a2fec
+    uint16_t *ptr = (uint16_t *)(vga->vram_ptr + offset);
4a2fec
+    return lduw_le_p(ptr);
4a2fec
+}
4a2fec
+
4a2fec
+static inline uint16_t vga_read_word_be(VGACommonState *vga, uint32_t addr)
4a2fec
+{
4a2fec
+    uint32_t offset = addr & vga->vbe_size_mask & ~1;
4a2fec
+    uint16_t *ptr = (uint16_t *)(vga->vram_ptr + offset);
4a2fec
+    return lduw_be_p(ptr);
4a2fec
+}
4a2fec
+
4a2fec
+static inline uint32_t vga_read_dword_le(VGACommonState *vga, uint32_t addr)
4a2fec
+{
4a2fec
+    uint32_t offset = addr & vga->vbe_size_mask & ~3;
4a2fec
+    uint32_t *ptr = (uint32_t *)(vga->vram_ptr + offset);
4a2fec
+    return ldl_le_p(ptr);
4a2fec
+}
4a2fec
+
4a2fec
 /*
4a2fec
  * 4 color mode
4a2fec
  */
4a2fec
-static void vga_draw_line2(VGACommonState *s1, uint8_t *d,
4a2fec
-                           const uint8_t *s, int width)
4a2fec
+static void vga_draw_line2(VGACommonState *vga, uint8_t *d,
4a2fec
+                           uint32_t addr, int width)
4a2fec
 {
4a2fec
     uint32_t plane_mask, *palette, data, v;
4a2fec
     int x;
4a2fec
 
4a2fec
-    palette = s1->last_palette;
4a2fec
-    plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
4a2fec
+    palette = vga->last_palette;
4a2fec
+    plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
4a2fec
     width >>= 3;
4a2fec
     for(x = 0; x < width; x++) {
4a2fec
-        data = ((uint32_t *)s)[0];
4a2fec
+        data = vga_read_dword_le(vga, addr);
4a2fec
         data &= plane_mask;
4a2fec
         v = expand2[GET_PLANE(data, 0)];
4a2fec
         v |= expand2[GET_PLANE(data, 2)] << 2;
4a2fec
@@ -124,7 +150,7 @@ static void vga_draw_line2(VGACommonState *s1, uint8_t *d,
4a2fec
         ((uint32_t *)d)[6] = palette[(v >> 4) & 0xf];
4a2fec
         ((uint32_t *)d)[7] = palette[(v >> 0) & 0xf];
4a2fec
         d += 32;
4a2fec
-        s += 4;
4a2fec
+        addr += 4;
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
@@ -134,17 +160,17 @@ static void vga_draw_line2(VGACommonState *s1, uint8_t *d,
4a2fec
 /*
4a2fec
  * 4 color mode, dup2 horizontal
4a2fec
  */
4a2fec
-static void vga_draw_line2d2(VGACommonState *s1, uint8_t *d,
4a2fec
-                             const uint8_t *s, int width)
4a2fec
+static void vga_draw_line2d2(VGACommonState *vga, uint8_t *d,
4a2fec
+                             uint32_t addr, int width)
4a2fec
 {
4a2fec
     uint32_t plane_mask, *palette, data, v;
4a2fec
     int x;
4a2fec
 
4a2fec
-    palette = s1->last_palette;
4a2fec
-    plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
4a2fec
+    palette = vga->last_palette;
4a2fec
+    plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
4a2fec
     width >>= 3;
4a2fec
     for(x = 0; x < width; x++) {
4a2fec
-        data = ((uint32_t *)s)[0];
4a2fec
+        data = vga_read_dword_le(vga, addr);
4a2fec
         data &= plane_mask;
4a2fec
         v = expand2[GET_PLANE(data, 0)];
4a2fec
         v |= expand2[GET_PLANE(data, 2)] << 2;
4a2fec
@@ -160,24 +186,24 @@ static void vga_draw_line2d2(VGACommonState *s1, uint8_t *d,
4a2fec
         PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]);
4a2fec
         PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]);
4a2fec
         d += 64;
4a2fec
-        s += 4;
4a2fec
+        addr += 4;
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
 /*
4a2fec
  * 16 color mode
4a2fec
  */
4a2fec
-static void vga_draw_line4(VGACommonState *s1, uint8_t *d,
4a2fec
-                           const uint8_t *s, int width)
4a2fec
+static void vga_draw_line4(VGACommonState *vga, uint8_t *d,
4a2fec
+                           uint32_t addr, int width)
4a2fec
 {
4a2fec
     uint32_t plane_mask, data, v, *palette;
4a2fec
     int x;
4a2fec
 
4a2fec
-    palette = s1->last_palette;
4a2fec
-    plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
4a2fec
+    palette = vga->last_palette;
4a2fec
+    plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
4a2fec
     width >>= 3;
4a2fec
     for(x = 0; x < width; x++) {
4a2fec
-        data = ((uint32_t *)s)[0];
4a2fec
+        data = vga_read_dword_le(vga, addr);
4a2fec
         data &= plane_mask;
4a2fec
         v = expand4[GET_PLANE(data, 0)];
4a2fec
         v |= expand4[GET_PLANE(data, 1)] << 1;
4a2fec
@@ -192,24 +218,24 @@ static void vga_draw_line4(VGACommonState *s1, uint8_t *d,
4a2fec
         ((uint32_t *)d)[6] = palette[(v >> 4) & 0xf];
4a2fec
         ((uint32_t *)d)[7] = palette[(v >> 0) & 0xf];
4a2fec
         d += 32;
4a2fec
-        s += 4;
4a2fec
+        addr += 4;
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
 /*
4a2fec
  * 16 color mode, dup2 horizontal
4a2fec
  */
4a2fec
-static void vga_draw_line4d2(VGACommonState *s1, uint8_t *d,
4a2fec
-                             const uint8_t *s, int width)
4a2fec
+static void vga_draw_line4d2(VGACommonState *vga, uint8_t *d,
4a2fec
+                             uint32_t addr, int width)
4a2fec
 {
4a2fec
     uint32_t plane_mask, data, v, *palette;
4a2fec
     int x;
4a2fec
 
4a2fec
-    palette = s1->last_palette;
4a2fec
-    plane_mask = mask16[s1->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
4a2fec
+    palette = vga->last_palette;
4a2fec
+    plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
4a2fec
     width >>= 3;
4a2fec
     for(x = 0; x < width; x++) {
4a2fec
-        data = ((uint32_t *)s)[0];
4a2fec
+        data = vga_read_dword_le(vga, addr);
4a2fec
         data &= plane_mask;
4a2fec
         v = expand4[GET_PLANE(data, 0)];
4a2fec
         v |= expand4[GET_PLANE(data, 1)] << 1;
4a2fec
@@ -224,7 +250,7 @@ static void vga_draw_line4d2(VGACommonState *s1, uint8_t *d,
4a2fec
         PUT_PIXEL2(d, 6, palette[(v >> 4) & 0xf]);
4a2fec
         PUT_PIXEL2(d, 7, palette[(v >> 0) & 0xf]);
4a2fec
         d += 64;
4a2fec
-        s += 4;
4a2fec
+        addr += 4;
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
@@ -233,21 +259,21 @@ static void vga_draw_line4d2(VGACommonState *s1, uint8_t *d,
4a2fec
  *
4a2fec
  * XXX: add plane_mask support (never used in standard VGA modes)
4a2fec
  */
4a2fec
-static void vga_draw_line8d2(VGACommonState *s1, uint8_t *d,
4a2fec
-                             const uint8_t *s, int width)
4a2fec
+static void vga_draw_line8d2(VGACommonState *vga, uint8_t *d,
4a2fec
+                             uint32_t addr, int width)
4a2fec
 {
4a2fec
     uint32_t *palette;
4a2fec
     int x;
4a2fec
 
4a2fec
-    palette = s1->last_palette;
4a2fec
+    palette = vga->last_palette;
4a2fec
     width >>= 3;
4a2fec
     for(x = 0; x < width; x++) {
4a2fec
-        PUT_PIXEL2(d, 0, palette[s[0]]);
4a2fec
-        PUT_PIXEL2(d, 1, palette[s[1]]);
4a2fec
-        PUT_PIXEL2(d, 2, palette[s[2]]);
4a2fec
-        PUT_PIXEL2(d, 3, palette[s[3]]);
4a2fec
+        PUT_PIXEL2(d, 0, palette[vga_read_byte(vga, addr + 0)]);
4a2fec
+        PUT_PIXEL2(d, 1, palette[vga_read_byte(vga, addr + 1)]);
4a2fec
+        PUT_PIXEL2(d, 2, palette[vga_read_byte(vga, addr + 2)]);
4a2fec
+        PUT_PIXEL2(d, 3, palette[vga_read_byte(vga, addr + 3)]);
4a2fec
         d += 32;
4a2fec
-        s += 4;
4a2fec
+        addr += 4;
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
@@ -256,63 +282,63 @@ static void vga_draw_line8d2(VGACommonState *s1, uint8_t *d,
4a2fec
  *
4a2fec
  * XXX: add plane_mask support (never used in standard VGA modes)
4a2fec
  */
4a2fec
-static void vga_draw_line8(VGACommonState *s1, uint8_t *d,
4a2fec
-                           const uint8_t *s, int width)
4a2fec
+static void vga_draw_line8(VGACommonState *vga, uint8_t *d,
4a2fec
+                           uint32_t addr, int width)
4a2fec
 {
4a2fec
     uint32_t *palette;
4a2fec
     int x;
4a2fec
 
4a2fec
-    palette = s1->last_palette;
4a2fec
+    palette = vga->last_palette;
4a2fec
     width >>= 3;
4a2fec
     for(x = 0; x < width; x++) {
4a2fec
-        ((uint32_t *)d)[0] = palette[s[0]];
4a2fec
-        ((uint32_t *)d)[1] = palette[s[1]];
4a2fec
-        ((uint32_t *)d)[2] = palette[s[2]];
4a2fec
-        ((uint32_t *)d)[3] = palette[s[3]];
4a2fec
-        ((uint32_t *)d)[4] = palette[s[4]];
4a2fec
-        ((uint32_t *)d)[5] = palette[s[5]];
4a2fec
-        ((uint32_t *)d)[6] = palette[s[6]];
4a2fec
-        ((uint32_t *)d)[7] = palette[s[7]];
4a2fec
+        ((uint32_t *)d)[0] = palette[vga_read_byte(vga, addr + 0)];
4a2fec
+        ((uint32_t *)d)[1] = palette[vga_read_byte(vga, addr + 1)];
4a2fec
+        ((uint32_t *)d)[2] = palette[vga_read_byte(vga, addr + 2)];
4a2fec
+        ((uint32_t *)d)[3] = palette[vga_read_byte(vga, addr + 3)];
4a2fec
+        ((uint32_t *)d)[4] = palette[vga_read_byte(vga, addr + 4)];
4a2fec
+        ((uint32_t *)d)[5] = palette[vga_read_byte(vga, addr + 5)];
4a2fec
+        ((uint32_t *)d)[6] = palette[vga_read_byte(vga, addr + 6)];
4a2fec
+        ((uint32_t *)d)[7] = palette[vga_read_byte(vga, addr + 7)];
4a2fec
         d += 32;
4a2fec
-        s += 8;
4a2fec
+        addr += 8;
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
 /*
4a2fec
  * 15 bit color
4a2fec
  */
4a2fec
-static void vga_draw_line15_le(VGACommonState *s1, uint8_t *d,
4a2fec
-                               const uint8_t *s, int width)
4a2fec
+static void vga_draw_line15_le(VGACommonState *vga, uint8_t *d,
4a2fec
+                               uint32_t addr, int width)
4a2fec
 {
4a2fec
     int w;
4a2fec
     uint32_t v, r, g, b;
4a2fec
 
4a2fec
     w = width;
4a2fec
     do {
4a2fec
-        v = lduw_le_p((void *)s);
4a2fec
+        v = vga_read_word_le(vga, addr);
4a2fec
         r = (v >> 7) & 0xf8;
4a2fec
         g = (v >> 2) & 0xf8;
4a2fec
         b = (v << 3) & 0xf8;
4a2fec
         ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
4a2fec
-        s += 2;
4a2fec
+        addr += 2;
4a2fec
         d += 4;
4a2fec
     } while (--w != 0);
4a2fec
 }
4a2fec
 
4a2fec
-static void vga_draw_line15_be(VGACommonState *s1, uint8_t *d,
4a2fec
-                               const uint8_t *s, int width)
4a2fec
+static void vga_draw_line15_be(VGACommonState *vga, uint8_t *d,
4a2fec
+                               uint32_t addr, int width)
4a2fec
 {
4a2fec
     int w;
4a2fec
     uint32_t v, r, g, b;
4a2fec
 
4a2fec
     w = width;
4a2fec
     do {
4a2fec
-        v = lduw_be_p((void *)s);
4a2fec
+        v = vga_read_word_be(vga, addr);
4a2fec
         r = (v >> 7) & 0xf8;
4a2fec
         g = (v >> 2) & 0xf8;
4a2fec
         b = (v << 3) & 0xf8;
4a2fec
         ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
4a2fec
-        s += 2;
4a2fec
+        addr += 2;
4a2fec
         d += 4;
4a2fec
     } while (--w != 0);
4a2fec
 }
4a2fec
@@ -320,38 +346,38 @@ static void vga_draw_line15_be(VGACommonState *s1, uint8_t *d,
4a2fec
 /*
4a2fec
  * 16 bit color
4a2fec
  */
4a2fec
-static void vga_draw_line16_le(VGACommonState *s1, uint8_t *d,
4a2fec
-                               const uint8_t *s, int width)
4a2fec
+static void vga_draw_line16_le(VGACommonState *vga, uint8_t *d,
4a2fec
+                               uint32_t addr, int width)
4a2fec
 {
4a2fec
     int w;
4a2fec
     uint32_t v, r, g, b;
4a2fec
 
4a2fec
     w = width;
4a2fec
     do {
4a2fec
-        v = lduw_le_p((void *)s);
4a2fec
+        v = vga_read_word_le(vga, addr);
4a2fec
         r = (v >> 8) & 0xf8;
4a2fec
         g = (v >> 3) & 0xfc;
4a2fec
         b = (v << 3) & 0xf8;
4a2fec
         ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
4a2fec
-        s += 2;
4a2fec
+        addr += 2;
4a2fec
         d += 4;
4a2fec
     } while (--w != 0);
4a2fec
 }
4a2fec
 
4a2fec
-static void vga_draw_line16_be(VGACommonState *s1, uint8_t *d,
4a2fec
-                               const uint8_t *s, int width)
4a2fec
+static void vga_draw_line16_be(VGACommonState *vga, uint8_t *d,
4a2fec
+                               uint32_t addr, int width)
4a2fec
 {
4a2fec
     int w;
4a2fec
     uint32_t v, r, g, b;
4a2fec
 
4a2fec
     w = width;
4a2fec
     do {
4a2fec
-        v = lduw_be_p((void *)s);
4a2fec
+        v = vga_read_word_be(vga, addr);
4a2fec
         r = (v >> 8) & 0xf8;
4a2fec
         g = (v >> 3) & 0xfc;
4a2fec
         b = (v << 3) & 0xf8;
4a2fec
         ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
4a2fec
-        s += 2;
4a2fec
+        addr += 2;
4a2fec
         d += 4;
4a2fec
     } while (--w != 0);
4a2fec
 }
4a2fec
@@ -359,36 +385,36 @@ static void vga_draw_line16_be(VGACommonState *s1, uint8_t *d,
4a2fec
 /*
4a2fec
  * 24 bit color
4a2fec
  */
4a2fec
-static void vga_draw_line24_le(VGACommonState *s1, uint8_t *d,
4a2fec
-                               const uint8_t *s, int width)
4a2fec
+static void vga_draw_line24_le(VGACommonState *vga, uint8_t *d,
4a2fec
+                               uint32_t addr, int width)
4a2fec
 {
4a2fec
     int w;
4a2fec
     uint32_t r, g, b;
4a2fec
 
4a2fec
     w = width;
4a2fec
     do {
4a2fec
-        b = s[0];
4a2fec
-        g = s[1];
4a2fec
-        r = s[2];
4a2fec
+        b = vga_read_byte(vga, addr + 0);
4a2fec
+        g = vga_read_byte(vga, addr + 1);
4a2fec
+        r = vga_read_byte(vga, addr + 2);
4a2fec
         ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
4a2fec
-        s += 3;
4a2fec
+        addr += 3;
4a2fec
         d += 4;
4a2fec
     } while (--w != 0);
4a2fec
 }
4a2fec
 
4a2fec
-static void vga_draw_line24_be(VGACommonState *s1, uint8_t *d,
4a2fec
-                               const uint8_t *s, int width)
4a2fec
+static void vga_draw_line24_be(VGACommonState *vga, uint8_t *d,
4a2fec
+                               uint32_t addr, int width)
4a2fec
 {
4a2fec
     int w;
4a2fec
     uint32_t r, g, b;
4a2fec
 
4a2fec
     w = width;
4a2fec
     do {
4a2fec
-        r = s[0];
4a2fec
-        g = s[1];
4a2fec
-        b = s[2];
4a2fec
+        r = vga_read_byte(vga, addr + 0);
4a2fec
+        g = vga_read_byte(vga, addr + 1);
4a2fec
+        b = vga_read_byte(vga, addr + 2);
4a2fec
         ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
4a2fec
-        s += 3;
4a2fec
+        addr += 3;
4a2fec
         d += 4;
4a2fec
     } while (--w != 0);
4a2fec
 }
4a2fec
@@ -396,44 +422,36 @@ static void vga_draw_line24_be(VGACommonState *s1, uint8_t *d,
4a2fec
 /*
4a2fec
  * 32 bit color
4a2fec
  */
4a2fec
-static void vga_draw_line32_le(VGACommonState *s1, uint8_t *d,
4a2fec
-                               const uint8_t *s, int width)
4a2fec
+static void vga_draw_line32_le(VGACommonState *vga, uint8_t *d,
4a2fec
+                               uint32_t addr, int width)
4a2fec
 {
4a2fec
-#ifndef HOST_WORDS_BIGENDIAN
4a2fec
-    memcpy(d, s, width * 4);
4a2fec
-#else
4a2fec
     int w;
4a2fec
     uint32_t r, g, b;
4a2fec
 
4a2fec
     w = width;
4a2fec
     do {
4a2fec
-        b = s[0];
4a2fec
-        g = s[1];
4a2fec
-        r = s[2];
4a2fec
+        b = vga_read_byte(vga, addr + 0);
4a2fec
+        g = vga_read_byte(vga, addr + 1);
4a2fec
+        r = vga_read_byte(vga, addr + 2);
4a2fec
         ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
4a2fec
-        s += 4;
4a2fec
+        addr += 4;
4a2fec
         d += 4;
4a2fec
     } while (--w != 0);
4a2fec
-#endif
4a2fec
 }
4a2fec
 
4a2fec
-static void vga_draw_line32_be(VGACommonState *s1, uint8_t *d,
4a2fec
-                               const uint8_t *s, int width)
4a2fec
+static void vga_draw_line32_be(VGACommonState *vga, uint8_t *d,
4a2fec
+                               uint32_t addr, int width)
4a2fec
 {
4a2fec
-#ifdef HOST_WORDS_BIGENDIAN
4a2fec
-    memcpy(d, s, width * 4);
4a2fec
-#else
4a2fec
     int w;
4a2fec
     uint32_t r, g, b;
4a2fec
 
4a2fec
     w = width;
4a2fec
     do {
4a2fec
-        r = s[1];
4a2fec
-        g = s[2];
4a2fec
-        b = s[3];
4a2fec
+        r = vga_read_byte(vga, addr + 1);
4a2fec
+        g = vga_read_byte(vga, addr + 2);
4a2fec
+        b = vga_read_byte(vga, addr + 3);
4a2fec
         ((uint32_t *)d)[0] = rgb_to_pixel32(r, g, b);
4a2fec
-        s += 4;
4a2fec
+        addr += 4;
4a2fec
         d += 4;
4a2fec
     } while (--w != 0);
4a2fec
-#endif
4a2fec
 }
4a2fec
diff --git a/hw/display/vga.c b/hw/display/vga.c
4a2fec
index 63421f9..4c2ee0b 100644
4a2fec
--- a/hw/display/vga.c
4a2fec
+++ b/hw/display/vga.c
4a2fec
@@ -1005,7 +1005,7 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, uint32_t val)
4a2fec
 }
4a2fec
 
4a2fec
 typedef void vga_draw_line_func(VGACommonState *s1, uint8_t *d,
4a2fec
-                                const uint8_t *s, int width);
4a2fec
+                                uint32_t srcaddr, int width);
4a2fec
 
4a2fec
 #include "vga-helpers.h"
4a2fec
 
4a2fec
@@ -1660,7 +1660,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
4a2fec
             if (y_start < 0)
4a2fec
                 y_start = y;
4a2fec
             if (!(is_buffer_shared(surface))) {
4a2fec
-                vga_draw_line(s, d, s->vram_ptr + addr, width);
4a2fec
+                vga_draw_line(s, d, addr, width);
4a2fec
                 if (s->cursor_draw_line)
4a2fec
                     s->cursor_draw_line(s, d, y);
4a2fec
             }
4a2fec
@@ -2164,6 +2164,7 @@ void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate)
4a2fec
     if (!s->vbe_size) {
4a2fec
         s->vbe_size = s->vram_size;
4a2fec
     }
4a2fec
+    s->vbe_size_mask = s->vbe_size - 1;
4a2fec
 
4a2fec
     s->is_vbe_vmstate = 1;
4a2fec
     memory_region_init_ram_nomigrate(&s->vram, obj, "vga.vram", s->vram_size,
4a2fec
diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h
4a2fec
index dd6c958..ad34a1f 100644
4a2fec
--- a/hw/display/vga_int.h
4a2fec
+++ b/hw/display/vga_int.h
4a2fec
@@ -94,6 +94,7 @@ typedef struct VGACommonState {
4a2fec
     uint32_t vram_size;
4a2fec
     uint32_t vram_size_mb; /* property */
4a2fec
     uint32_t vbe_size;
4a2fec
+    uint32_t vbe_size_mask;
4a2fec
     uint32_t latch;
4a2fec
     bool has_chain4_alias;
4a2fec
     MemoryRegion chain4_alias;
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec