Skip to content

Commit 064253c

Browse files
committed
drm: fix use of freed memory in drm_mode_setcrtc
drm_mode_setcrtc() retries modesetting in case one of the functions it calls returns -EDEADLK. connector_set, mode and fb are freed before retrying, but they are not set to NULL. This can cause drm_mode_setcrtc() to use those variables. For example: On the first try __drm_mode_set_config_internal() returns -EDEADLK. connector_set, mode and fb are freed. Next retry starts, and drm_modeset_lock_all_ctx() returns -EDEADLK, and we jump to 'out'. The code will happily try to release all three again. This leads to crashes of different kinds, depending on the sequence the EDEADLKs happen. Fix this by setting the three variables to NULL at the start of the retry loop. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20180917110054.4053-1-tomi.valkeinen@ti.com
1 parent db05c48 commit 064253c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/gpu/drm/drm_crtc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,9 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
567567
struct drm_mode_crtc *crtc_req = data;
568568
struct drm_crtc *crtc;
569569
struct drm_plane *plane;
570-
struct drm_connector **connector_set = NULL, *connector;
571-
struct drm_framebuffer *fb = NULL;
572-
struct drm_display_mode *mode = NULL;
570+
struct drm_connector **connector_set, *connector;
571+
struct drm_framebuffer *fb;
572+
struct drm_display_mode *mode;
573573
struct drm_mode_set set;
574574
uint32_t __user *set_connectors_ptr;
575575
struct drm_modeset_acquire_ctx ctx;
@@ -598,6 +598,10 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
598598
mutex_lock(&crtc->dev->mode_config.mutex);
599599
drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
600600
retry:
601+
connector_set = NULL;
602+
fb = NULL;
603+
mode = NULL;
604+
601605
ret = drm_modeset_lock_all_ctx(crtc->dev, &ctx);
602606
if (ret)
603607
goto out;

0 commit comments

Comments
 (0)