]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/vkms: Hold gem object while still in-use
authorEzequiel Garcia <ezequiel@collabora.com>
Mon, 27 Apr 2020 21:44:05 +0000 (18:44 -0300)
committerRodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Thu, 7 May 2020 01:51:46 +0000 (21:51 -0400)
We need to keep the reference to the drm_gem_object
until the last access by vkms_dumb_create.

Therefore, the put the object after it is used.

This fixes a use-after-free issue reported by syzbot.

While here, change vkms_gem_create() symbol to static.

Reported-and-tested-by: syzbot+e3372a2afe1e7ef04bc7@syzkaller.appspotmail.com
Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Reviewed-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200427214405.13069-1-ezequiel@collabora.com
drivers/gpu/drm/vkms/vkms_drv.h
drivers/gpu/drm/vkms/vkms_gem.c

index eda04ffba7b1f15ad3321c607fac524092a9c92d..f4036bb0b9a89a51c05acdb1df2c0041af47a4ff 100644 (file)
@@ -117,11 +117,6 @@ struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev,
                                  enum drm_plane_type type, int index);
 
 /* Gem stuff */
-struct drm_gem_object *vkms_gem_create(struct drm_device *dev,
-                                      struct drm_file *file,
-                                      u32 *handle,
-                                      u64 size);
-
 vm_fault_t vkms_gem_fault(struct vm_fault *vmf);
 
 int vkms_dumb_create(struct drm_file *file, struct drm_device *dev,
index 2e01186fb943b897b7b40dd29176465d2b85a1e7..c541fec575665b3414a437911a316457a916c6e1 100644 (file)
@@ -97,10 +97,10 @@ vm_fault_t vkms_gem_fault(struct vm_fault *vmf)
        return ret;
 }
 
-struct drm_gem_object *vkms_gem_create(struct drm_device *dev,
-                                      struct drm_file *file,
-                                      u32 *handle,
-                                      u64 size)
+static struct drm_gem_object *vkms_gem_create(struct drm_device *dev,
+                                             struct drm_file *file,
+                                             u32 *handle,
+                                             u64 size)
 {
        struct vkms_gem_object *obj;
        int ret;
@@ -113,7 +113,6 @@ struct drm_gem_object *vkms_gem_create(struct drm_device *dev,
                return ERR_CAST(obj);
 
        ret = drm_gem_handle_create(file, &obj->gem, handle);
-       drm_gem_object_put_unlocked(&obj->gem);
        if (ret)
                return ERR_PTR(ret);
 
@@ -142,6 +141,8 @@ int vkms_dumb_create(struct drm_file *file, struct drm_device *dev,
        args->size = gem_obj->size;
        args->pitch = pitch;
 
+       drm_gem_object_put_unlocked(gem_obj);
+
        DRM_DEBUG_DRIVER("Created object of size %lld\n", size);
 
        return 0;