dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Johan Jonker" <jbx6244@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/rockchip: rk3066_hdmi: convert to devm_drm_bridge_alloc() API
Date: Mon, 24 Aug 2026 10:30:54 +0000	[thread overview]
Message-ID: <20260824103055.418481F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260824-drm-v2-1-7f9273c6020b@gmail.com>

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

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but there is a Use-After-Free vulnerability on the error path of `rk3066_hdmi_bind()`. If `rk3066_hdmi_register()` fails, the code jumps to `err_disable_hclk`, skipping the encoder cleanup label `err_cleanup_hdmi`. Since the DRM encoder was added to the DRM device's list during `drm_encoder_init()` but is not removed, and the `hdmi` struct containing the encoder is freed by devres upon bind failure, the DRM core retains a dangling pointer. This will cause a Use-After-Free when the DRM core later iterates over the encoder list or during teardown.
--

--- Patch [1]: [PATCH v2] drm/rockchip: rk3066_hdmi: convert to devm_drm_bridge_alloc() API ---
commit bdad67e77f8f693946bd674b1a40ce7af3ce54c3
Author: Hüseyin BIYIK <boogiepop@gmx.com>

drm/rockchip: rk3066_hdmi: convert to devm_drm_bridge_alloc() API

This commit converts the rk3066_hdmi driver to use devm_drm_bridge_alloc()
for allocating DRM bridges. This conversion was missed during the initial
conversion of all bridges to the new API.

> diff --git a/drivers/gpu/drm/rockchip/rk3066_hdmi.c b/drivers/gpu/drm/rockchip/rk3066_hdmi.c
> index f28d6a883e099..39c65ee07caac 100644
> --- a/drivers/gpu/drm/rockchip/rk3066_hdmi.c
> +++ b/drivers/gpu/drm/rockchip/rk3066_hdmi.c
[ ... ]
> @@ -747,9 +746,10 @@ static int rk3066_hdmi_bind(struct device *dev, struct device *master,
>  	int irq;
>  	int ret;
>  
> -	hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
> -	if (!hdmi)
> -		return -ENOMEM;
> +	hdmi = devm_drm_bridge_alloc(dev, struct rk3066_hdmi, bridge,
> +				     &rk3066_hdmi_bridge_funcs);
> +	if (IS_ERR(hdmi))
> +		return PTR_ERR(hdmi);

[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the
allocation of the hdmi struct in rk3066_hdmi_bind() inside
drivers/gpu/drm/rockchip/rk3066_hdmi.c, I noticed a potential
use-after-free on the error path.

If rk3066_hdmi_register() fails after drm_encoder_init() has been called,
the error path in rk3066_hdmi_bind() jumps to err_disable_hclk:

	ret = rk3066_hdmi_register(drm, hdmi);
	if (ret)
		goto err_disable_hclk;

This bypasses the err_cleanup_hdmi label which destroys the encoder:

err_cleanup_hdmi:
	hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);
err_disable_hclk:
	clk_disable_unprepare(hdmi->hclk);

Since the encoder was added to the DRM device's internal lists during
drm_encoder_init(), and the devm-allocated hdmi struct will be freed when
rk3066_hdmi_bind() returns an error, does this leave a dangling pointer in
the DRM core that will cause a use-after-free when the list is iterated or
torn down?

>  
>  	hdmi->dev = dev;
>  	hdmi->drm_dev = drm;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824-drm-v2-1-7f9273c6020b@gmail.com?part=1

  reply	other threads:[~2026-08-24 10:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 10:21 [PATCH v2] drm/rockchip: rk3066_hdmi: convert to devm_drm_bridge_alloc() API Johan Jonker via B4 Relay
2026-08-24 10:30 ` sashiko-bot [this message]
2026-09-03 15:12 ` Heiko Stübner
2026-09-03 20:44   ` Johan Jonker
2026-09-03 21:09     ` Heiko Stübner

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=20260824103055.418481F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jbx6244@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