Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp182172pxx; Wed, 28 Oct 2020 01:56:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBLRqWU1QJH+EqNVxCE2XFUOj39mF0OGXEFqoYKwVJ4ndzk5NzVoZNm8fkg8PktobzW5Vw X-Received: by 2002:aa7:d29a:: with SMTP id w26mr6393981edq.59.1603875367139; Wed, 28 Oct 2020 01:56:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603875367; cv=none; d=google.com; s=arc-20160816; b=TSJpV43aEeEX1BDadbgzMjqF4kJ6xJ8InJiLWeSXBKh6yBdNYLK7lVJf5HFJCQ8OB4 VlQk7lyp/NKm3DFdRxZCtvRIn6XDGZttTi6lNPgrc4JK6myI7QXoDWeBPddAxN+tZ428 fB7yGs9R7ufAVNQhXN9H6/W98TETp+DbHhWp5PjOuRh72srOXjbCVpDrT+dlefwGVcBU mPqOJ0kOngQYjK/r0HvMsEkp3gdKGx/9KQztmRYGTKoMfP+ti2iZaDKk9HjOhskmmbv0 2HxVt6GwuS/1j6QIiRu/x/P5pRuIl7u+nxJ04g9GxVHzAUe5mQaEbf++B6B0LkFKcWIZ Nr8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1o1813sgayq3+j+CR2k9PtiOzd339A6Svln7o3TTluI=; b=pr1Oxuq/7/K5R9PbaJrXfW+aeYMA94xNGQ4FZvAMINO9igWI6TQpgM8z3ycEffI6sz E3L7N9XyQLSAclNTbRssNjYX5WBqWcxa36DHOqX1SUgi/5pubFI+6itj0axNSRV+mLE/ +5ZqQC5LvxUj42Be6QhP02V+vMO4FPsO8oVnYTHcmaHp6uHzMxN6yX1FkMb50T/jvBVb 02zGACfCODifNJ3qEt7XWYPkp1RopsEzDw4dOq8IauPjxynOlTZSvEjUxcJulfSRnzgc POBTf5621CSG6QXw+cPgkLpdNAqWcA6Hl0i36DYkJv9pxaxLyYQt+2N/BSsQ+4tSEYO8 /yDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v64iaalN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x26si2664388eds.99.2020.10.28.01.55.45; Wed, 28 Oct 2020 01:56:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v64iaalN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756520AbgJ0ONy (ORCPT + 99 others); Tue, 27 Oct 2020 10:13:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:56242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754861AbgJ0OH2 (ORCPT ); Tue, 27 Oct 2020 10:07:28 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6BB0E206D4; Tue, 27 Oct 2020 14:07:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807648; bh=9/P4t3T4oK4ugxqKvYoEhfqCdKZSPxWGBfHV5mm1LCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v64iaalNa5kVJgeKvilTsrADlGuGUIL5wOSCC+eL26oMUDWQ7xUYGYc1MkyPxsohg 6eM8XCx7Iiz+4S4qrA0pdpwEcnfVNsihep5ZPHsNDUF6qrlvVJ8BeKtewRWsylAKUj WFMJ6yHrzzPw6qa4wC+oyqmrU7OnbpDl7sDzzDhc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Doug Horn , Gerd Hoffmann , Sasha Levin Subject: [PATCH 4.9 128/139] Fix use after free in get_capset_info callback. Date: Tue, 27 Oct 2020 14:50:22 +0100 Message-Id: <20201027134908.226214507@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134902.130312227@linuxfoundation.org> References: <20201027134902.130312227@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Doug Horn [ Upstream commit e219688fc5c3d0d9136f8d29d7e0498388f01440 ] If a response to virtio_gpu_cmd_get_capset_info takes longer than five seconds to return, the callback will access freed kernel memory in vg->capsets. Signed-off-by: Doug Horn Link: http://patchwork.freedesktop.org/patch/msgid/20200902210847.2689-2-gurchetansingh@chromium.org Signed-off-by: Gerd Hoffmann Signed-off-by: Sasha Levin --- drivers/gpu/drm/virtio/virtgpu_kms.c | 2 ++ drivers/gpu/drm/virtio/virtgpu_vq.c | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index 036b0fbae0fb7..ba7855da7c7f6 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -113,8 +113,10 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev, vgdev->capsets[i].id > 0, 5 * HZ); if (ret == 0) { DRM_ERROR("timed out waiting for cap set %d\n", i); + spin_lock(&vgdev->display_info_lock); kfree(vgdev->capsets); vgdev->capsets = NULL; + spin_unlock(&vgdev->display_info_lock); return; } DRM_INFO("cap set %d: id %d, max-version %d, max-size %d\n", diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 772a5a3b0ce1a..18e8fcad6690b 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -596,9 +596,13 @@ static void virtio_gpu_cmd_get_capset_info_cb(struct virtio_gpu_device *vgdev, int i = le32_to_cpu(cmd->capset_index); spin_lock(&vgdev->display_info_lock); - vgdev->capsets[i].id = le32_to_cpu(resp->capset_id); - vgdev->capsets[i].max_version = le32_to_cpu(resp->capset_max_version); - vgdev->capsets[i].max_size = le32_to_cpu(resp->capset_max_size); + if (vgdev->capsets) { + vgdev->capsets[i].id = le32_to_cpu(resp->capset_id); + vgdev->capsets[i].max_version = le32_to_cpu(resp->capset_max_version); + vgdev->capsets[i].max_size = le32_to_cpu(resp->capset_max_size); + } else { + DRM_ERROR("invalid capset memory."); + } spin_unlock(&vgdev->display_info_lock); wake_up(&vgdev->resp_wq); } -- 2.25.1