* [PATCH] drm/virtio: Fix GEM handle creation UAF [not found] <20221216233355.542197-1-robdclark@gmail.com> @ 2022-12-16 23:33 ` Rob Clark 2022-12-16 23:50 ` Chia-I Wu [not found] ` <3ae74f28-580b-3b53-3d7b-e8bde97dabe3@collabora.com> 0 siblings, 2 replies; 3+ messages in thread From: Rob Clark @ 2022-12-16 23:33 UTC (permalink / raw) To: dri-devel Cc: Rob Clark, open list, Gurchetan Singh, Daniel Vetter, David Airlie, open list:VIRTIO GPU DRIVER, Chia-I Wu From: Rob Clark <robdclark@chromium.org> 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 <robdclark@chromium.org> --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index a5cccccb4998..f1c55c1630ca 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -366,10 +366,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; } @@ -731,11 +739,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; } -- 2.38.1 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/virtio: Fix GEM handle creation UAF 2022-12-16 23:33 ` [PATCH] drm/virtio: Fix GEM handle creation UAF Rob Clark @ 2022-12-16 23:50 ` Chia-I Wu [not found] ` <3ae74f28-580b-3b53-3d7b-e8bde97dabe3@collabora.com> 1 sibling, 0 replies; 3+ messages in thread From: Chia-I Wu @ 2022-12-16 23:50 UTC (permalink / raw) To: Rob Clark Cc: Rob Clark, open list, dri-devel, Gurchetan Singh, Daniel Vetter, David Airlie, open list:VIRTIO GPU DRIVER On Fri, Dec 16, 2022 at 3:33 PM Rob Clark <robdclark@gmail.com> wrote: > > From: Rob Clark <robdclark@chromium.org> > > 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 <robdclark@chromium.org> Reviewed-by: Chia-I Wu <olvaffe@gmail.com> _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <3ae74f28-580b-3b53-3d7b-e8bde97dabe3@collabora.com>]
* Re: [PATCH] drm/virtio: Fix GEM handle creation UAF [not found] ` <3ae74f28-580b-3b53-3d7b-e8bde97dabe3@collabora.com> @ 2023-01-10 1:47 ` Rob Clark 0 siblings, 0 replies; 3+ messages in thread From: Rob Clark @ 2023-01-10 1:47 UTC (permalink / raw) To: Dmitry Osipenko Cc: Rob Clark, open list, dri-devel, Gurchetan Singh, David Airlie, open list:VIRTIO GPU DRIVER On Mon, Jan 9, 2023 at 3:28 PM Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote: > > On 12/17/22 02:33, Rob Clark wrote: > > From: Rob Clark <robdclark@chromium.org> > > > > 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 <robdclark@chromium.org> > > --- > > drivers/gpu/drm/virtio/virtgpu_ioctl.c | 19 +++++++++++++++++-- > > 1 file changed, 17 insertions(+), 2 deletions(-) > > Added fixes/stable tags and applied this virtio-gpu patch to misc-fixes. > The Panfrost patch is untouched. Thanks.. the panfrost patch was not intended to be part of the same series (but apparently that is what happens when I send them at the same time), and was superceded by a patch from Steven Price (commit 4217c6ac8174 ("drm/panfrost: Fix GEM handle creation ref-counting") already applied to misc-fixes BR, -R _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-10 1:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20221216233355.542197-1-robdclark@gmail.com>
2022-12-16 23:33 ` [PATCH] drm/virtio: Fix GEM handle creation UAF Rob Clark
2022-12-16 23:50 ` Chia-I Wu
[not found] ` <3ae74f28-580b-3b53-3d7b-e8bde97dabe3@collabora.com>
2023-01-10 1:47 ` Rob Clark
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox