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 <[email protected]> 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/[email protected]?part=3
