All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH net-next v9 05/12] net: phylink: support late PCS provider attach
Date: Sat, 18 Jul 2026 09:01:13 +0000	[thread overview]
Message-ID: <20260718090113.B275D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717065448.1498335-6-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] Missing PCS removal notification leads to Use-After-Free when a PCS module is unloaded.
- [High] A TOCTOU race condition in `phylink_create()` can cause a newly added PCS provider to be permanently missed.
- [High] Unconditional `list_add()` in `pcs_provider_notify()` causes doubly-linked list corruption during concurrent additions.
- [High] Late PCS attachment fails for multi-port devices (e.g., DSA switches) due to incorrect fwnode lookup.
- [Medium] Synchronous acquisition of `rtnl_lock()` in the blocking notifier chain introduces a fragile self-deadlock risk.
--

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

net: phylink: support late PCS provider attach

Add support for late PCS provider attachment to a phylink instance.
This works by creating a global notifier for the PCS provider and
making each phylink instance that makes use of fwnode subscribe to
this notifier.

[ ... ]

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 986e0c1e3d678..1d83b31874fb2 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c

[ ... ]

> @@ -1999,6 +2001,53 @@ static int phylink_fill_available_pcs(struct phylink *pl,
>  	return ret;
>  }
>  
> +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();

[Severity: Medium]
Does unconditional acquisition of rtnl_lock() here risk a deadlock?

If a network driver registers a PCS provider from a context that already
holds rtnl_lock() (which is common in network driver probe or open paths),
wouldn't the synchronous notifier callback attempt to recursively acquire
the lock and hang the system?

> +
> +	/* 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 lookup fail for multi-port devices like DSA switches?

It seems to fetch the fwnode from the parent device (pl->config->dev) rather
than the port-specific fwnode passed during phylink creation. If the
pcs-handle property is in the port's subnode, will this return an error and
silently abort the late attachment?

> +	if (IS_ERR(pcs)) {
> +		rtnl_unlock();
> +		return NOTIFY_DONE;
> +	}
> +
> +	/* Add the PCS */
> +	mutex_lock(&pl->state_mutex);
> +
> +	/* Link PCS with phylink */
> +	list_add(&pcs->list, &pl->pcs_list);

[Severity: High]
Could this corrupt the doubly-linked list if the PCS is already present?

If a PCS provider is added concurrently, it might already be picked up by
phylink_fill_available_pcs() and then passed to this notifier. Calling
list_add() unconditionally on a node already in the list overwrites its
pointers and causes list corruption.

> +	pcs->phylink = pl;
> +

[ ... ]

> @@ -2116,6 +2165,12 @@ struct phylink *phylink_create(struct phylink_config *config,
>  	if (ret < 0)
>  		goto unlink_pcs_list;
>  
> +	/* Register notifier for late PCS attach */
> +	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 between fetching available PCS providers and
registering this notifier?

In phylink_create(), the list of available PCS providers is fetched earlier
via phylink_fill_available_pcs(). If a PCS provider calls
fwnode_pcs_add_provider() exactly after the list is fetched but before
register_fwnode_pcs_notifier() is called here, wouldn't the provider be
permanently missed since it wasn't in the global list initially and the
notification was missed?

>  	return pl;
>  
>  unlink_pcs_list:

[ ... ]

> diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h
> index b7cfdd680b2ab..45e8f96662db2 100644
> --- a/include/linux/pcs/pcs.h
> +++ b/include/linux/pcs/pcs.h
> @@ -4,7 +4,36 @@
>  
>  #include <linux/phylink.h>
>  
> +enum fwnode_pcs_notify_event {
> +	FWNODE_PCS_PROVIDER_ADD,
> +};

[Severity: Critical]
Does the lack of a removal notification event create a use-after-free risk?

If a PCS provider module is unloaded, fwnode_pcs_del_provider() is called to
free internal state, but phylink is never notified because there is no
FWNODE_PCS_PROVIDER_DEL event.

Won't the freed pointer remain linked in pl->pcs_list and be dereferenced
during the next phylink_resolve() run triggered by a timer or link state
change?

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

  reply	other threads:[~2026-07-18  9:01 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17  6:54 [PATCH net-next v9 00/12] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-07-17  6:54 ` [PATCH net-next v9 01/12] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 02/12] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 03/12] net: phylink: add phylink_release_pcs() to externally release a PCS Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 04/12] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 05/12] net: phylink: support late PCS provider attach Christian Marangi
2026-07-18  9:01   ` sashiko-bot [this message]
2026-07-17  6:54 ` [PATCH net-next v9 06/12] net: Document PCS subsystem Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 07/12] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-07-17  6:54 ` [PATCH net-next v9 08/12] of: property: fw_devlink: Add support for "pcs-handle" Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 09/12] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 10/12] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-07-17  6:54 ` [PATCH net-next v9 11/12] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 12/12] net: airoha: add phylink support Christian Marangi
2026-07-18  9:01   ` 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=20260718090113.B275D1F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.