mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Myeonghun Pak" <mhun512@gmail.com>
Cc: neil.armstrong@linaro.org, linux-amlogic@lists.infradead.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/meson: clean up KMS polling on register failure
Date: Tue, 04 Aug 2026 15:37:39 +0000	[thread overview]
Message-ID: <20260804153740.5667B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804150802.45262-1-mhun512@gmail.com>

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

Pre-existing issues:
- [High] NULL pointer dereference in error path if devm_kzalloc() fails to allocate priv
- [High] Use-After-Free due to DRM objects allocated with devm_kzalloc instead of drmm_kzalloc
- [High] Kernel panic/Resource leak on driver unload if initialized without component framework
- [High] Use-After-Free of devm-allocated bridges due to leakage in the global bridge_list
- [High] Use-After-Free due to drm_dev_put() dropping the DRM device before component_unbind_all() accesses it
--

--- Patch [1]: [PATCH v2] drm/meson: clean up KMS polling on register failure ---
commit 86a9a25dd06d99107bc269bc3d6752c0df753219
Author: Myeonghun Pak <mhun512@gmail.com>

drm/meson: clean up KMS polling on register failure

This commit ensures that drm_kms_helper_poll_fini() is called when
drm_dev_register() fails in meson_drv_bind_master(). This stops the
KMS polling helper before the probe error path unwinds the IRQ and
frees the DRM device.

Link: https://lore.kernel.org/r/20260524160657.17802-1-mhun512@gmail.com

> diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
> index 49ff9f1f16d32..bcc36f2cdc9a9 100644
> --- a/drivers/gpu/drm/meson/meson_drv.c
> +++ b/drivers/gpu/drm/meson/meson_drv.c
> @@ -351,8 +351,10 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
>  	platform_set_drvdata(pdev, priv);
>  
>  	ret = drm_dev_register(drm, 0);
> -	if (ret)
> +	if (ret) {
> +		drm_kms_helper_poll_fini(drm);
>  		goto uninstall_irq;
> +	}
>  
>  	drm_client_setup(drm, NULL);
>  

[Severity: High]
This isn't a bug introduced by this patch, but can this error path in
meson_drv_bind_master() trigger a NULL pointer dereference?

If devm_kzalloc() fails to allocate memory for priv, it jumps to free_drm:

drivers/gpu/drm/meson/meson_drv.c:meson_drv_bind_master() {
	...
	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	if (!priv) {
		ret = -ENOMEM;
		goto free_drm;
	}
	...
}

At the free_drm label, meson_encoder_dsi_remove(priv) is called, which
immediately dereferences the NULL priv pointer:

drivers/gpu/drm/meson/meson_encoder_dsi.c:meson_encoder_dsi_remove() {
	...
	if (priv->encoders[MESON_ENC_DSI]) {
	...
}

[Severity: High]
This is a pre-existing issue, but does using devm_kzalloc() for the DRM plane
risk a use-after-free?

drivers/gpu/drm/meson/meson_plane.c:meson_plane_create() {
	...
	meson_plane = devm_kzalloc(priv->drm->dev, sizeof(*meson_plane),
				   GFP_KERNEL);
	...
}

Because devm_kzalloc() ties the memory lifetime to the platform device, if
the device is unbound (e.g., via sysfs) while userspace still holds a DRM
file descriptor open, devres frees the plane structure. Later, when the file
descriptor is closed, the DRM core cleans up and accesses this already-freed
structure to invoke its .destroy hook.

[Severity: High]
This isn't a bug introduced by this patch, but does the driver unload sequence
leak resources if initialized without the component framework?

drivers/gpu/drm/meson/meson_drv.c:meson_drv_probe() {
	...
	if (count && !match)
		return meson_drv_bind_master(&pdev->dev, false);
	...
}

If no matching components are found, it bypasses the component framework.
However, during driver teardown, it only cleans up via the component
framework:

drivers/gpu/drm/meson/meson_drv.c:meson_drv_remove() {
	...
	component_master_del(&pdev->dev, &meson_drv_master_ops);
}

Because it was never added as a component master, meson_drv_unbind() is never
called, leaving the DRM device registered and memory allocated while the module
is unloaded.

[Severity: High]
This is a pre-existing issue, but if drm_simple_encoder_init() fails, does this
leak the bridge in the global bridge_list?

drivers/gpu/drm/meson/meson_encoder_dsi.c:meson_encoder_dsi_probe() {
	...
	drm_bridge_add(&meson_encoder_dsi->bridge);

	meson_encoder_dsi->priv = priv;

	/* Encoder */
	ret = drm_simple_encoder_init(priv->drm, &meson_encoder_dsi->encoder,
				      DRM_MODE_ENCODER_DSI);
	if (ret)
		return dev_err_probe(priv->dev, ret,
				     "Failed to init DSI encoder\n");
	...
}

If drm_simple_encoder_init() fails, the function returns an error without
calling drm_bridge_remove(). Because the bridge is a devm allocation, its
memory is freed on probe failure, but a dangling pointer remains in the
global bridge_list.

[Severity: High]
This isn't a bug introduced by this patch, but can the teardown order cause a
use-after-free when cleaning up components?

drivers/gpu/drm/meson/meson_drv.c:meson_drv_bind_master() {
	...
free_drm:
	drm_dev_put(drm);

	meson_encoder_dsi_remove(priv);
	meson_encoder_hdmi_remove(priv);
	meson_encoder_cvbs_remove(priv);

	if (has_components)
		component_unbind_all(dev, drm);
	...
}

The call to drm_dev_put(drm) drops the final reference and frees the drm
device. Then component_unbind_all(dev, drm) passes this newly freed drm pointer
to the unbind callbacks, which may attempt to access it. This same sequence
also exists in meson_drv_unbind().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260804150802.45262-1-mhun512@gmail.com?part=1

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

      reply	other threads:[~2026-08-04 15:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24 16:01 [PATCH] " Myeonghun Pak
2026-05-24 16:25 ` sashiko-bot
2026-05-24 16:35   ` Myeonghun Pak
2026-05-26  7:16 ` Neil Armstrong
2026-05-27  2:17 ` kernel test robot
2026-05-27  3:22 ` kernel test robot
2026-08-04 15:08 ` [PATCH v2] " Myeonghun Pak
2026-08-04 15:37   ` 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=20260804153740.5667B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=mhun512@gmail.com \
    --cc=neil.armstrong@linaro.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

Powered by JetHome