Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp165502pxx; Wed, 28 Oct 2020 01:18:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx73p57iIqS0w2Dam138kfcdzPjzESeLdWTeUSzenFvp+7o6H75XGBzv1sF5D0ysI0vRbQ X-Received: by 2002:a17:906:3641:: with SMTP id r1mr6677669ejb.391.1603873122608; Wed, 28 Oct 2020 01:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603873122; cv=none; d=google.com; s=arc-20160816; b=00mDTF7n8A9bcO/m1TPK7HfyHMU3rk10nkoEyNB6qxrIAZ3Bv3uBMkzvtuDUMOyvWd 1GTY8aasUMwE/payaJncMImrghKyf/Z5EKRKsbhWKjpTROdYqd4zkW6gOhi3iy0Zbrn0 Iurk5uU93Vj97ktxRzc8QH+fBgDlP8OBEcdF+Ow9xFKw/wnixUC/okhmnXtubMlsAcTv j8LrhgesBdBLifbk/Lu9exYtDPkuuDTQgjUqOw6YA6NMzbQ2SZViL7Bpze1nNyQwgdrJ eR2u/pa7SfszuBPYAkUREMgM1rHgQJkJLEXmPUW4ttXhzmwaSKFfRI6yTqt2H2jSLpJb F4kg== 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=PEGjiUviMexQaJ7C2jKRmuXd8LsVAuGm0zRubtd7CRg=; b=mqsogn88tADEPUiVRWTx3I3XWHbngJSkgWhFxwmQTcblWkQbG4SOVUD3oVsAZ+rscN Tfm+bJYolwhu28TEwH/wyYcNhaySbntVXXq673gcZ6KA28LdnYOKp3HWrPVAt9fKndpa eqgVFwT4SjSx3/sXkCMl5q7M9JhIuaX2I5WHgQYrjkac/8SdWJDyBdSV/+WlzX45rIuT K98O3kqPnalXYMSNKdWjFSHRHi/pO6pUefmbZFM4WaqxJwrwPfijIFxuqjKFug/9DDV1 VqUUjLQrte8dsyxptH1MnXpiUajMxWPKJbSRgXHqUR4SdsxHEVXKHEC38aZrO7mkojTN gfBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jcMGsjtL; 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 w11si2719069ejq.533.2020.10.28.01.18.20; Wed, 28 Oct 2020 01:18: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=jcMGsjtL; 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 S1753739AbgJ0OBt (ORCPT + 99 others); Tue, 27 Oct 2020 10:01:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:48644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753607AbgJ0OBE (ORCPT ); Tue, 27 Oct 2020 10:01:04 -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 8608721D7B; Tue, 27 Oct 2020 14:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807264; bh=wDUYPS56b/18VlLZ2KLd4bd6O6ujEctojC7MEYgAW6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jcMGsjtLgs+i5LYGPT1KyG7r1IUCQXW8k+3YTc9Icgq6+OsDfR9qUFQU8SvRo5sYB N34kzeFDzNOUukJSr1c5RYD4G+6f1EhoEkbakwV+yy5FUyv7EnQNxGXs+VDc4Zfdkg PQj96GcXhjbQJ6ecRBcz/UykX3ChaPAf+7kxNoTQ= 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.4 103/112] Fix use after free in get_capset_info callback. Date: Tue, 27 Oct 2020 14:50:13 +0100 Message-Id: <20201027134905.422342858@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134900.532249571@linuxfoundation.org> References: <20201027134900.532249571@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 06496a1281622..476b9993b0682 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