From 4e2439022731ad31a93a9a27bc0728e1a57beaf5 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 10 Feb 2017 08:30:15 +0100 Subject: [PATCH 3/3] cirrus: add blit_is_unsafe call to cirrus_bitblt_cputovideo RH-Author: Gerd Hoffmann Message-id: <1486715415-3462-4-git-send-email-kraxel@redhat.com> Patchwork-id: 73773 O-Subject: [virt-devel] [EMBARGOED RHEL-7.4 qemu-kvm PATCH 3/3] cirrus: add blit_is_unsafe call to cirrus_bitblt_cputovideo Bugzilla: 1420493 CVE: CVE-2017-2620/20170221 RH-Acked-by: Paolo Bonzini RH-Acked-by: Laurent Vivier RH-Acked-by: Dr. David Alan Gilbert CIRRUS_BLTMODE_MEMSYSSRC blits do NOT check blit destination and blit width, at all. Oops. Fix it. Security impact: high. The missing blit destination check allows to write to host memory. Basically same as CVE-2014-8106 for the other blit variants. The missing blit width check allows to overflow cirrus_bltbuf, with the attractive target cirrus_srcptr (current cirrus_bltbuf write position) being located right after cirrus_bltbuf in CirrusVGAState. Due to cirrus emulation writing cirrus_bltbuf bytewise the attacker hasn't full control over cirrus_srcptr though, only one byte can be changed. Once the first byte has been modified further writes land elsewhere. Signed-off-by: Gerd Hoffmann Upstream: TBD (embargoed until Feb 21st) Signed-off-by: Miroslav Rezanina --- hw/display/cirrus_vga.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index 93aa596..218dfc1 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -899,6 +899,10 @@ static int cirrus_bitblt_cputovideo(CirrusVGAState * s) { int w; + if (blit_is_unsafe(s, true)) { + return 0; + } + s->cirrus_blt_mode &= ~CIRRUS_BLTMODE_MEMSYSSRC; s->cirrus_srcptr = &s->cirrus_bltbuf[0]; s->cirrus_srcptr_end = &s->cirrus_bltbuf[0]; @@ -924,6 +928,10 @@ static int cirrus_bitblt_cputovideo(CirrusVGAState * s) } s->cirrus_srccounter = s->cirrus_blt_srcpitch * s->cirrus_blt_height; } + + /* the blit_is_unsafe call above should catch this */ + assert(s->cirrus_blt_srcpitch <= CIRRUS_BLTBUFSIZE); + s->cirrus_srcptr = s->cirrus_bltbuf; s->cirrus_srcptr_end = s->cirrus_bltbuf + s->cirrus_blt_srcpitch; cirrus_update_memory_access(s); -- 1.8.3.1