From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F1D1C3DA78 for ; Sat, 14 Jan 2023 09:58:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230205AbjANJ6Z (ORCPT ); Sat, 14 Jan 2023 04:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbjANJ6Y (ORCPT ); Sat, 14 Jan 2023 04:58:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81D487A85 for ; Sat, 14 Jan 2023 01:58:22 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3F44AB80765 for ; Sat, 14 Jan 2023 09:58:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CBB5C433EF; Sat, 14 Jan 2023 09:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1673690299; bh=xqMlhx5/i5rpIh5L12YNjBfGTyUDOEWM/YYYetYDzrs=; h=Subject:To:Cc:From:Date:From; b=at41KfgdK7lO7N2fg2059sKfkRTuVXkF86yPrlpNs1remWVqoUaZHvD2QdqvxHy6v pncCe3NfevhS48/TPZHIa4c74bAj4RUOZzXDfAj47CXHo5IrNR3K9znN+qQ3wj+H2q a/QNJq/xhbMfdX8ov7KTC78Viy2dS9RfyKs8me4s= Subject: FAILED: patch "[PATCH] drm/virtio: Fix GEM handle creation UAF" failed to apply to 5.4-stable tree To: robdclark@chromium.org, dmitry.osipenko@collabora.com, olvaffe@gmail.com Cc: From: Date: Sat, 14 Jan 2023 10:58:06 +0100 Message-ID: <167369028686134@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch below does not apply to the 5.4-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . Possible dependencies: 52531258318e ("drm/virtio: Fix GEM handle creation UAF") 897b4d1acaf5 ("drm/virtio: implement blob resources: resource create blob ioctl") 16845c5d5409 ("drm/virtio: implement blob resources: implement vram object") 6076a9711dc5 ("drm/virtio: implement blob resources: probe for host visible region") 6815cfe602d0 ("drm/virtio: implement blob resources: probe for the feature.") 30172efbfb84 ("drm/virtio: blob prep: refactor getting pages and attaching backing") deb2464e4c6d ("drm/virtio: report uuid in debugfs") c84adb304c10 ("drm/virtio: Support virtgpu exported resources") 0a19b068acc4 ("Merge tag 'drm-misc-next-2020-06-19' of git://anongit.freedesktop.org/drm/drm-misc into drm-next") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 52531258318ed59a2dc5a43df2eaf0eb1d65438e Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Fri, 16 Dec 2022 15:33:55 -0800 Subject: [PATCH] drm/virtio: Fix GEM handle creation UAF Userspace can guess the handle value and try to race GEM object creation with handle close, resulting in a use-after-free if we dereference the object after dropping the handle's reference. For that reason, dropping the handle's reference must be done *after* we are done dereferencing the object. Signed-off-by: Rob Clark Reviewed-by: Chia-I Wu Fixes: 62fb7a5e1096 ("virtio-gpu: add 3d/virgl support") Cc: stable@vger.kernel.org Signed-off-by: Dmitry Osipenko Link: https://patchwork.freedesktop.org/patch/msgid/20221216233355.542197-2-robdclark@gmail.com diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index 5d05093014ac..9f4a90493aea 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -358,10 +358,18 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, drm_gem_object_release(obj); return ret; } - drm_gem_object_put(obj); rc->res_handle = qobj->hw_res_handle; /* similiar to a VM address */ rc->bo_handle = handle; + + /* + * The handle owns the reference now. But we must drop our + * remaining reference *after* we no longer need to dereference + * the obj. Otherwise userspace could guess the handle and + * race closing it from another thread. + */ + drm_gem_object_put(obj); + return 0; } @@ -723,11 +731,18 @@ static int virtio_gpu_resource_create_blob_ioctl(struct drm_device *dev, drm_gem_object_release(obj); return ret; } - drm_gem_object_put(obj); rc_blob->res_handle = bo->hw_res_handle; rc_blob->bo_handle = handle; + /* + * The handle owns the reference now. But we must drop our + * remaining reference *after* we no longer need to dereference + * the obj. Otherwise userspace could guess the handle and + * race closing it from another thread. + */ + drm_gem_object_put(obj); + return 0; }