Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v10 05/11] net: phylink: support late PCS provider attach
Date: Fri, 31 Jul 2026 12:48:17 +0000	[thread overview]
Message-ID: <20260731124817.A58981F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260730102444.1967900-6-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Missing unregistration of the global PCS notifier on `phylink_create` error paths leads to a Use-After-Free.
- [High] Premature registration of the PCS notifier before `pl->config` is initialized allows a NULL pointer dereference.
- [High] Unprotected list iteration and data race on `supported_interfaces` in `phylink_create()`.
- [High] `pcs_provider_notify()` queries the wrong firmware node for multi-port devices, breaking late PCS attachment.
--

--- Patch [5]: [PATCH net-next v10 05/11] net: phylink: support late PCS provider attach ---
commit d9b1d2d810fd485b6cc269c43b554af06d8f51d3
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phylink: support late PCS provider attach
    
This commit adds support for late PCS provider attachment to a phylink
instance by creating a global notifier chain that emits events when a new
PCS provider is added. Phylink instances subscribe to this notifier to
dynamically link PCS providers and trigger interface reconfiguration when
they appear.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 562e09d1838b0..d38820543ae4a 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c

[ ... ]

> @@ -1988,21 +2011,70 @@ static int phylink_fill_available_pcs(struct phylink *pl,
> +static int pcs_provider_notify(struct notifier_block *self,
> +			       unsigned long val, void *data)
> +{
> +	struct phylink *pl = container_of(self, struct phylink, fwnode_pcs_nb);
> +	struct fwnode_handle *pcs_fwnode = data;
> +	struct phylink_pcs *pcs;
> +
> +	rtnl_lock();
> +
> +	/* Check if the just added PCS provider is
> +	 * in the phylink instance pcs-handle property.
> +	 */
> +	pcs = fwnode_phylink_pcs_get_from_fwnode(dev_fwnode(pl->config->dev),
> +						 pcs_fwnode);

[Severity: High]
Will this correctly handle multi-port MACs or DSA switches where the pcs-handle
property is located in a child port's firmware node?

In phylink_create(), the port-specific firmware node is passed in as the
fwnode parameter. However, this callback queries the top-level
dev_fwnode(pl->config->dev), which may not contain the pcs-handle property
for individual ports. 

Should the instance store the port's fwnode during creation so the notifier
can use it here instead?

[ ... ]

> @@ -2047,15 +2119,21 @@ struct phylink *phylink_create(struct phylink_config *config,
>  	INIT_WORK(&pl->resolve, phylink_resolve);
>  	INIT_LIST_HEAD(&pl->pcs_list);
>  
> +	/*
> +	 * First register notifier for late PCS attach to catch
> +	 * any possible provider that registers while we fill
> +	 * the available PCS.
> +	 */
> +	if (!phy_interface_empty(config->pcs_interfaces)) {
> +		pl->fwnode_pcs_nb.notifier_call = pcs_provider_notify;
> +		register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
> +	}

[Severity: High]
Is there a race condition here if a PCS provider is registered concurrently?

By registering the global notifier here, pcs_provider_notify() can be invoked
immediately on another CPU. That callback dereferences pl->config->dev:

pcs_provider_notify() {
   ...
   pcs = fwnode_phylink_pcs_get_from_fwnode(dev_fwnode(pl->config->dev),
                                            pcs_fwnode);
}

However, pl->config isn't assigned until further down in phylink_create().
Could this result in a NULL pointer dereference if a driver probes
concurrently?

>  	/* Fill the PCS list with available PCS from phylink config */
>  	ret = phylink_fill_available_pcs(pl, config);
>  	if (ret < 0)
>  		goto free_pl;

[Severity: High]
If phylink_fill_available_pcs() or subsequent initialization steps fail, will
this leak the notifier block into the global chain?

The error handling path at free_pl calls kfree(pl). If the notifier was
registered right above this step, but isn't unregistered before freeing pl,
could the next system-wide PCS registration trigger a use-after-free and crash
when it walks the global fwnode_pcs_notify_list?

> -	/* Link available PCS to phylink */
> -	list_for_each_entry(pcs, &pl->pcs_list, list)
> -		pcs->phylink = pl;
> -
>  	phy_interface_copy(pl->supported_interfaces,
>  			   config->supported_interfaces);
>  
> +	/* Update supported interfaces */
> +	list_for_each_entry(pcs, &pl->pcs_list, list)
> +		phy_interface_or(pl->supported_interfaces,
> +				 pl->supported_interfaces,
> +				 pcs->supported_interfaces);

[Severity: High]
Does this list iteration need to be protected by pl->state_mutex?

Since the PCS notifier has already been registered globally above,
pcs_provider_notify() could be executing on another CPU, acquiring
state_mutex, and modifying both pl->pcs_list and pl->supported_interfaces.

Could iterating the list and doing the bitwise OR here without holding the lock
lead to data corruption?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730102444.1967900-1-ansuelsmth@gmail.com?part=5

  reply	other threads:[~2026-07-31 12:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 10:24 [PATCH net-next v10 00/11] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 01/11] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 02/11] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 03/11] net: phylink: add phylink_release_pcs() to externally release a PCS Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 04/11] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 05/11] net: phylink: support late PCS provider attach Christian Marangi
2026-07-31 12:48   ` sashiko-bot [this message]
2026-07-30 10:24 ` [PATCH net-next v10 06/11] net: Document PCS subsystem Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 07/11] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 08/11] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 09/11] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 10/11] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 11/11] net: airoha: add phylink support Christian Marangi
2026-07-30 11:56   ` Lorenzo Bianconi
2026-07-31 12:48   ` 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=20260731124817.A58981F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ansuelsmth@gmail.com \
    --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