Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH 3/4] software node: handle missing remote endpoint node
Date: Wed, 04 Nov 2026 16:14:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-197590@kernel.org> (raw)
In-Reply-To: <20261104-swnode-race-v1-v1-3-9406a67e25be@nxp.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] software node: refcount race in software_node_graph_get_remote_endpoint()
--

commit 248da443d964ed22789819ccc10771552e53780f
Author: Peng Fan <peng.fan@nxp.com>

software node: handle missing remote endpoint node

This commit updates software_node_graph_get_remote_endpoint() to check the
return value of software_node_fwnode() for NULL before passing it to
software_node_get().

> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index 9095d50ba146f..4d95a59a27f0a 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -676,6 +676,7 @@ software_node_graph_get_remote_endpoint(const struct fwnode_handle *fwnode)
>  {
>  	struct swnode *swnode = to_swnode(fwnode);
>  	const struct software_node_ref_args *ref;
> +	struct fwnode_handle *refnode;
>  	const struct property_entry *prop;
>  
>  	if (!swnode)
> @@ -690,7 +691,11 @@ software_node_graph_get_remote_endpoint(const struct fwnode_handle *fwnode)
>  	if (!ref->swnode)
>  		return NULL;
>  
> -	return software_node_get(software_node_fwnode(ref->swnode));
> +	refnode = software_node_fwnode(ref->swnode);
> +	if (!refnode)
> +		return NULL;
> +
> +	return software_node_get(refnode);

[Severity: High]
Can this race with a concurrent unregistration of ref->swnode and cause a
use-after-free or refcount addition on zero?

software_node_fwnode() calls software_node_to_swnode(), which acquires a
reference via software_node_to_swnode_get() and immediately drops it:

drivers/base/swnode.c:software_node_to_swnode() {
	struct swnode *swnode = software_node_to_swnode_get(node);

	if (swnode)
		swnode_put(swnode);

	return swnode;
}

Because the caller of software_node_graph_get_remote_endpoint() only holds
a reference to the local endpoint fwnode and not to ref->swnode, if
ref->swnode is concurrently unregistered after kobject_get_unless_zero()
succeeds in software_node_to_swnode_get(), either swnode_put() inside
software_node_to_swnode() or the concurrent unregistration can drop the
last reference before software_node_get(refnode) runs.

software_node_get(refnode) will then call kobject_get() on a dying or
freed swnode.

Should software_node_graph_get_remote_endpoint() call
software_node_to_swnode_get(ref->swnode) directly and return
&remote->fwnode (or NULL) so that the reference acquired under
swnode_kset->list_lock via kobject_get_unless_zero() is retained?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-swnode-race-v1-v1-0-9406a67e25be@nxp.com?part=3

  reply	other threads:[~2026-11-04 16:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 15:43 [PATCH 0/4] software node: fix lookup of swnode in release path Peng Fan (OSS)
2026-11-04 15:43 ` [PATCH 1/4] software node: do not resurrect swnode being released Peng Fan (OSS)
2026-11-04 15:54   ` sashiko-bot
2026-11-04 15:43 ` [PATCH 2/4] software node: use kobject_get_unless_zero() in software_node_find_by_name() Peng Fan (OSS)
2026-11-04 16:07   ` sashiko-bot
2026-11-04 21:29   ` Andy Shevchenko
2026-11-04 15:43 ` [PATCH 3/4] software node: handle missing remote endpoint node Peng Fan (OSS)
2026-11-04 16:14   ` sashiko-bot [this message]
2026-11-04 15:43 ` [PATCH 4/4] software node: skip dying children during traversal Peng Fan (OSS)
2026-11-04 16:22   ` sashiko-bot

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-197590@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=peng.fan@oss.nxp.com \
    --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