diff options
author | Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com> | 2018-05-22 10:13:04 -0400 |
---|---|---|
committer | Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com> | 2018-05-31 03:36:28 -0400 |
commit | 069035c5db3459b9b5f12caf3bffed9a863fa5c4 (patch) | |
tree | f32b505ef20d1e6dba33220a5681fd71b330344d | |
parent | fbecef131676c1d18e8e6b42c04e10dc49725e96 (diff) |
drm: Fix possible race conditions while unplugging DRM device
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: bee330f3d672 ("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
-rw-r--r-- | drivers/gpu/drm/drm_drv.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index f6910ebe4d0e..cc2675550e28 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c | |||
@@ -369,13 +369,6 @@ EXPORT_SYMBOL(drm_dev_exit); | |||
369 | */ | 369 | */ |
370 | void drm_dev_unplug(struct drm_device *dev) | 370 | void drm_dev_unplug(struct drm_device *dev) |
371 | { | 371 | { |
372 | drm_dev_unregister(dev); | ||
373 | |||
374 | mutex_lock(&drm_global_mutex); | ||
375 | if (dev->open_count == 0) | ||
376 | drm_dev_put(dev); | ||
377 | mutex_unlock(&drm_global_mutex); | ||
378 | |||
379 | /* | 372 | /* |
380 | * After synchronizing any critical read section is guaranteed to see | 373 | * After synchronizing any critical read section is guaranteed to see |
381 | * the new value of ->unplugged, and any critical section which might | 374 | * the new value of ->unplugged, and any critical section which might |
@@ -384,6 +377,13 @@ void drm_dev_unplug(struct drm_device *dev) | |||
384 | */ | 377 | */ |
385 | dev->unplugged = true; | 378 | dev->unplugged = true; |
386 | synchronize_srcu(&drm_unplug_srcu); | 379 | synchronize_srcu(&drm_unplug_srcu); |
380 | |||
381 | drm_dev_unregister(dev); | ||
382 | |||
383 | mutex_lock(&drm_global_mutex); | ||
384 | if (dev->open_count == 0) | ||
385 | drm_dev_put(dev); | ||
386 | mutex_unlock(&drm_global_mutex); | ||
387 | } | 387 | } |
388 | EXPORT_SYMBOL(drm_dev_unplug); | 388 | EXPORT_SYMBOL(drm_dev_unplug); |
389 | 389 | ||