Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: "CK Hu (胡俊光)" <ck.hu@mediatek.com>
To: "p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	"chunkuang.hu@kernel.org" <chunkuang.hu@kernel.org>,
	"johan@kernel.org" <johan@kernel.org>
Cc: "simona@ffwll.ch" <simona@ffwll.ch>,
	"make24@iscas.ac.cn" <make24@iscas.ac.cn>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH 1/2] drm/mediatek: fix potential OF node use-after-free
Date: Mon, 8 Sep 2025 03:41:47 +0000	[thread overview]
Message-ID: <741436f7fff7003aa629f8b330a248ddda592d62.camel@mediatek.com> (raw)
In-Reply-To: <20250829090345.21075-2-johan@kernel.org>

On Fri, 2025-08-29 at 11:03 +0200, Johan Hovold wrote:
> External email : Please do not click links or open attachments until you have verified the sender or the content.
> 
> 
> The for_each_child_of_node() helper drops the reference it takes to each
> node as it iterates over children and an explicit of_node_put() is only
> needed when exiting the loop early.
> 
> Drop the recently introduced bogus additional reference count decrement
> at each iteration that could potentially lead to a use-after-free.

Reviewed-by: CK Hu <ck.hu@mediatek.com>

> 
> Fixes: 1f403699c40f ("drm/mediatek: Fix device/node reference count leaks in mtk_drm_get_all_drm_priv")
> Cc: Ma Ke <make24@iscas.ac.cn>
> Cc: stable@vger.kernel.org
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index 34131ae2c207..3b02ed0a16da 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -388,11 +388,11 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
> 
>                 of_id = of_match_node(mtk_drm_of_ids, node);
>                 if (!of_id)
> -                       goto next_put_node;
> +                       continue;
> 
>                 pdev = of_find_device_by_node(node);
>                 if (!pdev)
> -                       goto next_put_node;
> +                       continue;
> 
>                 drm_dev = device_find_child(&pdev->dev, NULL, mtk_drm_match);
>                 if (!drm_dev)
> @@ -418,11 +418,10 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
>  next_put_device_pdev_dev:
>                 put_device(&pdev->dev);
> 
> -next_put_node:
> -               of_node_put(node);
> -
> -               if (cnt == MAX_CRTC)
> +               if (cnt == MAX_CRTC) {
> +                       of_node_put(node);
>                         break;
> +               }
>         }
> 
>         if (drm_priv->data->mmsys_dev_num == cnt) {
> --
> 2.49.1
> 


      reply	other threads:[~2025-09-08  3:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250829090345.21075-1-johan@kernel.org>
2025-08-29  9:03 ` [PATCH 1/2] drm/mediatek: fix potential OF node use-after-free Johan Hovold
2025-09-08  3:41   ` CK Hu (胡俊光) [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=741436f7fff7003aa629f8b330a248ddda592d62.camel@mediatek.com \
    --to=ck.hu@mediatek.com \
    --cc=airlied@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=johan@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=make24@iscas.ac.cn \
    --cc=matthias.bgg@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    /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