Skip to content

Commit 8408e40

Browse files
robclarksmb49
authored andcommitted
drm/virtio: Fix GEM handle creation UAF
BugLink: https://bugs.launchpad.net/bugs/2003914 [ Upstream commit 5253125 ] 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] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent 047a28f commit 8408e40

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/gpu/drm/virtio/virtgpu_ioctl.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,18 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
327327
drm_gem_object_release(obj);
328328
return ret;
329329
}
330-
drm_gem_object_put_unlocked(obj);
331330

332331
rc->res_handle = qobj->hw_res_handle; /* similiar to a VM address */
333332
rc->bo_handle = handle;
333+
334+
/*
335+
* The handle owns the reference now. But we must drop our
336+
* remaining reference *after* we no longer need to dereference
337+
* the obj. Otherwise userspace could guess the handle and
338+
* race closing it from another thread.
339+
*/
340+
drm_gem_object_put_unlocked(obj);
341+
334342
return 0;
335343
}
336344

0 commit comments

Comments
 (0)