From patchwork Tue Mar 1 07:17:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 8462581 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 91FF1C0553 for ; Tue, 1 Mar 2016 07:17:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 02D48201C8 for ; Tue, 1 Mar 2016 07:17:49 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 4651520142 for ; Tue, 1 Mar 2016 07:17:48 +0000 (UTC) Received: from localhost ([::1]:41360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaeYz-0006pI-MY for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Mar 2016 02:17:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaeYr-0006oZ-C7 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 02:17:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaeYo-0003Qh-J6 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 02:17:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42506) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaeYo-0003Qd-Cq for qemu-devel@nongnu.org; Tue, 01 Mar 2016 02:17:34 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 0FD59C0006F1 for ; Tue, 1 Mar 2016 07:17:34 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u217HXbZ025740; Tue, 1 Mar 2016 02:17:33 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id C33F58087D; Tue, 1 Mar 2016 08:17:32 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 1 Mar 2016 08:17:28 +0100 Message-Id: <1456816649-4713-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1456816649-4713-1-git-send-email-kraxel@redhat.com> References: <1456816649-4713-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Gerd Hoffmann Subject: [Qemu-devel] [PULL 1/2] cirrus_vga: fix off-by-one in blit_region_is_unsafe 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini The "max" value is being compared with >=, but addr + width points to the first byte that will _not_ be copied. Laszlo suggested using a "greater than" comparison, instead of subtracting one like it is already done above for the height, so that max remains always positive. The mistake is "safe"---it will reject some blits, but will never cause out-of-bounds writes. Cc: Gerd Hoffmann Signed-off-by: Paolo Bonzini Reviewed-by: Laszlo Ersek Message-id: 1455121059-18280-1-git-send-email-pbonzini@redhat.com Signed-off-by: Gerd Hoffmann --- hw/display/cirrus_vga.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index b6ce1c8..57b91a7 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -276,14 +276,14 @@ static bool blit_region_is_unsafe(struct CirrusVGAState *s, + ((int64_t)s->cirrus_blt_height-1) * pitch; int32_t max = addr + s->cirrus_blt_width; - if (min < 0 || max >= s->vga.vram_size) { + if (min < 0 || max > s->vga.vram_size) { return true; } } else { int64_t max = addr + ((int64_t)s->cirrus_blt_height-1) * pitch + s->cirrus_blt_width; - if (max >= s->vga.vram_size) { + if (max > s->vga.vram_size) { return true; } }