From patchwork Thu May 19 10:25:55 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: 9126331 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 25B299F37F for ; Thu, 19 May 2016 10:53:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D87F2021A for ; Thu, 19 May 2016 10:53:33 +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 C0496200E3 for ; Thu, 19 May 2016 10:53:32 +0000 (UTC) Received: from localhost ([::1]:49271 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3LE8-0001H6-Km for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 May 2016 06:30:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3L9l-000578-2O for qemu-devel@nongnu.org; Thu, 19 May 2016 06:26:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3L9b-0005QV-0i for qemu-devel@nongnu.org; Thu, 19 May 2016 06:26:16 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:36773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3L9a-0005QI-SD for qemu-devel@nongnu.org; Thu, 19 May 2016 06:26:06 -0400 Received: by mail-qk0-x241.google.com with SMTP id l68so7104988qkf.3 for ; Thu, 19 May 2016 03:26:06 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=YoSa9IbrbQBRDk7jjwKwRT/o4Tlg19d420Ndq/ujR3U=; b=DLZ1Y3HoWEB9raaTnXlmLGLvRfU7R0kEpHWcVDJhfIM6XkUMWQlnoz1msd1YwMHp4A 3h3yY1OWToOU1B6uYvX7GZ7A6/gAnpkaG2I5PLFl6waAQWS3heWIK63c6c7v9NLUFpSp CwXatc1CyHFbMd2nRbs/r1V169MgtjP5EmQdOXrzIFbLpgaYhuSqlr4vGjmbI5l4uOIc yCaz1m62JMHvTChP+fJKMgkfrAk7zNflAm1TVInfVWcXiMwuvmIIFEnfnbm0R9MsVQNz STdOrEPbhemoP6DJEmhBVbTRAtGBPW4nB3AzZP4h6XUzuxD8p/7Xb4HxemPFgVG1IFLV YDig== 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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=YoSa9IbrbQBRDk7jjwKwRT/o4Tlg19d420Ndq/ujR3U=; b=cMAaL2/koGro722pseL55Eyk7n44vgmzaVVtql0YKjiu0GBOiPBUGXDweSMBQ0lBb5 f8Yvo0VjOaaavTORoZDLzC9qISxkIRpPyr1/rLsodk+LymZjROBobolHKSP8j0FyVKMo JST0OWEvK4dibFyI4RMWBCrikm5wphiWFXBCuzwpO0Xdg6/NrpY+Tvchc6jsJQWIFyil 7cdaqG34OM0hk8M+CQK5LrceSQ/JhVGH47J6P90IdBvUfQu+sWRd1fbENhRRv/BfheDJ eVi4EzEP8y3Gt8rX88qo9xPWe8ueVsbG+/PHKTWlQPAicugLTh9fY1dXui2ZWr+aoHbF rMAQ== X-Gm-Message-State: AOPr4FVpPHCNMKI7wSbYqoiCuG3lplK7n1gfvQfl/nMLqjYAP82Rpb5/DEbFkBfnWIspLw== X-Received: by 10.55.90.130 with SMTP id o124mr13648214qkb.178.1463653566540; Thu, 19 May 2016 03:26:06 -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 w70sm6283168qhw.22.2016.05.19.03.26.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 May 2016 03:26:05 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Thu, 19 May 2016 12:25:55 +0200 Message-Id: <1463653560-26958-2-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1463653560-26958-1-git-send-email-marcandre.lureau@redhat.com> References: <1463653560-26958-1-git-send-email-marcandre.lureau@redhat.com> 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:c09::241 Subject: [Qemu-devel] [PATCH 1/6] 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=unavailable 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",