dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oarora Etimis" <oaroraetimis@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 3/7] drm/vkms: use the colorop states of the state being composed
Date: Sat, 28 Nov 2026 17:31:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-238883@kernel.org> (raw)
In-Reply-To: <20261128-colorop-v1-3-dd79919f822b@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/vkms: use-after-free in vkms_plane_colorops_update() on
  nonblocking commit
--

commit 838e4d7bd5412801fae0f59aa09cd076672b38c7
Author: Oarora Etimis <oaroraetimis@gmail.com>

drm/vkms: use the colorop states of the state being composed

This commit copies each active plane's colorop state and LUT blob reference
into vkms_plane_state during vkms_crtc_atomic_flush() so the asynchronous
composer worker does not read drm_colorop::state directly.

> diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
> index 7d18178d53205..e7ea487187bce 100644
> --- a/drivers/gpu/drm/vkms/vkms_crtc.c
> +++ b/drivers/gpu/drm/vkms/vkms_crtc.c
> @@ -5,6 +5,7 @@
>  #include <drm/drm_atomic.h>
>  #include <drm/drm_atomic_helper.h>
>  #include <drm/drm_blend.h>
> +#include <drm/drm_colorop.h>
>  #include <drm/drm_managed.h>
>  #include <drm/drm_print.h>
>  #include <drm/drm_probe_helper.h>
> @@ -186,11 +187,43 @@ static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
>  	spin_lock_irq(&vkms_output->lock);
>  }
>  
> +static void vkms_plane_colorops_update(struct vkms_plane_state *plane_state,
> +				       struct drm_atomic_commit *commit)
> +{
> +	struct drm_colorop *colorop;
> +	size_t slot = 0;
> +
> +	/*
> +	 * The plane state is freshly allocated for this commit, so its
> +	 * colorop_states array is zero and holds nothing to release.
> +	 */
> +	for (colorop = plane_state->base.base.color_pipeline;
> +	     colorop && slot < ARRAY_SIZE(plane_state->colorop_states);
> +	     colorop = colorop->next) {
> +		struct drm_colorop_state *colorop_state;
> +		struct vkms_colorop_state *state;
> +
> +		colorop_state = drm_atomic_get_new_colorop_state(commit, colorop);
> +		if (!colorop_state)
> +			break;
> +
> +		state = &plane_state->colorop_states[slot++];
> +		state->colorop = colorop;
> +		state->bypass = colorop_state->bypass;
> +		state->curve_1d_type = colorop_state->curve_1d_type;
> +		state->multiplier = colorop_state->multiplier;
> +
> +		if (colorop_state->data)
> +			state->data = drm_property_blob_get(colorop_state->data);
> +	}
> +}
> +
>  static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
>  				   struct drm_atomic_commit *state)
>  	__releases(&vkms_output->lock)
>  {
>  	struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
> +	struct vkms_crtc_state *crtc_state = to_vkms_crtc_state(crtc->state);
>  
>  	if (crtc->state->event) {
>  		spin_lock(&crtc->dev->event_lock);
> @@ -205,7 +238,15 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
>  		crtc->state->event = NULL;
>  	}
>  
> -	vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
> +	/*
> +	 * Capture the color operations of this commit: drm_colorop::state is
> +	 * the current value of the colorop, not the one this frame was built
> +	 * from, and the composer runs asynchronously, so it must not read it.
> +	 */
> +	for (size_t i = 0; i < crtc_state->num_active_planes; i++)
> +		vkms_plane_colorops_update(crtc_state->active_planes[i], state);

[Severity: High]
Can vkms_plane_colorops_update() read a freed drm_colorop_state and take a
reference on an already-released data blob when commit 1 is nonblocking?

CPU0 (commit 1, nonblocking)      CPU1 (commit 2, unchanged colorop prop)
drm_mode_atomic_ioctl()
  drm_atomic_helper_commit(s1)
    drm_atomic_helper_swap_state(s1)
      colorop->state = cs1
    queue_work(s1->commit_work)
  drm_modeset_drop_locks()
                                  drm_mode_atomic_ioctl()
                                    drm_atomic_set_property()
                                      drm_atomic_get_colorop_state(s2)
                                      /* !replaced: plane not added to s2 */
                                    drm_atomic_helper_commit(s2)
                                      /* no plane/CRTC in s2, no stall */
                                      drm_atomic_helper_swap_state(s2)
                                        s2->...->state_to_destroy = cs1
                                    drm_atomic_commit_put(s2)
                                      drm_colorop_Passed/destroy_state(cs1)
                                        drm_property_blob_put(cs1->data)
                                        kfree(cs1)
commit_work()
  drm_atomic_helper_wait_for_fences()
  vkms_atomic_commit_tail(s1)
    ...
      vkms_crtc_atomic_flush()
        vkms_plane_colorops_update()
          cs1->bypass             <-- use-after-free
          drm_property_blob_get(cs1->data)

For a nonblocking commit, drm_atomic_helper_swap_state() publishes
commit 1's new_colorop_state into colorop->state and drops the modeset
locks before commit_work runs vkms_atomic_commit_tail().  If commit 1 is
still waiting (for example in drm_atomic_helper_wait_for_fences() on an
IN_FENCE_FD) when commit 2 writes the same value the colorop property
already has, drm_atomic_set_property() adds the colorop to commit 2
without adding its plane or CRTC.  Because drm_colorop_state has no
drm_crtc_commit dependency tracking, commit 2 swaps and frees commit 1's
new_colorop_state immediately, before commit 1 reaches
vkms_crtc_atomic_flush().

Capturing colorop_states during atomic_check before
drm_atomic_helper_swap_state(), while plane->mutex is still held, would
avoid this race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-colorop-v1-0-dd79919f822b@gmail.com?part=3

  reply	other threads:[~2026-11-28 17:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 17:15 [PATCH 0/7] drm/vkms: complete the plane color pipeline Oarora Etimis
2026-11-28 17:15 ` [PATCH 1/7] drm/vkms: add the colorops of a plane that is being enabled Oarora Etimis
2026-11-28 17:15 ` [PATCH 2/7] drm/vkms: free the colorop whose initialization failed Oarora Etimis
2026-11-28 17:27   ` sashiko-bot
2026-11-28 17:15 ` [PATCH 3/7] drm/vkms: use the colorop states of the state being composed Oarora Etimis
2026-11-28 17:31   ` sashiko-bot [this message]
2026-11-28 17:15 ` [PATCH 4/7] drm/vkms: add a programmable 1D LUT colorop Oarora Etimis
2026-11-28 17:25   ` sashiko-bot
2026-11-28 17:15 ` [PATCH 5/7] drm/vkms: add a 3D " Oarora Etimis
2026-11-28 17:34   ` sashiko-bot
2026-11-28 17:15 ` [PATCH 6/7] drm/vkms: add a multiplier colorop Oarora Etimis
2026-11-28 17:31   ` sashiko-bot
2026-11-28 17:15 ` [PATCH 7/7] drm/vkms: add KUnit coverage for the 3D LUT and multiplier colorops Oarora Etimis
2026-11-29 12:37 ` [PATCH 0/7] drm/vkms: complete the plane color pipeline Louis Chauvet

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-238883@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=oaroraetimis@gmail.com \
    --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