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: 824078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3yBVxP6PGLz9t5Q for ; Wed, 11 Oct 2017 08:44:09 +1100 (AEDT) Received: from localhost ([::1]:37282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e22Jr-00007N-UN for incoming@patchwork.ozlabs.org; Tue, 10 Oct 2017 17:44:07 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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); } /***************************************