Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wentao Liang" <vulab@iscas.ac.cn>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH] of: unittest: Fix overlay node reference leak in of_notify()
Date: Thu, 17 Sep 2026 12:52:27 +0000	[thread overview]
Message-ID: <20260917125227.80DD31F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260917124457.2151809-1-vulab@iscas.ac.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] of: double-free of overlay device node in of_notify()
--

commit 2fb07d7f45ad569912e3b48cd4b44d5fe901b5ee
Author: Wentao Liang <vulab@iscas.ac.cn>

of: unittest: Fix overlay node reference leak in of_notify()

of_notify() takes a reference on nd->overlay but only drops it in the
default branch of the action switch. The PRE_APPLY, POST_APPLY,
PRE_REMOVE and POST_REMOVE branches return without dropping it, so the
reference is leaked on every notification. Move the of_node_put() to the
common exit path.

> The PRE_APPLY, POST_APPLY,
> PRE_REMOVE and POST_REMOVE branches return without dropping it, so the
> reference is leaked on every notification.

Is this description accurate?

Looking at of_find_node_by_name(), it explicitly consumes and drops the
reference count of its from argument. Since these branches all call
of_find_node_by_name(nd->overlay, ...), they appear to naturally drop the
reference on nd->overlay.

Could the commit message be clarified to explain what exactly is leaking?

> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index e255f54f4d760..3202781998808 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -3460,11 +3460,12 @@ static int of_notify(struct notifier_block *nb, unsigned long action,
>  		break;
>  
>  	default:			/* should not happen */
> -		of_node_put(nd->overlay);
>  		ret = -EINVAL;
>  		break;
>  	}
>  
> +	of_node_put(nd->overlay);

[Severity: High]
Does moving this of_node_put() into the common exit path cause a double-free
of nd->overlay?

Since the non-default branches already consume the reference via
of_find_node_by_name(nd->overlay, ...):

	case OF_OVERLAY_PRE_APPLY:
		found = of_find_node_by_name(nd->overlay, "test-unittest16");

will this unconditional put at the end of the function result in a second,
unbalanced put on all valid notification paths, potentially leading to a
use-after-free during the OF unittests?

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

      reply	other threads:[~2026-09-17 12:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 12:44 [PATCH] of: unittest: Fix overlay node reference leak in of_notify() Wentao Liang
2026-09-17 12:52 ` 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=20260917125227.80DD31F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox