Commit 8490d6a7e0a0a6fab5c2d82d57a3937306660864
Committed by
Daniel Vetter
1 parent
900ab59e26
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 <cohens@codeaurora.org> Cc: stable@vger.kernel.org Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/1595284250-31580-1-git-send-email-cohens@codeaurora.org
Showing 1 changed file with 4 additions and 6 deletions Side-by-side Diff
drivers/gpu/drm/drm_gem.c
... | ... | @@ -871,9 +871,6 @@ |
871 | 871 | * @file_priv: drm file-private structure |
872 | 872 | * |
873 | 873 | * 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. | |
877 | 874 | */ |
878 | 875 | int |
879 | 876 | drm_gem_open_ioctl(struct drm_device *dev, void *data, |
880 | 877 | |
881 | 878 | |
... | ... | @@ -898,14 +895,15 @@ |
898 | 895 | |
899 | 896 | /* drm_gem_handle_create_tail unlocks dev->object_name_lock. */ |
900 | 897 | ret = drm_gem_handle_create_tail(file_priv, obj, &handle); |
901 | - drm_gem_object_put_unlocked(obj); | |
902 | 898 | if (ret) |
903 | - return ret; | |
899 | + goto err; | |
904 | 900 | |
905 | 901 | args->handle = handle; |
906 | 902 | args->size = obj->size; |
907 | 903 | |
908 | - return 0; | |
904 | +err: | |
905 | + drm_gem_object_put_unlocked(obj); | |
906 | + return ret; | |
909 | 907 | } |
910 | 908 | |
911 | 909 | /** |