All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wentao Liang" <vulab@iscas.ac.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/mediatek: Fix pdev reference leak in mtk_drm_bind()
Date: Wed, 16 Sep 2026 17:51:45 +0000	[thread overview]
Message-ID: <20260916175145.F06751F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260916174058.2088709-1-vulab@iscas.ac.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/mediatek: UAF in mtk_crtc_create() due to dangling mutex_dev
--

commit 8e4c071af71a8f36ce4623ffd3129ead77322d8b
Author: Wentao Liang <vulab@iscas.ac.cn>

drm/mediatek: Fix pdev reference leak in mtk_drm_bind()

This commit addresses a device reference leak in mtk_drm_bind() by dropping
the reference to the disp-mutex device via put_device() when returning early
for non-master components.

> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -638,8 +638,10 @@ static int mtk_drm_bind(struct device *dev)
>  	private->mtk_drm_bound = true;
>  	private->dev = dev;
>  
> -	if (!mtk_drm_get_all_drm_priv(dev))
> +	if (!mtk_drm_get_all_drm_priv(dev)) {
> +		put_device(private->mutex_dev);
>  		return 0;
> +	}

[Severity: High]
Does this introduce a dangling pointer that could lead to a Use-After-Free?

When put_device(private->mutex_dev) is called, the reference is dropped, but
the pointer private->mutex_dev is left intact while returning success.

Later, when the master component binds, it initializes the CRTCs for all
components. In mtk_crtc_create(), it retrieves the non-master's private
structure and uses this pointer:

drivers/gpu/drm/mediatek/mtk_crtc.c:mtk_crtc_create() {
    ...
    mtk_crtc->mutex = mtk_mutex_get(priv->mutex_dev);
    ...
}

This accesses the potentially freed device memory in mtk_mutex_get():

drivers/soc/mediatek/mtk-mutex.c:mtk_mutex_get() {
    struct mtk_mutex_ctx *mtx = dev_get_drvdata(dev);
    ...
}

If the disp-mutex device is unregistered between the non-master and master
binds, could this lead to a memory corruption or panic? Should
private->mutex_dev be set to NULL after the put_device() call?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260916174058.2088709-1-vulab@iscas.ac.cn?part=1

      reply	other threads:[~2026-09-16 17:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 17:40 [PATCH] drm/mediatek: Fix pdev reference leak in mtk_drm_bind() Wentao Liang
2026-09-16 17:51 ` 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=20260916175145.F06751F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vulab@iscas.ac.cn \
    /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.