drm/amd/display: Fix NULL pointer dereference in amdgpu_dm_crtc_set_vblank()
Subsystems (3)
PATCH 1/1 drm/amd/display: Fix NULL pointer dereference in amdgpu_dm_crtc_set_vblank()
amdgpu_dm_crtc_set_vblank() dereferences acrtc_state->stream when vblank is enabled/queried from DRM_IOCTL_MODE_CRTC_GET_SEQUENCE before a stream is attached to it.
BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: amdgpu_dm_crtc_set_vblank+0x6b/0x4d0 [amdgpu] Call Trace: drm_vblank_enable drm_vblank_get drm_crtc_get_sequence_ioctl drm_ioctl_kernel drm_ioctl
Reproduced by running VKCTS with WSI tests enabled on RADV.
Guard the enable path on acrtc_state->stream being non-NULL, matching the existing checks in this function.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +1 -1
@@ -268,7 +268,7 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable) irq_type =amdgpu_display_crtc_idx_to_irq_type (adev, acrtc->crtc_id); -if (enable) { +if (enable && acrtc_state->stream) {struct dc *dc = adev->dm.dc;struct drm_vblank_crtc *vblank =drm_crtc_vblank_crtc (crtc);struct psr_settings *psr = &acrtc_state->stream->link->psr_settings;
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Lockless access to crtc->state in the vblank enable hook can lead to a Use-After-Free of the state and stream objects. --
--- Patch [1]: [PATCH] drm/amd/display: Fix NULL pointer dereference in amdgpu_dm_crtc_set_vblank() --- commit 22682e17c05c1df8dcb5140d5111a3b728f76c8e
Author: Samuel Pitoiset <[email protected]>
Subject: drm/amd/display: Fix NULL pointer dereference in amdgpu_dm_crtc_set_vblank()
This commit adds a check to ensure acrtc_state->stream is non-NULL before dereferencing it in the vblank enable path, fixing a crash when vblank is queried early.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable) · line 274
Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +1
-1@@ -268,7 +268,7 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable) irq_type =amdgpu_display_crtc_idx_to_irq_type (adev, acrtc->crtc_id); -if (enable) { +if (enable && acrtc_state->stream) {struct dc *dc = adev->dm.dc;struct drm_vblank_crtc *vblank =drm_crtc_vblank_crtc (crtc);struct psr_settings *psr = &acrtc_state->stream->link->psr_settings;
[Severity: High]
This is a pre-existing issue, but could this lockless access to crtc->state lead to a use-after-free of the state and stream objects?
The enable_vblank hook (amdgpu_dm_crtc_set_vblank) is reached through the ioctl path where only vbl_lock is held, not crtc->mutex:
drm_crtc_get_sequence_ioctl()
drm_vblank_get()
amdgpu_dm_crtc_set_vblank()
Concurrently, a non-blocking atomic commit can swap crtc->state and free the old state asynchronously.
If the hook is preempted or delayed, the old state could be freed before dereferencing acrtc_state->stream here.
Could this also cause the dc_stream_retain(acrtc_state->stream) call further down in this function to corrupt memory by incrementing the refcount of a freed object?
Quoted 1 line
struct
replay_settings*pr =&acrtc_state->stream->link->replay_settings;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 29 lines · Samuel Pitoiset
amdgpu_dm_crtc_set_vblank()dereferencesacrtc_state->streamwhen vblank is enabled/queried fromDRM_IOCTL_MODE_CRTC_GET_SEQUENCEbefore a stream is attached to it.BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: amdgpu_dm_crtc_set_vblank+0x6b/0x4d0 [amdgpu] Call Trace: drm_vblank_enable drm_vblank_get drm_crtc_get_sequence_ioctl drm_ioctl_kernel drm_ioctlReproduced by running VKCTS with WSI tests enabled on RADV.
Guard the enable path on
acrtc_state->streambeing non-NULL, matching the existing checks in this function.Fixes 34d66bc7ff10 ("drm/amd/display: Fix Xorg desktop unresponsive on Replay panel")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable) · line 271
Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +1
-1@@ -268,7 +268,7 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable) irq_type =amdgpu_display_crtc_idx_to_irq_type (adev, acrtc->crtc_id); -if (enable) { +if (enable && acrtc_state->stream) {
LGTM.
+AMD display folks for visibility
Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0struct dc *dc = adev->dm.dc;struct drm_vblank_crtc *vblank =drm_crtc_vblank_crtc (crtc);struct psr_settings *psr = &acrtc_state->stream->link->psr_settings;
Alex Deucher
AppliedApplied. Thanks!
Quoted 49 lines · Melissa Wen
Quoted 29 lines · Samuel Pitoiset
amdgpu_dm_crtc_set_vblank()dereferencesacrtc_state->streamwhen vblank is enabled/queried fromDRM_IOCTL_MODE_CRTC_GET_SEQUENCEbefore a stream is attached to it.BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: amdgpu_dm_crtc_set_vblank+0x6b/0x4d0 [amdgpu] Call Trace: drm_vblank_enable drm_vblank_get drm_crtc_get_sequence_ioctl drm_ioctl_kernel drm_ioctlReproduced by running VKCTS with WSI tests enabled on RADV.
Guard the enable path on
acrtc_state->streambeing non-NULL, matching the existing checks in this function.Fixes 34d66bc7ff10 ("drm/amd/display: Fix Xorg desktop unresponsive on Replay panel")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable) · line 271
Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +1
-1@@ -268,7 +268,7 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable) irq_type =amdgpu_display_crtc_idx_to_irq_type (adev, acrtc->crtc_id); -if (enable) { +if (enable && acrtc_state->stream) {LGTM.
Reviewed-by Melissa Wen <[email protected]>+AMD display folks for visibility
Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0struct dc *dc = adev->dm.dc;struct drm_vblank_crtc *vblank =drm_crtc_vblank_crtc (crtc);struct psr_settings *psr = &acrtc_state->stream->link->psr_settings;