From patchwork Mon May 12 07:10:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 347896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 868BA14009F for ; Mon, 12 May 2014 17:11:31 +1000 (EST) Received: from localhost ([::1]:35672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjkOW-0000vH-CO for incoming@patchwork.ozlabs.org; Mon, 12 May 2014 03:11:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjkOA-0000YG-8d for qemu-devel@nongnu.org; Mon, 12 May 2014 03:11:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WjkO3-0007NU-TY for qemu-devel@nongnu.org; Mon, 12 May 2014 03:11:06 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:57450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjkO3-0007Mx-0z for qemu-devel@nongnu.org; Mon, 12 May 2014 03:10:59 -0400 Received: from 172.24.2.119 (EHLO szxeml214-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BTQ76199; Mon, 12 May 2014 15:10:53 +0800 (CST) Received: from SZXEML405-HUB.china.huawei.com (10.82.67.60) by szxeml214-edg.china.huawei.com (172.24.2.29) with Microsoft SMTP Server (TLS) id 14.3.158.1; Mon, 12 May 2014 15:10:51 +0800 Received: from localhost (10.177.19.102) by szxeml405-hub.china.huawei.com (10.82.67.60) with Microsoft SMTP Server id 14.3.158.1; Mon, 12 May 2014 15:10:41 +0800 From: To: Date: Mon, 12 May 2014 15:10:38 +0800 Message-ID: <1399878638-11292-1-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: weidong.huang@huawei.com, mst@redhat.com, mjt@tls.msk.ru, blauwirbel@gmail.com, Gonglei , kraxel@redhat.com, pbonzini@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v3] cirrus_vga: adding sanity check for vram size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei when configure a invalid vram size for cirrus card, such as less 2 MB, which will crash qemu. Follow the real hardware, the cirrus card has 4 MB video memory. Also for backward compatibility, accept 8 MB and 16 MB vram size. Signed-off-by: Gonglei Reviewed-by: Andreas Färber --- v3: - fix logic bug pointed out by Michael Tokarev - add the same restriction for ISA cirrus device, thanks Andreas v2: - fix checkpatch fails. "WARNING: suspect code indent for conditional statements (5, 9)" maybe not a real warning. hw/display/cirrus_vga.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index d1afc76..ca0d786 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -2913,6 +2913,14 @@ static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **errp) ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev); VGACommonState *s = &d->cirrus_vga.vga; + /* follow real hardware, cirrus card emulated has 4 MB video memory. + Also accept 8 MB/16 MB for backward compatibility. */ + if (s->vram_size_mb != 4 && s->vram_size_mb != 8 && + s->vram_size_mb != 16) { + error_setg(errp, "Invalid cirrus_vga ram size '%u'", + s->vram_size_mb); + return; + } vga_common_init(s, OBJECT(dev), true); cirrus_init_common(&d->cirrus_vga, OBJECT(dev), CIRRUS_ID_CLGD5430, 0, isa_address_space(isadev), @@ -2959,6 +2967,14 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev) PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); int16_t device_id = pc->device_id; + /* follow real hardware, cirrus card emulated has 4 MB video memory. + Also accept 8 MB/16 MB for backward compatibility. */ + if (s->vga.vram_size_mb != 4 && s->vga.vram_size_mb != 8 && + s->vga.vram_size_mb != 16) { + error_report("Invalid cirrus_vga ram size '%u'", + s->vga.vram_size_mb); + return -1; + } /* setup VGA */ vga_common_init(&s->vga, OBJECT(dev), true); cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev),