devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Abdurrahman Hussain" <abdurrahman@nexthop.ai>
To: "Rob Herring" <robh@kernel.org>,
	"Abdurrahman Hussain" <abdurrahman@nexthop.ai>
Cc: "Saravana Kannan" <saravanak@kernel.org>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Shawn Guo" <shawn.guo@linaro.org>,
	"Grant Likely" <grant.likely@secretlab.ca>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 02/10] of: hold a reference on of_aliases during alias path resolution
Date: Thu, 27 Aug 2026 13:20:35 -0700	[thread overview]
Message-ID: <DL0074F6I9HO.5OPQ5ABY74KS@nexthop.ai> (raw)
In-Reply-To: <20260827145237.GA3212208-robh@kernel.org>

On Thu Aug 27, 2026 at 7:52 AM PDT, Rob Herring wrote:
> On Wed, Aug 05, 2026 at 01:31:01PM -0700, Abdurrahman Hussain wrote:
>> of_find_node_opts_by_path() walks the property list of of_aliases
>> without taking a reference on the node and passes pp->value straight
>> to of_find_node_by_path().
>> 
>> Take a reference across the walk. The walk itself stays lock-free
>> like every other property iteration: it can race property surgery and
>> see a stale view (a removed property's ->next is repointed at the
>> deadprops list), but nothing it can reach is freed while the node
>> reference is held. devtree_lock covers only the pointer load,
>> pairing it with a later patch in this series that clears of_aliases
>> and drops its reference when the node is detached at runtime.
>> 
>> Validate the value before resolving it. of_alias_value_ok() requires
>> a non-empty, NUL-terminated, absolute path:
>> 
>>   - an empty property has a NULL value and crashes in strchr()
>>   - a value without a NUL inside the property is read past its end
>>   - a relative value naming another alias (loop = "loop") recurses
>>     through of_find_node_by_path() until the stack is exhausted
>> 
>> All three are reachable with a malformed boot FDT today.
>> 
>> The name comparison loses its redundant strlen() pass while here.
>> 
>> Assisted-by: Claude:claude-fable-5 [Claude Code]
>> Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
>> ---
>>  drivers/of/base.c       | 20 +++++++++++++++-----
>>  drivers/of/of_private.h |  8 ++++++++
>>  2 files changed, 23 insertions(+), 5 deletions(-)
>> 
>> diff --git a/drivers/of/base.c b/drivers/of/base.c
>> index 477017ed6f49..eca1f55eee87 100644
>> --- a/drivers/of/base.c
>> +++ b/drivers/of/base.c
>> @@ -995,6 +995,8 @@ struct device_node *of_find_node_opts_by_path(const char *path, const char **opt
>>  
>>  	/* The path could begin with an alias */
>>  	if (*path != '/') {
>> +		struct device_node *aliases;
>> +		const char *value = NULL;
>>  		int len;
>>  		const char *p = strchrnul(path, '/');
>>  
>> @@ -1002,16 +1004,24 @@ 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)
>> +		/* the load pairs with writers that retire the node */
>> +		raw_spin_lock_irqsave(&devtree_lock, flags);
>> +		aliases = of_node_get(of_aliases);
>> +		raw_spin_unlock_irqrestore(&devtree_lock, flags);
>
> There's no need to take the spinlock for just a get. Furthermore, as 
> long as the of_aliases pointer is exposed to the rest of the kernel, a 
> reference should always be held. Not that you should rely on that 
> here...
>
> Rob

Agreed, dropped the lock for v7 (here and around the of_aliases
updates in the notifier patch, which are already serialized by
aliases_mutex).

Since patch 1 is applied, I'll drop it and rebase the rest on dt/next
unless you prefer otherwise.

Thanks,
Abdurrahman

  reply	other threads:[~2026-08-27 20:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 20:30 [PATCH v6 00/10] of: teach overlay code to keep /aliases in sync Abdurrahman Hussain
2026-08-05 20:31 ` [PATCH v6 01/10] of: fix out-of-bounds read in of_alias_scan() stem parser Abdurrahman Hussain
2026-08-06  8:10   ` Geert Uytterhoeven
2026-08-27 14:36   ` Rob Herring (Arm)
2026-08-05 20:31 ` [PATCH v6 02/10] of: hold a reference on of_aliases during alias path resolution Abdurrahman Hussain
2026-08-05 20:52   ` sashiko-bot
2026-08-27 14:52   ` Rob Herring
2026-08-27 20:20     ` Abdurrahman Hussain [this message]
2026-08-05 20:31 ` [PATCH v6 03/10] of: update /aliases lookup on reconfig notifications Abdurrahman Hussain
2026-08-05 20:31 ` [PATCH v6 04/10] of/overlay: look up absolute target-paths absolutely Abdurrahman Hussain
2026-08-05 20:40   ` sashiko-bot
2026-08-27 20:32     ` Abdurrahman Hussain
2026-08-05 20:31 ` [PATCH v6 05/10] of/overlay: put property on deadprops only after changeset add succeeds Abdurrahman Hussain
2026-08-05 20:45   ` sashiko-bot
2026-08-05 20:31 ` [PATCH v6 06/10] of/overlay: only treat a positive changeset id as registered Abdurrahman Hussain
2026-08-05 20:42   ` sashiko-bot
2026-08-06  7:52   ` Geert Uytterhoeven
2026-08-05 20:31 ` [PATCH v6 07/10] of/overlay: don't create "//" paths for fragments targeting the root Abdurrahman Hussain
2026-08-05 20:45   ` sashiko-bot
2026-08-05 20:31 ` [PATCH v6 08/10] of/overlay: return ERR_PTR from dup_and_fixup_symbol_prop() Abdurrahman Hussain
2026-08-05 20:31 ` [PATCH v6 09/10] of/overlay: rewrite /aliases path values to live-tree paths Abdurrahman Hussain
2026-08-05 20:31 ` [PATCH v6 10/10] 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=DL0074F6I9HO.5OPQ5ABY74KS@nexthop.ai \
    --to=abdurrahman@nexthop.ai \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=saravanak@kernel.org \
    --cc=shawn.guo@linaro.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;
as well as URLs for NNTP newsgroup(s).