From patchwork Tue Oct 10 21:36:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9997973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DD434601AE for ; Tue, 10 Oct 2017 21:44:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0346286DB for ; Tue, 10 Oct 2017 21:44:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C52DC28760; Tue, 10 Oct 2017 21:44:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4F735286DB for ; Tue, 10 Oct 2017 21:44:43 +0000 (UTC) Received: from localhost ([::1]:37282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e22KQ-00007N-Bm for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Oct 2017 17:44:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e22CM-0002G1-7J for qemu-devel@nongnu.org; Tue, 10 Oct 2017 17:36:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e22CL-0001nr-8z for qemu-devel@nongnu.org; Tue, 10 Oct 2017 17:36:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36204) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e22CL-0001lA-2Q for qemu-devel@nongnu.org; Tue, 10 Oct 2017 17:36:21 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71FD025767; Tue, 10 Oct 2017 21:36:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 71FD025767 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ppandit@redhat.com Received: from localhost.localdomain (ovpn-117-99.phx2.redhat.com [10.3.117.99]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE66A1883E; Tue, 10 Oct 2017 21:36:13 +0000 (UTC) From: P J P To: Qemu Developers Date: Wed, 11 Oct 2017 03:06:08 +0530 Message-Id: <20171010213608.31567-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 10 Oct 2017 21:36:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] cirrus: keep vga vram pointer within bounds X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , Niu Guoxiang , Prasad J Pandit Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit 'dst' pointer could exceed vga vram size when writing to the cirrus memory area; it'd lead to an OOB access issue. Add check to avoid it. Reported-by: Niu Guoxiang Signed-off-by: Prasad J Pandit --- hw/display/cirrus_vga.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index afc290ab91..451a736262 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -2047,8 +2047,11 @@ static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState * s, } val <<= 1; dst++; + if (dst >= s->vga.vram_ptr + s->vga.vram_size) { + break; + } } - memory_region_set_dirty(&s->vga.vram, offset, 8); + memory_region_set_dirty(&s->vga.vram, offset, x); } static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState * s, @@ -2071,8 +2074,11 @@ static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState * s, } val <<= 1; dst += 2; + if (dst >= s->vga.vram_ptr + s->vga.vram_size) { + break; + } } - memory_region_set_dirty(&s->vga.vram, offset, 16); + memory_region_set_dirty(&s->vga.vram, offset, x<<1); } /***************************************