Skip to content

Commit

Permalink
drm/virtio: Fix GEM handle creation UAF
Browse files Browse the repository at this point in the history
[ 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]>
  • Loading branch information
robclark authored and gregkh committed Jan 18, 2023
1 parent 34606ad commit 19ec87d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/gpu/drm/virtio/virtgpu_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
}
return ret;
}
drm_gem_object_put_unlocked(obj);

rc->res_handle = res_id; /* similiar to a VM address */
rc->bo_handle = handle;
Expand All @@ -318,6 +317,15 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
virtio_gpu_unref_list(&validate_list);
dma_fence_put(&fence->f);
}

/*
* 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_unlocked(obj);

return 0;
fail_unref:
if (vgdev->has_virgl_3d) {
Expand Down

0 comments on commit 19ec87d

Please sign in to comment.