Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Abdurrahman Hussain" <abdurrahman@nexthop.ai>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 5/6] of/overlay: rewrite /aliases path values to live-tree paths
Date: Wed, 22 Jul 2026 01:16:11 +0000	[thread overview]
Message-ID: <20260722011611.6AAD31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721-nh-of-alias-overlay-v4-5-8ad097e31e36@nexthop.ai>

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

New issues:
- [High] Valid absolute alias paths matching an overlay fragment name are silently corrupted in dup_and_fixup_symbol_prop().

Pre-existing issues:
- [High] Double free on add_changeset_property() error path for newly created nodes.
--

--- Patch [5]: [PATCH v4 5/6] of/overlay: rewrite /aliases path values to live-tree paths ---
commit b11eb3214c77837761c517184661f83716f7e731
Author: Abdurrahman Hussain <abdurrahman@nexthop.ai>

of/overlay: rewrite /aliases path values to live-tree paths

The commit rewrites overlay-internal alias values in /aliases to their
live-tree paths using dup_and_fixup_symbol_prop(). This ensures that
alias paths are resolvable after the overlay is applied.

> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
> index ad4e504825157..2a37b5260ba7a 100644
> --- a/drivers/of/overlay.c
> +++ b/drivers/of/overlay.c
> @@ -356,6 +356,19 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
>  		new_prop = dup_and_fixup_symbol_prop(ovcs, overlay_prop);
>  		if (IS_ERR(new_prop))
>  			return PTR_ERR(new_prop);
> +	} else if (!is_pseudo_property(overlay_prop->name) &&
> +		   of_node_is_aliases(target->np)) {
> +		/* rewrite overlay-internal alias values to live-tree paths */
> +		new_prop = dup_and_fixup_symbol_prop(ovcs, overlay_prop);

[Severity: High]
Can valid absolute alias paths be silently corrupted if they happen to match an
overlay fragment name?

When a user defines an absolute live-tree path in /aliases (e.g.,
serial0 = "/soc/serial_port@1234"), the path starts with "/soc".
dup_and_fixup_symbol_prop() calls __of_find_node_by_path(), which stops
matching at the first '/' delimiter.

If the overlay contains a fragment whose name matches this first component
(e.g. a hand-named fragment "soc"), __of_find_node_by_path() returns that
fragment node. Since the fragment contains an __overlay__ child, the function
assumes it's an overlay-internal path and computes an overlay_name_len
(e.g., 16 for "/soc/__overlay__"). It then blindly slices the string at that
offset, yielding "port@1234", and concatenates it with the fragment's
target_path.

Could this transform a valid absolute live-tree alias into a corrupted path?

> +		if (new_prop == ERR_PTR(-ENOMEM))
> +			return -ENOMEM;
> +		if (IS_ERR(new_prop)) {
> +			if (new_prop == ERR_PTR(-EINVAL))
> +				pr_warn("%pOF/%s is not a valid string; alias will be inert\n",
> +					target->np, overlay_prop->name);
> +			/* not overlay-internal: copy verbatim, consumers validate */
> +			new_prop = __of_prop_dup(overlay_prop, GFP_KERNEL);
> +		}
>  	} else {
>  		new_prop = __of_prop_dup(overlay_prop, GFP_KERNEL);
>  	}

[Severity: High]
This is a pre-existing issue, but is there a double free on this error path
for newly created nodes?

Looking at the code just below this in add_changeset_property():

	if (!prop) {
		if (!target->in_livetree) {
			new_prop->next = target->np->deadprops;
			target->np->deadprops = new_prop;
		}
		ret = of_changeset_add_property(&ovcs->cset, target->np,
						new_prop);
	}
    
	[ ... ]

	if (ret)
		__of_prop_free(new_prop);

If the target node is newly created (!target->in_livetree), new_prop is
prepended to target->np->deadprops. If of_changeset_add_property() fails
(e.g. -ENOMEM), __of_prop_free() is called here.

However, new_prop remains linked in the node's deadprops list. When the
error propagates, the overlay application aborts and rolls back. The rollback
destroys the target node attachment, and of_node_release() calls
property_list_free() on the node's deadprops list, freeing new_prop a second
time.

Will this result in a double-free during node destruction?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721-nh-of-alias-overlay-v4-0-8ad097e31e36@nexthop.ai?part=5

  reply	other threads:[~2026-07-22  1:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  1:01 [PATCH v4 0/6] of: teach overlay code to keep /aliases in sync Abdurrahman Hussain
2026-07-22  1:01 ` [PATCH v4 1/6] of: resolve alias-prefixed paths under devtree_lock Abdurrahman Hussain
2026-07-22  1:19   ` sashiko-bot
2026-07-22  7:30   ` Krzysztof Kozlowski
2026-07-22  1:01 ` [PATCH v4 2/6] of: incrementally update /aliases lookup on reconfig notifications Abdurrahman Hussain
2026-07-22  7:35   ` Krzysztof Kozlowski
2026-07-22  1:01 ` [PATCH v4 3/6] of/overlay: look up absolute target-paths absolutely Abdurrahman Hussain
2026-07-22  1:01 ` [PATCH v4 4/6] of/overlay: return ERR_PTR from dup_and_fixup_symbol_prop() Abdurrahman Hussain
2026-07-22  1:13   ` sashiko-bot
2026-07-22  7:36   ` Krzysztof Kozlowski
2026-07-22  1:01 ` [PATCH v4 5/6] of/overlay: rewrite /aliases path values to live-tree paths Abdurrahman Hussain
2026-07-22  1:16   ` sashiko-bot [this message]
2026-07-22  1:01 ` [PATCH v4 6/6] of: unittest: cover /aliases updates from overlay apply/revert Abdurrahman Hussain

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=20260722011611.6AAD31F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=abdurrahman@nexthop.ai \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.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