Skip to content

Commit 8490d6a

Browse files
Steve Cohendanvet
authored andcommitted
drm: hold gem reference until object is no longer accessed
A use-after-free in drm_gem_open_ioctl can happen if the GEM object handle is closed between the idr lookup and retrieving the size from said object since a local reference is not being held at that point. Hold the local reference while the object can still be accessed to fix this and plug the potential security hole. Signed-off-by: Steve Cohen <[email protected]> Cc: [email protected] Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 900ab59 commit 8490d6a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/gpu/drm/drm_gem.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,6 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
871871
* @file_priv: drm file-private structure
872872
*
873873
* Open an object using the global name, returning a handle and the size.
874-
*
875-
* This handle (of course) holds a reference to the object, so the object
876-
* will not go away until the handle is deleted.
877874
*/
878875
int
879876
drm_gem_open_ioctl(struct drm_device *dev, void *data,
@@ -898,14 +895,15 @@ drm_gem_open_ioctl(struct drm_device *dev, void *data,
898895

899896
/* drm_gem_handle_create_tail unlocks dev->object_name_lock. */
900897
ret = drm_gem_handle_create_tail(file_priv, obj, &handle);
901-
drm_gem_object_put_unlocked(obj);
902898
if (ret)
903-
return ret;
899+
goto err;
904900

905901
args->handle = handle;
906902
args->size = obj->size;
907903

908-
return 0;
904+
err:
905+
drm_gem_object_put_unlocked(obj);
906+
return ret;
909907
}
910908

911909
/**

0 commit comments

Comments
 (0)