From: sashiko-bot@kernel.org
To: "Abdurrahman Hussain" <abdurrahman@nexthop.ai>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v8 3/6] of: hold a reference on of_aliases during alias path resolution
Date: Wed, 14 Oct 2026 23:32:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-172021@kernel.org> (raw)
In-Reply-To: <20261014-nh-of-alias-overlay-v8-3-0f74f05ac762@nexthop.ai>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] of: lockless TOCTOU UAF reading of_aliases against concurrent overlay detach
--
commit 66550105e7f11866d2d8f8f454161df1bb855fa8
Author: Abdurrahman Hussain <abdurrahman@nexthop.ai>
of: hold a reference on of_aliases during alias path resolution
This commit takes a reference across the walk of the of_aliases property
list in of_find_node_opts_by_path() to prevent accessing stale views. It
also validates the alias value before resolving it to avoid crashes on
malformed boot FDTs.
> The pointer load itself needs no locking:
> of_aliases always holds a reference on the node it points to, so a
> reader that observes a non-NULL pointer observes a live node. A later
> patch in this series clears of_aliases and drops that reference when
> the node is detached at runtime; the detach path holds its own
> references across the transition.
[Severity: High]
Is this description accurate regarding the lack of locking for the pointer
load?
While the detach path holds a reference during the transition, if
of_changeset_destroy() runs immediately after the revert without any RCU
grace period, it could drop the final reference to the node.
Since of_node_release() uses kfree() and not kfree_rcu(), the object is
destroyed immediately, which leaves a race window open.
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 57313055d9ede..6a6d9f8439dd1 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
[ ... ]
> @@ -1010,16 +1012,21 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
> p = separator;
> len = p - path;
>
> - /* of_aliases must not be NULL */
> - if (!of_aliases)
> + aliases = of_node_get(of_aliases);
[Severity: High]
Can this lockless read lead to a TOCTOU race and a use-after-free?
If a thread calls of_find_node_opts_by_path() and reads the global of_aliases
pointer, but gets preempted before taking the reference in of_node_get():
Thread 1
of_find_node_opts_by_path()
aliases = of_aliases;
<preempted>
Thread 2 could concurrently remove an overlay containing a dynamically
created /aliases node. The detach notifier clears of_aliases = NULL and
drops its reference, and then of_changeset_destroy() drops the final
reference to the node, freeing it synchronously via kfree().
When Thread 1 resumes:
Thread 1
of_node_get(aliases);
Could this lead to dereferencing node->kobj on freed memory?
Should this read be protected by devtree_lock or similar synchronization to
prevent the node from being freed before the reference is taken?
> + if (!aliases)
> return NULL;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261014-nh-of-alias-overlay-v8-0-0f74f05ac762@nexthop.ai?part=3
next prev parent reply other threads:[~2026-10-14 23:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 23:17 [PATCH v8 0/6] of: teach overlay code to keep /aliases in sync Abdurrahman Hussain
2026-10-14 23:17 ` [PATCH v8 1/6] of/overlay: look up absolute target-paths absolutely Abdurrahman Hussain
2026-10-14 23:17 ` [PATCH v8 2/6] of/overlay: return ERR_PTR from dup_and_fixup_symbol_prop() Abdurrahman Hussain
2026-10-14 23:17 ` [PATCH v8 3/6] of: hold a reference on of_aliases during alias path resolution Abdurrahman Hussain
2026-10-14 23:32 ` sashiko-bot [this message]
2026-10-14 23:17 ` [PATCH v8 4/6] of: update /aliases lookup on reconfig notifications Abdurrahman Hussain
2026-10-14 23:29 ` sashiko-bot
2026-10-14 23:17 ` [PATCH v8 5/6] of/overlay: rewrite /aliases path values to live-tree paths Abdurrahman Hussain
2026-10-14 23:27 ` sashiko-bot
2026-10-14 23:17 ` [PATCH v8 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=sashiko-outbox-172021@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