From patchwork Wed May 18 17:08:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 9121521 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0AEBE9F30C for ; Wed, 18 May 2016 17:09:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 444DE2037C for ; Wed, 18 May 2016 17:09:16 +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 9316220364 for ; Wed, 18 May 2016 17:09:15 +0000 (UTC) Received: from localhost ([::1]:46191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b34yA-0006GG-7V for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 May 2016 13:09:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b34xw-0006Ft-0x for qemu-devel@nongnu.org; Wed, 18 May 2016 13:09:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b34xq-0008LI-SJ for qemu-devel@nongnu.org; Wed, 18 May 2016 13:08:59 -0400 Received: from mail-qg0-x242.google.com ([2607:f8b0:400d:c04::242]:34562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b34xq-0008L2-NT for qemu-devel@nongnu.org; Wed, 18 May 2016 13:08:54 -0400 Received: by mail-qg0-x242.google.com with SMTP id e35so4701358qge.1 for ; Wed, 18 May 2016 10:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YoSa9IbrbQBRDk7jjwKwRT/o4Tlg19d420Ndq/ujR3U=; b=WFwXNfUcbRiCI82sP779i/azKxC2Uef2y+7qFXDQOD2vJRShDUcrmOjen9W8Yxs0m0 D/2peK310qYZOEgtnxNo/5uNkREQoKImJ1lVMv4YmCYx/XWs16hXyMi+3BhqN2Db/4SN hdOKSJiDtHnnApyOCRU+7rvaNOz5YpS3TnJgtrCXQSqF02e13zwy5zxc4voP7TBKcSyH Rerzpg9ZwCQ1GEsOSKAX6BoUO+euWbfOFDBK55WnWv2PsfwPWFtxexifY2oWsKiHEtNU b/JvWFEOboewOpePix/KOadIP4DX7epPp2S6mcOgbMelPkhXtocg7wLnt4peUqOKXGB3 cjKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=YoSa9IbrbQBRDk7jjwKwRT/o4Tlg19d420Ndq/ujR3U=; b=Mh1uebL+AHCyi66qxXlG/3Wv4nlQx5MfUvLURzOyg8n5dN2O7z45AKeae3TpwFHg/4 Xsv7iIjIk8/jOdcNb8oPgtOT6KsF6zrWDE8ysBY/4lY3oyZCAc8AwmfizbFeNWIB0qI3 yC/JDGmNRztWBkKLe9/e36cBXqfFNoKXBVDs/of2lYMUq/iXwQ7QXb5SW6zSS60u+vxe DTKdU5mvk8Yk2tZ5/2jQ57Qef2VBDGFro7PA5JEeuR0oBslKinfFI40SBZi4Craiqnt3 jLf5Kq/7i3eBoPp0tkMC+uv6z3Za4KpybdG/ZE2TjGYBkeKKcubGUTxNoqoyNGImaWXT 5PPw== X-Gm-Message-State: AOPr4FVjY+D/cu+3o7Cd2bGJ4zsfDggtla2R12Y3hw7XigSQRjVZHvoZDh7YSAyBpmDV9Q== X-Received: by 10.140.163.85 with SMTP id j82mr9182778qhj.40.1463591332846; Wed, 18 May 2016 10:08:52 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id c50sm4584003qga.38.2016.05.18.10.08.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 May 2016 10:08:51 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Wed, 18 May 2016 19:08:27 +0200 Message-Id: <1463591307-21205-1-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::242 Subject: [Qemu-devel] [PATCH] virtio-gpu: check early scanout id X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , kraxel@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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: Marc-André Lureau Before accessing the g->scanout array, in order to avoid potential out-of-bounds access. Signed-off-by: Marc-André Lureau --- 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 c181fb3..1193838 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -507,6 +507,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); + if (ss.scanout_id >= VIRTIO_GPU_MAX_SCANOUT || + ss.scanout_id >= g->conf.max_outputs) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d", + __func__, ss.scanout_id); + cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; + return; + } + g->enable = 1; if (ss.resource_id == 0) { scanout = &g->scanout[ss.scanout_id]; @@ -516,8 +524,7 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, res->scanout_bitmask &= ~(1 << ss.scanout_id); } } - if (ss.scanout_id == 0 || - ss.scanout_id >= g->conf.max_outputs) { + if (ss.scanout_id == 0) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d", __func__, ss.scanout_id); @@ -532,14 +539,6 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, } /* create a surface for this scanout */ - if (ss.scanout_id >= VIRTIO_GPU_MAX_SCANOUT || - ss.scanout_id >= g->conf.max_outputs) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %d", - __func__, ss.scanout_id); - cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; - return; - } - res = virtio_gpu_find_resource(g, ss.resource_id); if (!res) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\n",