In the atomic commit pipeline, drm_atomic_helper_wait_for_vblanks() is called after drm_atomic_helper_commit_hw_done() has signaled completion of the hardware commit. Once drm_atomic_helper_swap_state() installs new_crtc_state into crtc->state and hw_done is signaled, the commit no longer owns new_crtc_state. A subsequent commit only waits on hw_done and flip_done before swapping out and freeing the previous crtc->state via drm_atomic_commit_default_clear(). If a nonblocking commit's commit_work worker is preempted between drm_atomic_helper_commit_hw_done() and drm_atomic_helper_wait_for_vblanks(), a concurrent synchronous commit can free new_crtc_state, causing a slab-use-after-free read when drm_atomic_helper_wait_for_vblanks() checks new_crtc_state->active. Add a bool active field to struct __drm_crtcs_state, reset it in drm_atomic_commit_default_clear(), and cache new_crtc_state->active into state->crtcs[i].active during drm_atomic_helper_swap_state() before hw_done can be signaled. Update drm_atomic_helper_wait_for_vblanks() to iterate with for_each_old_crtc_in_state() and check state->crtcs[i].active instead of dereferencing new_crtc_state. This keeps the flag within the lifetime of struct drm_atomic_commit without delaying hw_done until after vblank waits. Fixes: 9f2a7950e77a ("drm/atomic-helper: nonblocking commit support") Assisted-by: Gemini:gemini-4-hydrogen Gemini:gemini-4-carbon Gemini:gemini-3.8-flash syzbot Reported-by: syzbot+0f999d26a4fd79c3a23b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=0f999d26a4fd79c3a23b Link: https://syzkaller.appspot.com/ai_job?id=a0c63f30-6a0c-4071-bd8a-8aeba5423908 To: "David Airlie" To: To: "Maarten Lankhorst" To: "Maxime Ripard" To: "Simona Vetter" To: "Thomas Zimmermann" To: "Daniel Vetter" --- diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 9bb761eda..25414f803 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -318,6 +318,7 @@ void drm_atomic_commit_default_clear(struct drm_atomic_commit *state) state->crtcs[i].state_to_destroy = NULL; state->crtcs[i].old_state = NULL; state->crtcs[i].new_state = NULL; + state->crtcs[i].active = false; if (state->crtcs[i].commit) { drm_crtc_commit_put(state->crtcs[i].commit); diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index ccfe3840d..24c50f89b 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1890,7 +1890,7 @@ drm_atomic_helper_wait_for_vblanks(struct drm_device *dev, struct drm_atomic_commit *state) { struct drm_crtc *crtc; - struct drm_crtc_state *old_crtc_state, *new_crtc_state; + struct drm_crtc_state *old_crtc_state; int i, ret; unsigned int crtc_mask = 0; @@ -1901,8 +1901,8 @@ drm_atomic_helper_wait_for_vblanks(struct drm_device *dev, if (state->legacy_cursor_update) return; - for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { - if (!new_crtc_state->active) + for_each_old_crtc_in_state(state, crtc, old_crtc_state, i) { + if (!state->crtcs[i].active) continue; ret = drm_crtc_vblank_get(crtc); @@ -3333,6 +3333,7 @@ int drm_atomic_helper_swap_state(struct drm_atomic_commit *state, new_crtc_state->state = NULL; state->crtcs[i].state_to_destroy = old_crtc_state; + state->crtcs[i].active = new_crtc_state->active; crtc->state = new_crtc_state; if (new_crtc_state->commit) { diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index 3ae35b09c..5224e1a98 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -231,6 +231,17 @@ struct __drm_crtcs_state { s32 __user *out_fence_ptr; u64 last_vblank_count; + + /** + * @active: + * + * Cached value of &drm_crtc_state.active from @new_state, saved in + * drm_atomic_helper_swap_state() for use by + * drm_atomic_helper_wait_for_vblanks() after + * drm_atomic_helper_commit_hw_done() is called, when @new_state may + * already have been freed by a concurrent commit. + */ + bool active; }; struct __drm_connnectors_state { base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 -- This is an AI-generated patch subject to moderation. Reply with '#syz upstream' to Sign-off the patch as a human author and send it to the upstream kernel mailing lists. Reply with '#syz reject' to reject it ('#syz unreject' to undo). See https://goo.gle/syzbot-ai-patches for information about AI-generated patches. You can comment on the patch as usual, syzbot will try to address the comments and send a new version of the patch if necessary. syzbot engineers can be reached at syzkaller@googlegroups.com.