Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3575305pxp; Tue, 8 Mar 2022 17:52:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5kQwvy4ebnV0pt3S2iKMdJCTjVCCoNixxF2ykzzd2ERiefCvCMAGRwi8m/h+OVoQaqhR4 X-Received: by 2002:a63:87c2:0:b0:380:93c6:e29a with SMTP id i185-20020a6387c2000000b0038093c6e29amr4373424pge.310.1646790725491; Tue, 08 Mar 2022 17:52:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646790725; cv=none; d=google.com; s=arc-20160816; b=Bt3anloCAhswkq1qS4BwfajKYFYzzZ3B8FPScwIgCJh9RUP1NeJuQ4vwpItxjpSuGf CuFOY6NzF3Tb4x4GciSRvhp9WS0s45D9PNMA7KRU3VKZ5DB3QX0NalztbEAgzg9WWOOU nBZZ1fQKTAkGhMKyjdkod5LL85ykf+EucSHhYzcGdiXogqAoibwCdnEdJbkdkh4EH5cc 7tK63Ratmlr1m5eoZU4y0OY4CCv9UYw7xV3hxChNP18++9Y4gVutWmYYp4CfwqD0S3SD C15kQH87/Xq527mJQKD7sDw1Sz5zCcvBDtu5vGkIU/zHP0t+7x7Um35FsjYhtgdrDLxw PgeA== 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=sEly6PDcAhY54sytFVZp8NCXQtiJ7gjc/bJTjUaqKE/BqcrXjuy/BxdNhX31VHRBU/ t6UUMjnfAQHYmeNp1g+20HU5uDrz5oGbY4B9ccsZHCvhiqr7MF90Ai2VYsyec7hpBYfn Bh5k8jgvKOW66zuAZ1kAhaOgLiU2Wk0wWv0RHlQsscHps8JTAHMSuw6dfKvOSE65yfFZ zLpn369X762J129CRW0QpAapjU0Xb+GFrFMOIT2K+ldoRiTRa5fcwTE7O+anVwuq3kfM NclPDkgEafod2YyLIeWPUEXCfF8pAHC2XgjKtg22q9Y/551lEPI2oGwCf0Z/VlyNNT4T aNGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=RAMZgwvb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d5-20020a63a705000000b0036c17259f1csi475466pgf.820.2022.03.08.17.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:52:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=RAMZgwvb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 82E2533374; Tue, 8 Mar 2022 16:27:16 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347112AbiCHNSv (ORCPT + 99 others); Tue, 8 Mar 2022 08:18:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347096AbiCHNSk (ORCPT ); Tue, 8 Mar 2022 08:18:40 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6DF0BC33 for ; Tue, 8 Mar 2022 05:17:40 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id DC4201F4404D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1646745459; bh=chUCxgrXxxLP18r48yk/BRUcyw0NU6neGfKRFCcPg+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RAMZgwvbW2XOy+frKOBEYxArTnDRzdt+R64V2yCLaTLaZHgjKscL80dfb6PfZ6GmQ I1jjo4BtX31ZIdTh5I3vczLk3m22XdmCthCfyL+yZbmZTwStts28WROgUqyQFirKnY M4MfMXgijeV+Xkoq26vw+0vlamzK2YtClTpTxcL56L2dPGMtMC+vwGzo2aivkCpxXJ CLI0pY1qlsnBxDl9n3gKc6QFhu7uU74u5yTzsGeZ2TSosc8l8ZLy1Zs1A9dUfEJFro Aoq70epRHjQKs+sj1cIae/mXGOnkntpxxFiK0MzoY3eIPj5juYMMR1EkLOSUmd0lsv kAamol1Tr3+Gw== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Gustavo Padovan , Daniel Stone , Tomeu Vizoso , virtualization@lists.linux-foundation.org, Dmitry Osipenko Subject: [PATCH v1 2/5] drm/virtio: Check whether transferred 2D BO is shmem Date: Tue, 8 Mar 2022 16:17:22 +0300 Message-Id: <20220308131725.60607-3-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220308131725.60607-1-dmitry.osipenko@collabora.com> References: <20220308131725.60607-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no 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