From patchwork Thu Nov 4 21:42:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 12603825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5AA0C433F5 for ; Thu, 4 Nov 2021 21:57:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 51E4661215 for ; Thu, 4 Nov 2021 21:57:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 51E4661215 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 47F7673899; Thu, 4 Nov 2021 21:57:29 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2FD287388F for ; Thu, 4 Nov 2021 21:57:28 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10158"; a="231647517" X-IronPort-AV: E=Sophos;i="5.87,209,1631602800"; d="scan'208";a="231647517" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2021 14:57:27 -0700 X-IronPort-AV: E=Sophos;i="5.87,209,1631602800"; d="scan'208";a="579056880" Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2021 14:57:27 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/virtio: Fix NULL dereference error in virtio_gpu_poll Date: Thu, 4 Nov 2021 14:42:49 -0700 Message-Id: <20211104214249.1802789-1-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <15731ad7-83ff-c7ef-e4a1-8b11814572c2@xenosoft.de> References: <15731ad7-83ff-c7ef-e4a1-8b11814572c2@xenosoft.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gurchetan Singh , Gerd Hoffmann , Vivek Kasireddy , Christian Zigotzky Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" When virgl is not enabled, vfpriv pointer would not be allocated. Therefore, check for a valid value before dereferencing. Reported-by: Christian Zigotzky Cc: Gurchetan Singh Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Tested-by: Christian Zigotzky [1] --- drivers/gpu/drm/virtio/virtgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c b/drivers/gpu/drm/virtio/virtgpu_drv.c index 749db18dcfa2..d86e1ad4a972 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.c +++ b/drivers/gpu/drm/virtio/virtgpu_drv.c @@ -163,10 +163,11 @@ static __poll_t virtio_gpu_poll(struct file *filp, struct drm_file *drm_file = filp->private_data; struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv; struct drm_device *dev = drm_file->minor->dev; + struct virtio_gpu_device *vgdev = dev->dev_private; struct drm_pending_event *e = NULL; __poll_t mask = 0; - if (!vfpriv->ring_idx_mask) + if (!vgdev->has_virgl_3d || !vfpriv || !vfpriv->ring_idx_mask) return drm_poll(filp, wait); poll_wait(filp, &drm_file->event_wait, wait);