Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maxime Ripard" <mripard@kernel.org>
Cc: intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 3/6] drm/i915: Implement CRTC atomic_create_state
Date: Tue, 24 Nov 2026 11:26:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-231047@kernel.org> (raw)
In-Reply-To: <20261124-drm-i915-conversion-state-readout-v1-3-b7132f72644d@kernel.org>

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 <mripard@kernel.org>

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-b7132f72644d@kernel.org?part=3

  reply	other threads:[~2026-11-24 11:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 10:59 [PATCH 0/6] drm/i915: Support DRM_MODE_ATOMIC_RESET Maxime Ripard
2026-11-24 10:59 ` [PATCH 1/6] drm/atomic-state-helper: Provide more STATE_CHECK_* variants Maxime Ripard
2026-11-24 10:59 ` [PATCH 2/6] drm/i915: Use the STATE_CHECK_* macros in the pipe config comparison Maxime Ripard
2026-11-24 11:23   ` Jani Nikula
2026-11-24 10:59 ` [PATCH 3/6] drm/i915: Implement CRTC atomic_create_state Maxime Ripard
2026-11-24 11:26   ` sashiko-bot [this message]
2026-11-24 10:59 ` [PATCH 4/6] drm/i915: Implement plane atomic_create_state Maxime Ripard
2026-11-24 11:19   ` sashiko-bot
2026-11-24 10:59 ` [PATCH 5/6] drm/i915: Implement connector atomic_create_state Maxime Ripard
2026-11-24 11:21   ` sashiko-bot
2026-11-24 10:59 ` [PATCH 6/6] drm/i915: Carry the current state over created states Maxime Ripard
2026-11-24 11:40   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-231047@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=mripard@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox