Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp67979pxp; Wed, 16 Mar 2022 00:05:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYxryDx5Y3efKrMxD06PQLn0hHK92RYYXKS8N68YfM7gMJPzKL80S2d+wjcj8mLJhK9CGI X-Received: by 2002:a05:6402:510d:b0:416:a24f:2173 with SMTP id m13-20020a056402510d00b00416a24f2173mr28557216edd.274.1647414353870; Wed, 16 Mar 2022 00:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647414353; cv=none; d=google.com; s=arc-20160816; b=REVxkBlem4vM3Rkjh1MBChMUHcxxTgJVQ2wFs19Y2wFYm5USsphOBrFWtfNV6mYler 5FkysvOrZ8wbM+0RtLmor0mtnJOy/xkxmDNFfN1nDldDhLMCIf9eOqfEvdx+Iwv8lXsY iNe0ZENiNkxXmZPSzSnTF1X2KpCT5dTuCcyVlEnIdhw0IWyLa5fnwbdI6W3tOtqJG/gS BjTZ/sigITfK7UrInSknBMX7ckdX2Zz70SDA61FQTDANuy1j9rd0vAS7bVkwo9UEIT76 eLDE6aYTjz+41UqKK07GRIBiw4S8l2Cs92FShSlX8hKQA9NSzdqkkhJqS75LqKrc4uWP WNgQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UL7lLj4A++5Oz+pkYLcvbBVkt2iuq0TY2TonxDLjvE0=; b=yeAzNQA+Qp+e0ANzgRUMW46sdHAAPHwdGHxpC1lm+GWeG1aTLQ8ZScXtXUCmkOY99Z e2Zc/LGLNwAItbB+QfKu7qwK0q7Cxk3g88WjG4qakfoV5cTmH03Kw7jbe85LAJ9q+p4K 8HhaWT55JD5pmWUnBdT12Xp6aHGQadFwdPEbAD4E8Je8rIyatg7PYtUz5wuBge32IrQB SUjgqLM9KHgXlmc3bz8bo8Dd/m6T7tEcsLAYUzi/HqSAvtCXPAso1zY62A/vVqeMScWL EKPFL9Wj6xo3TMDKMPz8yOHo4q6u4/lyS0DIZ4KQnKglFRwIOjCSNBOMBhVDylaWslxG mDEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=n6u+BcOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz30-20020a1709077d9e00b006dab3dde56asi819771ejc.994.2022.03.16.00.05.10; Wed, 16 Mar 2022 00:05:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=n6u+BcOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245748AbiCNWp3 (ORCPT + 99 others); Mon, 14 Mar 2022 18:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245730AbiCNWpZ (ORCPT ); Mon, 14 Mar 2022 18:45:25 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CAB733EB2 for ; Mon, 14 Mar 2022 15:44:13 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id 92C0E1F42F1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1647297852; bh=chUCxgrXxxLP18r48yk/BRUcyw0NU6neGfKRFCcPg+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n6u+BcOSzxReYDlBivMmtSD9VeErrWx/vStT244llJdalsWwkCCjcHbUKX/OWlSZ/ Oy+Spx20aH8mxRwbVhoGqAA83CZL6gOxePHBo3ps2BLM9nVRw3X1jDRrH82b7kymXd 4900Hrkbjjq5AmbyEFHcnvITzvB7+5aNt0nt9VlPuuxX3B4izwDUUIWWuiLhOlHKNu 1amkAhvCnmWy8E7FycZEFLksO28KJlH0XDlfueTOQIoBM1LIDLUz1J3I+LxYqokeo0 w42+kmqxRLUMU7kqqJpPq3e8y93LufREAgD6X1QjMZZkqpFUsZoIKWh+oRUfwaM0Tx ux6kyxH/obUAA== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Steven Price , Alyssa Rosenzweig Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Gustavo Padovan , Daniel Stone , virtualization@lists.linux-foundation.org, Dmitry Osipenko , Dmitry Osipenko Subject: [PATCH v2 2/8] drm/virtio: Check whether transferred 2D BO is shmem Date: Tue, 15 Mar 2022 01:42:47 +0300 Message-Id: <20220314224253.236359-3-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314224253.236359-1-dmitry.osipenko@collabora.com> References: <20220314224253.236359-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Transferred 2D BO always must be a shmem BO. Add check for that to prevent NULL dereference if userspace passes a VRAM BO. Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/virtio/virtgpu_vq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 7c052efe8836..2edf31806b74 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -595,7 +595,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev, bool use_dma_api = !virtio_has_dma_quirk(vgdev->vdev); struct virtio_gpu_object_shmem *shmem = to_virtio_gpu_shmem(bo); - if (use_dma_api) + if (virtio_gpu_is_shmem(bo) && use_dma_api) dma_sync_sgtable_for_device(vgdev->vdev->dev.parent, shmem->pages, DMA_TO_DEVICE); -- 2.35.1