Skip to content

Commit

Permalink
drm/simple_kms_helper: Fix NULL pointer dereference with no active CRTC
Browse files Browse the repository at this point in the history
With fixes for 4.14

It is possible that drm_simple_kms_plane_atomic_check called
with no CRTC set, e.g. when user-space application sets CRTC_ID/FB_ID
to 0 before doing any actual drawing. This leads to NULL pointer
dereference because in this case new CRTC state is NULL and must be
checked before accessing.

Signed-off-by: Oleksandr Andrushchenko <[email protected]>
Reviewed-by: Daniel Vetter <[email protected]>
Signed-off-by: Daniel Vetter <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
Oleksandr Andrushchenko authored and iartemenko committed Apr 25, 2018
1 parent a95d91d commit 6b7b71d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/gpu/drm/drm_simple_kms_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ static int drm_simple_kms_plane_atomic_check(struct drm_plane *plane,
pipe = container_of(plane, struct drm_simple_display_pipe, plane);
crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
&pipe->crtc);
if (!crtc_state->enable)
return 0; /* nothing to check when disabling or disabled */

clip.x2 = crtc_state->adjusted_mode.hdisplay;
clip.y2 = crtc_state->adjusted_mode.vdisplay;
if (crtc_state) {
clip.x2 = crtc_state->adjusted_mode.hdisplay;
clip.y2 = crtc_state->adjusted_mode.vdisplay;
}

ret = drm_plane_helper_check_state(plane_state, &clip,
DRM_PLANE_HELPER_NO_SCALING,
Expand All @@ -111,7 +111,9 @@ static int drm_simple_kms_plane_atomic_check(struct drm_plane *plane,
return ret;

if (!plane_state->visible)
return -EINVAL;
return 0;

drm_mode_get_hv_timing(&crtc_state->mode, &clip.x2, &clip.y2);

if (!pipe->funcs || !pipe->funcs->check)
return 0;
Expand Down

0 comments on commit 6b7b71d

Please sign in to comment.