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 v18 02/12] net: phylink: introduce internal phylink PCS handling
Date: Sat, 10 Oct 2026 18:49:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-166836@kernel.org> (raw)
In-Reply-To: <20261009182836.50631-3-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net: phylink: UAF of phylink struct in phylink_pcs_change() during concurrent teardown
- [Medium] net: phylink: missing validation failure when a required PCS is not found
--

commit 7ece69b824da0eb34269e858e3ce098347af5b79
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phylink: introduce internal phylink PCS handling

This commit introduces internal handling of PCS for phylink by migrating the
selection logic to use a list of available PCS attached to the phylink
instance. It updates validation and configuration functions to search this
list if a dedicated PCS is required for the requested interface mode.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index a98e62fa4bd26..1156e6c61a08b 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -530,6 +549,21 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
>  		pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
>  		if (IS_ERR(pcs))
>  			return PTR_ERR(pcs);
> +	/*
> +	 * Find a PCS in available PCS list for the requested interface.
> +	 *
> +	 * Skip searching if the MAC doesn't require a dedicated PCS for
> +	 * the requested interface.
> +	 */
> +	} else if (test_bit(state->interface, pl->config->pcs_interfaces)) {
> +		struct phylink_pcs *tmp;
> +
> +		list_for_each_entry(tmp, &pl->pcs_list, list) {
> +			if (!phylink_validate_pcs_interface(tmp, state->interface)) {
> +				pcs = tmp;
> +				break;
> +			}
> +		}
>  	}
>  
>  	if (pcs) {

[Severity: Medium]
If the MAC requires a dedicated PCS for the requested interface but no PCS in
pl->pcs_list supports it, pcs remains NULL. Since there is no check for !pcs
here, the function will bypass the if (pcs) validation block and incorrectly
return 0 (success).

Will this cause unsupported link modes to be falsely reported as supported
during phylink_validate()? It appears that later during
phylink_major_config(), the exact same lookup correctly checks for !pcs and
fatally aborts the link configuration. Should this return an error like
-EINVAL when a required PCS is not found?

[ ... ]
> @@ -2076,11 +2215,20 @@ EXPORT_SYMBOL_GPL(phylink_create);
>   */
>  void phylink_destroy(struct phylink *pl)
>  {
> +	struct phylink_pcs *pcs, *tmp;
> +
>  	sfp_bus_del_upstream(pl->sfp_bus);
>  	if (pl->link_gpio)
>  		gpiod_put(pl->link_gpio);
>  
>  	cancel_work_sync(&pl->resolve);
> +
> +	/* Remove every PCS from phylink PCS list */
> +	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
> +		pcs->phylink = NULL;
> +		list_del(&pcs->list);
> +	}
> +
>  	kfree(pl);
>  }
>  EXPORT_SYMBOL_GPL(phylink_destroy);

[Severity: High]
Does this teardown path properly synchronize with concurrent PCS events?

This path clears pcs->phylink and frees pl unconditionally, without an RCU
grace period or synchronization against concurrent execution. If
phylink_pcs_change() is called by an external PCS driver (e.g. from an
interrupt handler) and is delayed, a concurrent MAC driver unbind could
invoke phylink_destroy().

Because the teardown frees pl without waiting for pending PCS interrupts to
finish, this might leave readers in phylink_pcs_change() vulnerable to a
use-after-free.

[ ... ]
> @@ -2546,8 +2694,15 @@ void phylink_pcs_change(struct phylink_pcs *pcs, bool up)
>  {
>  	struct phylink *pl = pcs->phylink;
>  
> -	if (pl)
> -		phylink_link_changed(pl, up, "pcs");
> +	/*
> +	 * Ignore PCS link state change if the PCS is not
> +	 * attached to a phylink instance or the phylink
> +	 * instance is not currently using this PCS.
> +	 */
> +	if (!pl || READ_ONCE(pl->pcs) != pcs)
> +		return;
> +
> +	phylink_link_changed(pl, up, "pcs");
>  }
>  EXPORT_SYMBOL_GPL(phylink_pcs_change);

[Severity: High]
Can pl be a dangling pointer when this READ_ONCE() is executed?

As noted above in phylink_destroy(), pl could be freed if teardown happens
concurrently after pl is read from pcs->phylink but before this READ_ONCE()
completes, resulting in a use-after-free.

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

  reply	other threads:[~2026-10-10 18:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 18:27 [PATCH net-next v18 00/12] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-10-09 18:27 ` [PATCH net-next v18 01/12] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-10-09 18:27 ` [PATCH net-next v18 02/12] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-10-10 18:49   ` sashiko-bot [this message]
2026-10-09 18:27 ` [PATCH net-next v18 03/12] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-10-10 18:49   ` sashiko-bot
2026-10-09 18:28 ` [PATCH net-next v18 04/12] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
2026-10-09 18:28 ` [PATCH net-next v18 05/12] net: phylink: support PCS provider release Christian Marangi
2026-10-10 18:49   ` sashiko-bot
2026-10-09 18:28 ` [PATCH net-next v18 06/12] net: phylink: support late PCS provider attach Christian Marangi
2026-10-10 18:49   ` sashiko-bot
2026-10-09 18:28 ` [PATCH net-next v18 07/12] net: Document PCS subsystem Christian Marangi
2026-10-09 18:28 ` [PATCH net-next v18 08/12] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-10-09 18:28 ` [PATCH net-next v18 09/12] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-10-09 18:28 ` [PATCH net-next v18 10/12] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-10-09 18:28 ` [PATCH net-next v18 11/12] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-10-10 18:49   ` sashiko-bot
2026-10-09 18:28 ` [PATCH net-next v18 12/12] net: airoha: add phylink support Christian Marangi

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-166836@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