From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTY1n-0004AO-US for qemu-devel@nongnu.org; Wed, 10 Feb 2016 11:54:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTY1i-0001Ph-Ul for qemu-devel@nongnu.org; Wed, 10 Feb 2016 11:54:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTY1i-0001Pd-PZ for qemu-devel@nongnu.org; Wed, 10 Feb 2016 11:54:02 -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 4BBE5C00126D for ; Wed, 10 Feb 2016 16:54:02 +0000 (UTC) References: <1455121059-18280-1-git-send-email-pbonzini@redhat.com> From: Laszlo Ersek Message-ID: <56BB6B28.9030605@redhat.com> Date: Wed, 10 Feb 2016 17:54:00 +0100 MIME-Version: 1.0 In-Reply-To: <1455121059-18280-1-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] cirrus_vga: fix off-by-one in blit_region_is_unsafe List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: Gerd Hoffmann On 02/10/16 17:17, Paolo Bonzini wrote: > 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 > --- > 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; > } > } > Thank you for your patience. :) Reviewed-by: Laszlo Ersek