All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jason Xiang" <jx@jasonxiang.net>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/logicvc: Fix layer_node reference leak in logicvc_layers_init()
Date: Thu, 25 Jun 2026 02:44:07 +0000	[thread overview]
Message-ID: <20260625024407.970D41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260625023359.26011-1-jx@jasonxiang.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-after-free on DRM mode objects (plane, CRTC) due to `devm_kzalloc` memory allocation combined with `drmm_mode_config_init` lifecycle management, and incorrect explicit freeing via `devm_kfree()`.
--

commit 0b8e61159a658d64dd9da573a68be2d6791f659b
Author: Jason Xiang <jx@jasonxiang.net>

drm/logicvc: Fix layer_node reference leak in logicvc_layers_init()

This commit fixes a reference leak on layer_node in the error path of
logicvc_layers_init() by adding an of_node_put() call.

> diff --git a/drivers/gpu/drm/logicvc/logicvc_layer.c b/drivers/gpu/drm/logicvc/logicvc_layer.c
> index 7f5ba000188ab..e83a2aafed779 100644
> --- a/drivers/gpu/drm/logicvc/logicvc_layer.c
> +++ b/drivers/gpu/drm/logicvc/logicvc_layer.c
> @@ -613,6 +613,7 @@ int logicvc_layers_init(struct logicvc_drm *logicvc)
>  
>  		ret = logicvc_layer_init(logicvc, layer_node, index);
>  		if (ret) {
> +			of_node_put(layer_node);
>  			of_node_put(layers_node);
>  			goto error;

[Severity: High]
This isn't a bug introduced by this patch, but does jumping to this error
label cause a use-after-free on DRM mode objects?

Looking at logicvc_layer_init(), layers are allocated with devm_kzalloc():

drivers/gpu/drm/logicvc/logicvc_layer.c:logicvc_layer_init() {
	...
	layer = devm_kzalloc(dev, sizeof(*layer), GFP_KERNEL);
	...
	ret = drm_universal_plane_init(drm_dev, &layer->drm_plane, ...);
	...
}

If an error occurs in logicvc_layers_init() after some layers are
successfully initialized, it jumps to the error label:

drivers/gpu/drm/logicvc/logicvc_layer.c:logicvc_layers_init() {
	...
error:
	list_for_each_entry_safe(layer, next, &logicvc->layers_list, list)
		logicvc_layer_fini(logicvc, layer);
	...
}

Then logicvc_layer_fini() explicitly frees the layer memory using devm_kfree():

drivers/gpu/drm/logicvc/logicvc_layer.c:logicvc_layer_fini() {
	...
	list_del(&layer->list);
	devm_kfree(dev, layer);
}

Since the layer was registered with drm_universal_plane_init(), manually
freeing the layer without calling drm_plane_cleanup() leaves a dangling
pointer in drm_dev->mode_config.plane_list.

Additionally, on driver unbind or probe unwind, devres cleans up memory
before drmm_mode_config_init() runs its cleanup, which could iterate over
freed objects. A similar pattern appears to exist for the CRTC allocation
in logicvc_crtc_init().

Does this driver need to be updated to use drmm_universal_plane_alloc() and
similar drmm_* helpers to safely tie the object lifecycles to the DRM device
instead of devres?

>  		}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260625023359.26011-1-jx@jasonxiang.net?part=1

      reply	other threads:[~2026-06-25  2:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25  2:33 [PATCH] drm/logicvc: Fix layer_node reference leak in logicvc_layers_init() Jason Xiang
2026-06-25  2:44 ` sashiko-bot [this message]

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=20260625024407.970D41F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jx@jasonxiang.net \
    --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 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.