Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1124398pxx; Tue, 27 Oct 2020 08:48:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI3bba0wzHT+y4dV0kxzb8M41x1sEZUbs9nI1nDaRcBkJ8GXqkgsRiIODl+KcZGACKJEyH X-Received: by 2002:a17:906:7247:: with SMTP id n7mr3044407ejk.174.1603813719315; Tue, 27 Oct 2020 08:48:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603813719; cv=none; d=google.com; s=arc-20160816; b=kfjkedys/ONYiXyB7LpCSbLPDEp5bad0eaSbqAop3Z8PDElysotjBhiawuL6dHmiCN CguDZ/T3ufAvAxS09JQ1lP0bsOiYZK7CrJe0w2MNEHB6QmAxRBLO3mL3UfmUuNafBpHh C9TXP2p9b7XVx/krjuZpeyGIWDhUArCM+dUhgoVjdk3gnm2JgxXkn/yHNktwFclrmlcy K4cAq4PT3xHpJQRd5pKfunsx5+4YQE/GFRHxzlCMWNhd1ra6gct/yKfxiEEovavyCvGd yk7bUuN1q/aWYdA/pEpgpEW2VcF/+gWBThOJG/6ZUCkUi8d0aY8ZiHKWhkTYygjvII9m 0+Bw== 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=4eg1vsSuSwpkF6+H1RGEbFwp9ZZLwoXLrUjWjbpIfus=; b=wC8AaTKeXL8X9rNgtNDmxdoQtajFwxI23nGOQcmUMyQ3Co+idu6SRp2jnMBVU9d3bf nIgMTvN2LMp4dn3ayElU1hoo1xj2r08DnlTiOmpzVuNAoGJjAmPEb5r0Y5TC3ONMBE2U SQR+FkTHYUzUyJBI/ZFNI7sw5U6AxWTitROFdsHU9+7kMajOBovzcjqAkv7zIofaB03T GopbgFAAZ5kHNunrlSQNbwToskiCJlWbi6rKdNIqeyW4ez2pWLfob2tjRfkevfzuTjDj EfRrFjVJADjcru9XJdM+nlrrYXshULSKzWbkhJg7OF2kqm8QkgmoP9AO6q8PYqSzgQft Q6uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q6qrUomz; 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 m26si1126223edq.372.2020.10.27.08.48.14; Tue, 27 Oct 2020 08:48:39 -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=Q6qrUomz; 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 S1782087AbgJ0O4i (ORCPT + 99 others); Tue, 27 Oct 2020 10:56:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:46252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1764140AbgJ0OqW (ORCPT ); Tue, 27 Oct 2020 10:46:22 -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 CE5AF20773; Tue, 27 Oct 2020 14:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809981; bh=wQr68+vYs99n5H4ysvc98rbX0sn/3HNW51O3srouVyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q6qrUomzBrHsZJzj9ZdHwLxyYjJD8oXJX39vuvO6qb9zDKsv71kRnKywXTrMaOF7Y XQeZHKs5Spq8bKoezyEtbIiUMTfANSUl/Q4iYpsdThupRcupnvL8274YcpPCB0Bs/3 i1qNiGyWTevrZprK5SffmrKFpQQGbXxD0Je3x0qs= 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 5.4 380/408] Fix use after free in get_capset_info callback. Date: Tue, 27 Oct 2020 14:55:18 +0100 Message-Id: <20201027135512.626726151@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 c190702fab726..6dcc05ab31eba 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -96,8 +96,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 7ac20490e1b4c..92022a83bbd5e 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -572,9 +572,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