Skip to content

Commit d6ea261

Browse files
Oleksandr Andrushchenkoandr2000
authored andcommitted
drm: Fix possible race conditions while unplugging DRM device
[ Upstream commit 069035c ] When unplugging a hotpluggable DRM device we first unregister it with drm_dev_unregister and then set drm_device.unplugged flag which is used to mark device critical sections with drm_dev_enter()/ drm_dev_exit() preventing access to device resources that are not available after the device is gone. But drm_dev_unregister may lead to hotplug uevent(s) fired to user-space on card and/or connector removal, thus making it possible for user-space to try accessing a disconnected device. Fix this by first making sure device is properly marked as disconnected and only then unregister it. Fixes: bee330f ("drm: Use srcu to protect drm_device.unplugged") Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com> Reported-by: Andrii Chepurnyi <andrii_chepurnyi@epam.com> Cc: "Noralf Trønnes" <noralf@tronnes.org> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20180522141304.18646-1-andr2000@gmail.com
1 parent 4881b23 commit d6ea261

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

drivers/gpu/drm/drm_drv.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,6 @@ EXPORT_SYMBOL(drm_dev_exit);
417417
*/
418418
void drm_dev_unplug(struct drm_device *dev)
419419
{
420-
drm_dev_unregister(dev);
421-
422-
mutex_lock(&drm_global_mutex);
423-
if (dev->open_count == 0)
424-
drm_dev_unref(dev);
425-
mutex_unlock(&drm_global_mutex);
426-
427420
/*
428421
* After synchronizing any critical read section is guaranteed to see
429422
* the new value of ->unplugged, and any critical section which might
@@ -432,6 +425,13 @@ void drm_dev_unplug(struct drm_device *dev)
432425
*/
433426
dev->unplugged = true;
434427
synchronize_srcu(&drm_unplug_srcu);
428+
429+
drm_dev_unregister(dev);
430+
431+
mutex_lock(&drm_global_mutex);
432+
if (dev->open_count == 0)
433+
drm_dev_unref(dev);
434+
mutex_unlock(&drm_global_mutex);
435435
}
436436
EXPORT_SYMBOL(drm_dev_unplug);
437437

0 commit comments

Comments
 (0)