Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp195028pxx; Wed, 28 Oct 2020 02:22:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHzLM87cHeWQcf/BrUiegOiOL+GnPSP3KJV4T/4dIjhFjFLndyxb7G8WXy5ntvPMamb1Ja X-Received: by 2002:a50:9ec6:: with SMTP id a64mr6520254edf.382.1603876962396; Wed, 28 Oct 2020 02:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603876962; cv=none; d=google.com; s=arc-20160816; b=ZioOTzXNhz+KF5Itf3uS/pbc17dE03J1gajLlfjPZNw0HBusRvtB4Ygaf6qCCrix8P 7Fte35gOPwqNVj1Zb7GCwCYgyBltjm3NG/u0kOdySyut45FfFGMYKZOqptRXFLZdwnlx 7cGV34QGyAIiZ6BETeC98KxyClJUcY6TLuo/wA/zN5zGAwlsykoiwQGR3PXuEGDq4BeF jO7ZCs+eVyyVeiorGr7HtZbfcguv+e7dJm1sOTwyvlk18h812BbGHGx7yy6FHo+6flcD 2K+c6PjxNUVhuLY52CX7Gz21zRuSG8z6GtSUbYNKTQLWRxch3K0cOEi+Pv8D2tX0MeRA lpwg== 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=u6ptgyWrasA+SG82A3/GY1LR/kOtgXHwDL+vllNK3Ec=; b=f52gk2PODAFlZT+esEX/pmNuGonCed9eOy45+49bi+b9zGtQ/O0kt+EtJP0s9Z/uDy ESw17/k30jKbfUmpyHfbCxdm/7/pmOX9mdRAnR/+8rAdwLMx3S2tcNqhxizbJIPWcie6 Bia14NrWrPBa6dSw4f9hd10NWZmPaCkuLM53kAVYbawhxItmTaYmtqzFDQoc+fkCYfOA nQGpH7rQiaqhzYYnQ+0zi4y4KaEWYtA/rwy4rSyBtJF0ow15sKc1g0IzM0Y3Ygbbu0D4 Kdp91NrA9+WWJwbANt6T47vHAIBjJCCl4iY9AT1PYHookZ/WLjgXyDJR3XR5FS/ZrElC yPLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tEgHbChD; 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 d2si2953320edn.245.2020.10.28.02.22.20; Wed, 28 Oct 2020 02:22:42 -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=tEgHbChD; 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 S2509490AbgJ0OTg (ORCPT + 99 others); Tue, 27 Oct 2020 10:19:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:39302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757213AbgJ0OQt (ORCPT ); Tue, 27 Oct 2020 10:16:49 -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 2EA5822281; Tue, 27 Oct 2020 14:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603808208; bh=XmtH0B5d3U1FNGvtemeJjeJBz814mke7qpOlX3I7Z/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tEgHbChDEfsJHkDYLec2CPvryIhsPa7Co3lvWIO3Xhr9eSby4r/WxLXYhKkSp+zzr ik7Ed3X919urwA6NXVECyrpistwPqjMxjuX2bGNavRB2y0n5/B/82hygoGauSyauLr fpO+c7MjjayhGHtIMP6LPrO3YtDVGwJu7ZoH/dpE= 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.14 175/191] Fix use after free in get_capset_info callback. Date: Tue, 27 Oct 2020 14:50:30 +0100 Message-Id: <20201027134918.145991503@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@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 6400506a06b07..bed450fbb2168 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 a3be65e689fd2..a956c73ea85e5 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -563,9 +563,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