* [Qemu-devel] [PATCH v2] cirrus_vga: fix off-by-one in blit_region_is_unsafe
@ 2016-02-10 16:17 Paolo Bonzini
2016-02-10 16:54 ` Laszlo Ersek
2016-02-16 13:30 ` Gerd Hoffmann
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2016-02-10 16:17 UTC (permalink / raw)
To: qemu-devel; +Cc: lersek, Gerd Hoffmann
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 <kraxel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
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;
}
}
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] cirrus_vga: fix off-by-one in blit_region_is_unsafe
2016-02-10 16:17 [Qemu-devel] [PATCH v2] cirrus_vga: fix off-by-one in blit_region_is_unsafe Paolo Bonzini
@ 2016-02-10 16:54 ` Laszlo Ersek
2016-02-16 13:30 ` Gerd Hoffmann
1 sibling, 0 replies; 3+ messages in thread
From: Laszlo Ersek @ 2016-02-10 16:54 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +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 <kraxel@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> 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 <lersek@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] cirrus_vga: fix off-by-one in blit_region_is_unsafe
2016-02-10 16:17 [Qemu-devel] [PATCH v2] cirrus_vga: fix off-by-one in blit_region_is_unsafe Paolo Bonzini
2016-02-10 16:54 ` Laszlo Ersek
@ 2016-02-16 13:30 ` Gerd Hoffmann
1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2016-02-16 13:30 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: lersek, qemu-devel
On Mi, 2016-02-10 at 17:17 +0100, 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.
added to vga queue.
thanks,
Gerd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-16 13:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-10 16:17 [Qemu-devel] [PATCH v2] cirrus_vga: fix off-by-one in blit_region_is_unsafe Paolo Bonzini
2016-02-10 16:54 ` Laszlo Ersek
2016-02-16 13:30 ` Gerd Hoffmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).