Blame SOURCES/kvm-vga-check-the-validation-of-memory-addr-when-draw-te.patch

4a2fec
From 3b2c6ef26bdde6363ca750008cef962076e2bf0f Mon Sep 17 00:00:00 2001
4a2fec
From: Gerd Hoffmann <kraxel@redhat.com>
4a2fec
Date: Fri, 26 Jan 2018 08:12:43 +0100
4a2fec
Subject: [PATCH 6/8] vga: check the validation of memory addr when draw text
4a2fec
4a2fec
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
4a2fec
Message-id: <20180126081243.19785-2-kraxel@redhat.com>
4a2fec
Patchwork-id: 78712
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 1/1] vga: check the validation of memory addr when draw text
4a2fec
Bugzilla: 1534682
4a2fec
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
From: linzhecheng <linzhecheng@huawei.com>
4a2fec
4a2fec
Start a vm with qemu-kvm -enable-kvm -vnc :66 -smp 1 -m 1024 -hda
4a2fec
redhat_5.11.qcow2  -device pcnet -vga cirrus,
4a2fec
then use VNC client to connect to VM, and excute the code below in guest
4a2fec
OS will lead to qemu crash:
4a2fec
4a2fec
int main()
4a2fec
 {
4a2fec
    iopl(3);
4a2fec
    srand(time(NULL));
4a2fec
    int a,b;
4a2fec
    while(1){
4a2fec
	a = rand()%0x100;
4a2fec
	b = 0x3c0 + (rand()%0x20);
4a2fec
        outb(a,b);
4a2fec
    }
4a2fec
    return 0;
4a2fec
}
4a2fec
4a2fec
The above code is writing the registers of VGA randomly.
4a2fec
We can write VGA CRT controller registers index 0x0C or 0x0D
4a2fec
(which is the start address register) to modify the
4a2fec
the display memory address of the upper left pixel
4a2fec
or character of the screen. The address may be out of the
4a2fec
range of vga ram. So we should check the validation of memory address
4a2fec
when reading or writing it to avoid segfault.
4a2fec
4a2fec
Signed-off-by: linzhecheng <linzhecheng@huawei.com>
4a2fec
Message-id: 20180111132724.13744-1-linzhecheng@huawei.com
4a2fec
Fixes: CVE-2018-5683
4a2fec
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
4a2fec
(cherry picked from commit 191f59dc17396bb5a8da50f8c59b6e0a430711a4)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/display/vga.c | 3 +++
4a2fec
 1 file changed, 3 insertions(+)
4a2fec
4a2fec
diff --git a/hw/display/vga.c b/hw/display/vga.c
4a2fec
index 06ca3da..b1cdf36 100644
4a2fec
--- a/hw/display/vga.c
4a2fec
+++ b/hw/display/vga.c
4a2fec
@@ -1280,6 +1280,9 @@ static void vga_draw_text(VGACommonState *s, int full_update)
4a2fec
         cx_min = width;
4a2fec
         cx_max = -1;
4a2fec
         for(cx = 0; cx < width; cx++) {
4a2fec
+            if (src + sizeof(uint16_t) > s->vram_ptr + s->vram_size) {
4a2fec
+                break;
4a2fec
+            }
4a2fec
             ch_attr = *(uint16_t *)src;
4a2fec
             if (full_update || ch_attr != *ch_attr_ptr || src == cursor_ptr) {
4a2fec
                 if (cx < cx_min)
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec