From: Melissa Wen <mwen@igalia.com>
To: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
kernel-dev@igalia.com, sashiko-bot@kernel.org
Subject: Re: [PATCH v4] drm: Fix drm_pending_vblank_event leak in error path for out_fence_ptr
Date: Fri, 11 Sep 2026 15:58:36 +0200 [thread overview]
Message-ID: <48a67b88-7ad8-4764-bab0-c226e9247dda@igalia.com> (raw)
In-Reply-To: <20260826-drm_pending_vblank_event_leak-v4-1-f8de8b996b9d@igalia.com>
On 26/08/2026 13:46, Thadeu Lima de Souza Cascardo wrote:
> When an out_fence_ptr is provided but DRM_MODE_PAGE_FLIP_EVENT is not
> set, a drm_pending_vblank_event will be allocated. If later, there is an
> allocation failure or another failure at setup_out_fence(), that event
> will not have base.fence set and it will not be released at
> complete_signaling().
>
> Release the event and set crtc_state->event to NULL just like in the
> DRM_MODE_PAGE_FLIP_EVENT case when there is a failure at
> drm_event_reserve_init(). That is, prepare_signaling() releases the
> event and there is nothing to be done at complete_signaling(). Use
> drm_event_cancel_free() as that will also undo drm_event_reserve_init()
> in case it has been called.
LGTM. Thanks!
Reviewed-by: Melissa Wen <mwen@igalia.com>
>
> Reported-by: sashiko-bot@kernel.org
> Closes: https://sashiko.dev/#/patchset/20260727-drm_crtc_atomic_commit_leak-v1-1-23d9948a9d7c@igalia.com?part=1
> Fixes: 92c715fca907 ("drm/atomic: Fix double free in drm_atomic_state_default_clear")
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
> ---
> Changes in v4:
> - Rename label to err_free_event.
> - Use crtc_state->event instead of a local variable e.
> - Link to v3: https://patch.msgid.link/20260817-drm_pending_vblank_event_leak-v3-1-7582b24447d0@igalia.com
>
> Changes in v3:
> - Use a label for the common exit pattern.
> - Link to v2: https://patch.msgid.link/20260729-drm_pending_vblank_event_leak-v2-1-a5074aae07df@igalia.com
>
> Changes in v2:
> - Fix UAF when DRM_MODE_PAGE_FLIP_EVENT is used.
> - Link to v1: https://patch.msgid.link/20260728-drm_pending_vblank_event_leak-v1-1-08429b920b16@igalia.com
> ---
> drivers/gpu/drm/drm_atomic_uapi.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c
> index ae7667d1072d..8c0eea2fed4a 100644
> --- a/drivers/gpu/drm/drm_atomic_uapi.c
> +++ b/drivers/gpu/drm/drm_atomic_uapi.c
> @@ -1458,10 +1458,12 @@ static int prepare_signaling(struct drm_device *dev,
> struct dma_fence *fence;
> struct drm_out_fence_state *f;
>
> + ret = -ENOMEM;
> +
> f = krealloc(*fence_state, sizeof(**fence_state) *
> (*num_fences + 1), GFP_KERNEL);
> if (!f)
> - return -ENOMEM;
> + goto err_free_event;
>
> memset(&f[*num_fences], 0, sizeof(*f));
>
> @@ -1470,12 +1472,12 @@ static int prepare_signaling(struct drm_device *dev,
>
> fence = drm_crtc_create_fence(crtc);
> if (!fence)
> - return -ENOMEM;
> + goto err_free_event;
>
> ret = setup_out_fence(&f[(*num_fences)++], fence);
> if (ret) {
> dma_fence_put(fence);
> - return ret;
> + goto err_free_event;
> }
>
> crtc_state->event->base.fence = fence;
> @@ -1531,6 +1533,11 @@ static int prepare_signaling(struct drm_device *dev,
> }
>
> return 0;
> +
> +err_free_event:
> + drm_event_cancel_free(dev, &crtc_state->event->base);
> + crtc_state->event = NULL;
> + return ret;
> }
>
> static void complete_signaling(struct drm_device *dev,
>
> ---
> base-commit: 4d4be202165e832d74849b4a68e289a2a377039c
> change-id: 20260728-drm_pending_vblank_event_leak-a36cedb296ba
>
> Best regards,
> --
> Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
>
next prev parent reply other threads:[~2026-09-11 13:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 11:46 [PATCH v4] drm: Fix drm_pending_vblank_event leak in error path for out_fence_ptr Thadeu Lima de Souza Cascardo
2026-09-11 13:58 ` Melissa Wen [this message]
2026-09-11 14:26 ` Melissa Wen
2026-09-11 14:43 ` Markus Elfring
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=48a67b88-7ad8-4764-bab0-c226e9247dda@igalia.com \
--to=mwen@igalia.com \
--cc=airlied@gmail.com \
--cc=cascardo@igalia.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel-dev@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.