Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Khp1B-00035D-UA for qemu-devel@nongnu.org; Mon, 22 Sep 2008 13:16:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Khp1A-000351-Da for qemu-devel@nongnu.org; Mon, 22 Sep 2008 13:16:12 -0400 Received: from [199.232.76.173] (port=58992 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Khp1A-00034y-5r for qemu-devel@nongnu.org; Mon, 22 Sep 2008 13:16:12 -0400 Received: from mail.gondor.com ([212.117.64.182]:4355 helo=moria.gondor.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Khp18-0002HW-Js for qemu-devel@nongnu.org; Mon, 22 Sep 2008 13:16:10 -0400 Date: Mon, 22 Sep 2008 19:16:05 +0200 From: Jan Niehusmann Message-ID: <20080922171558.GA11353@x61s.gondor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [Patch] Segfault with -vnc option Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kvm@vger.kernel.org Hi! I observed a reproducible segmentation fault of kvm under the following conditions: - start kvm with -vnc option, using cirrus vga (default) - connect to the vnc console - boot windows xp - login - screen resolutions 1024x768 - change to qemu monitor (ctrl-alt-2) - wait for the windows screensaver to kick in Here is the stack trace of the segmentation fault: (gdb) info stack #0 0xb7cc4573 in memmove () from /lib/i686/cmov/libc.so.6 #1 0x080db22a in vnc_copy (ds=0x81d0b20, src_x=50, src_y=50, dst_x=195, dst_y=576, w=275, h=174) at vnc.c:477 #2 0x080b2626 in cirrus_bitblt_start (s=0x86eb1e4) at /tmp/kvm-72+dfsg/qemu/hw/cirrus_vga.c:780 #3 0x080b29e5 in cirrus_hook_write_gr (s=0x86eb1e4, reg_index=0, reg_value=275) at /tmp/kvm-72+dfsg/qemu/hw/cirrus_vga.c:1091 #4 0x080fe885 in cpu_physical_memory_rw (addr=753728, buf=0x5a408028
, len=1, is_write=1) at /tmp/kvm-72+dfsg/qemu/exec.c:2800 #5 0x08159eae in kvm_mmio_write (opaque=0x0, addr=753728, data=0x5a408028
, len=1) at /tmp/kvm-72+dfsg/qemu/qemu-kvm.c:690 #6 0x0818d30b in handle_mmio (kvm=0x83ec028, kvm_run=0x5a408000) at libkvm.c:849 #7 0x0818d820 in kvm_run (kvm=0x83ec028, vcpu=0) at libkvm.c:975 #8 0x0815a680 in kvm_cpu_exec (env=0x84da9b0) at /tmp/kvm-72+dfsg/qemu/qemu-kvm.c:218 #9 0x0815a980 in ap_main_loop (_env=0x84da9b0) at /tmp/kvm-72+dfsg/qemu/qemu-kvm.c:407 #10 0xb7e964c0 in start_thread () from /lib/i686/cmov/libpthread.so.0 #11 0xb7d2d55e in clone () from /lib/i686/cmov/libc.so.6 The cause is that the default windows screensaver uses bitblt to move the windows logo around, and cirrus_bitblt_start does call vnc_copy with parameters suitable for the VGA mode the virtual VGA card uses. But vnc_copy uses the currently active console, which is a text console with a resolution of 800x600: (gdb) up #1 0x080db22a in vnc_copy (ds=0x81d0b20, src_x=50, src_y=50, dst_x=195, dst_y=576, w=275, h=174) at vnc.c:477 477 memmove(old_row, src_row, w * vs->depth); As you can see, dst_y + h = 750 > 600. As vnc_copy doesn't check these parameters, a segmentation fault occurs. I think it's quite easy to prevent this behaviour: If we are not on the graphics console, just skip the vnc_copy. This patch assumes that there is only one graphic console. This is, of course, the usual case - but I'm not sure if this is guaranteed in every case. Regards, Jan Signed-off-by: Jan Niehusmann --- qemu/vnc.c.orig 2008-09-22 18:38:08.000000000 +0200 +++ qemu/vnc.c 2008-09-22 18:39:13.000000000 +0200 @@ -457,6 +457,9 @@ int pitch = ds->linesize; VncState *vs = ds->opaque; + /* Skip copy when on text console */ + if(!is_graphic_console()) return; + vnc_update_client(vs); if (dst_y > src_y) {