Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/i915: intel_crtc_create_state() causes UAF in
  drm_mode_config_reset()
--

commit c5121c9ae2a50c81961f73b900dacfb69a94085f
Author: Maxime Ripard <[email protected]>

drm/i915: Implement CRTC atomic_create_state

This commit adds an atomic_create_state callback for i915 CRTCs by
wrapping intel_crtc_state_alloc() and wiring it into INTEL_CRTC_FUNCS.

> diff --git a/drivers/gpu/drm/i915/display/intel_crtc.c 
> b/drivers/gpu/drm/i915/display/intel_crtc.c
> index 10ed9bdfee763..7bb3caf913106 100644
> --- a/drivers/gpu/drm/i915/display/intel_crtc.c
> +++ b/drivers/gpu/drm/i915/display/intel_crtc.c
> @@ -177,6 +177,17 @@ struct intel_crtc_state *intel_crtc_state_alloc(struct 
> intel_crtc *crtc)
>       return crtc_state;
>  }
>  
> +static struct drm_crtc_state *intel_crtc_create_state(struct drm_crtc *crtc)
> +{
> +     struct intel_crtc_state *crtc_state;
> +
> +     crtc_state = intel_crtc_state_alloc(to_intel_crtc(crtc));
> +     if (!crtc_state)
> +             return ERR_PTR(-ENOMEM);
> +
> +     return &crtc_state->uapi;
> +}
> +
>  void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
>                           struct intel_crtc *crtc)
>  {
> @@ -243,6 +254,7 @@ static int intel_crtc_late_register(struct drm_crtc *crtc)
>       .set_config = drm_atomic_helper_set_config, \
>       .destroy = intel_crtc_destroy, \
>       .page_flip = drm_atomic_helper_page_flip, \
> +     .atomic_create_state = intel_crtc_create_state, \

[Severity: High]
Does wiring up .atomic_create_state cause a use-after-free of
struct intel_crtc_state when drm_mode_config_reset() runs on resume or
Xe D3cold exit?

When crtc->funcs->atomic_create_state is populated,
drm_mode_config_reset() calls
drm_mode_config_crtc_reset_with_create_state(), which destroys
crtc->state via atomic_destroy_state() and replaces it with a new state
from atomic_create_state().  Both i915 and Xe call
drm_mode_config_reset() in i915_drm_resume(), xe_display_pm_resume(),
and xe_display_disable_d3cold(), where INTEL_CRTC_FUNCS previously had
neither .reset nor .atomic_create_state.

First, replacing crtc->base.state without updating intel_crtc->config
leaves crtc->config as a dangling pointer to the freed state.  During
intel_modeset_setup_hw_state() on system resume,
intel_modeset_readout_hw_state() resets crtc->base.state in place and
paths such as bxt_dsi_get_config() or
intel_crtc_disable_noatomic_complete() -> intel_update_watermarks() ->
intel_crtc_active() dereference the freed crtc->config before
intel_atomic_commit_tail() updates it.

Second, on Xe D3cold exit, an atomic commit records
state->crtcs[i].old_state = crtc->state before intel_atomic_commit()
calls intel_display_rpm_get(), which wakes the device and runs
xe_display_disable_d3cold() -> drm_mode_config_reset().  That frees
old_crtc_state mid-commit, so intel_atomic_setup_commit() and
drm_atomic_helper_swap_state() read and write freed memory, hit
WARN_ON(crtc->state != old_crtc_state), leak the newly allocated state,
and double free old_crtc_state when the commit is put.  Even outside an
atomic commit, xe_display_disable_d3cold() runs unlocked without state
restoration and wipes active CRTC state.

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/20261124-drm-i915-conversion-state-readout-v1-0-b7132f726...@kernel.org?part=3

Reply via email to