From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4p2Y-00040O-B7 for qemu-devel@nongnu.org; Mon, 23 May 2016 08:32:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4p2S-0008Hr-7l for qemu-devel@nongnu.org; Mon, 23 May 2016 08:32:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32971) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4p2S-0008Hc-1m for qemu-devel@nongnu.org; Mon, 23 May 2016 08:32:52 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40AB17F344 for ; Mon, 23 May 2016 12:32:50 +0000 (UTC) From: Gerd Hoffmann Date: Mon, 23 May 2016 14:32:37 +0200 Message-Id: <1464006764-8115-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1464006764-8115-1-git-send-email-kraxel@redhat.com> References: <1464006764-8115-1-git-send-email-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 1/7] virtio-gpu: check early scanout id List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , "Michael S. Tsirkin" From: Marc-Andr=C3=A9 Lureau Before accessing the g->scanout array, in order to avoid potential out-of-bounds access. Signed-off-by: Marc-Andr=C3=A9 Lureau Message-id: 1463653560-26958-2-git-send-email-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- hw/display/virtio-gpu.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 91345bd..64a60f2 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -508,6 +508,14 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id, ss.r.width, ss.r.height, ss.r.x, ss= .r.y); =20 + if (ss.scanout_id >=3D VIRTIO_GPU_MAX_SCANOUT || + ss.scanout_id >=3D g->conf.max_outputs) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified= %d", + __func__, ss.scanout_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; + return; + } + g->enable =3D 1; if (ss.resource_id =3D=3D 0) { scanout =3D &g->scanout[ss.scanout_id]; @@ -517,8 +525,7 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, res->scanout_bitmask &=3D ~(1 << ss.scanout_id); } } - if (ss.scanout_id =3D=3D 0 || - ss.scanout_id >=3D g->conf.max_outputs) { + if (ss.scanout_id =3D=3D 0) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d", __func__, ss.scanout_id); @@ -533,14 +540,6 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, } =20 /* create a surface for this scanout */ - if (ss.scanout_id >=3D VIRTIO_GPU_MAX_SCANOUT || - ss.scanout_id >=3D g->conf.max_outputs) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified= %d", - __func__, ss.scanout_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; - return; - } - res =3D virtio_gpu_find_resource(g, ss.resource_id); if (!res) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %= d\n", --=20 1.8.3.1