Skip to content

Commit 5253125

Browse files
robclarkdigetx
authored andcommitted
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 <[email protected]> Reviewed-by: Chia-I Wu <[email protected]> Fixes: 62fb7a5 ("virtio-gpu: add 3d/virgl support") Cc: [email protected] Signed-off-by: Dmitry Osipenko <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 0688773 commit 5253125

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

drivers/gpu/drm/virtio/virtgpu_ioctl.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,18 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
358358
drm_gem_object_release(obj);
359359
return ret;
360360
}
361-
drm_gem_object_put(obj);
362361

363362
rc->res_handle = qobj->hw_res_handle; /* similiar to a VM address */
364363
rc->bo_handle = handle;
364+
365+
/*
366+
* The handle owns the reference now. But we must drop our
367+
* remaining reference *after* we no longer need to dereference
368+
* the obj. Otherwise userspace could guess the handle and
369+
* race closing it from another thread.
370+
*/
371+
drm_gem_object_put(obj);
372+
365373
return 0;
366374
}
367375

@@ -723,11 +731,18 @@ static int virtio_gpu_resource_create_blob_ioctl(struct drm_device *dev,
723731
drm_gem_object_release(obj);
724732
return ret;
725733
}
726-
drm_gem_object_put(obj);
727734

728735
rc_blob->res_handle = bo->hw_res_handle;
729736
rc_blob->bo_handle = handle;
730737

738+
/*
739+
* The handle owns the reference now. But we must drop our
740+
* remaining reference *after* we no longer need to dereference
741+
* the obj. Otherwise userspace could guess the handle and
742+
* race closing it from another thread.
743+
*/
744+
drm_gem_object_put(obj);
745+
731746
return 0;
732747
}
733748

0 commit comments

Comments
 (0)