Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aleksei Sviridkin" <f@lex.la>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [RFC PATCH net-next 8/9] net: phylink: wait for PHYs that are known to probe late
Date: Sun, 30 Aug 2026 05:26:22 +0000	[thread overview]
Message-ID: <20260830052623.408C81F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260829052546.1152446-9-f@lex.la>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] pl->phydev is left as a dangling pointer if phylink_bringup_phy() fails, causing an infinite -EBUSY retry loop and a subsequent double-free/UAF.
--

commit 041169a410024c4510d91d095a3546cc79dd0bb6
Author: Aleksei Sviridkin <f@lex.la>

net: phylink: wait for PHYs that are known to probe late

A PHY whose driver or firmware lives on a filesystem mounted after the MAC
probes cannot be connected when the port is set up. This commit allows a port
to specify slow-to-probe, polling for the PHY instead of failing. It waits
for the PHY's driver to finish probing and re-tries on failures.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 3ec3bb4391095..62e6059a18da3 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -2254,6 +2277,129 @@ int phylink_connect_phy(struct phylink *pl, struct phy_device *phy)
>  }
>  EXPORT_SYMBOL_GPL(phylink_connect_phy);
>  
[ ... ]
> +static void phylink_slow_phy_poll(struct work_struct *work)
> +{
[ ... ]
> +	if (!ret) {
> +		ret = phylink_bringup_phy(pl, phy_dev,
> +					  pl->link_config.interface);
> +		if (ret)
> +			phy_detach(phy_dev);

[Severity: High]
This isn't a bug introduced by this patch, but the existing lack of rollback
in phylink_bringup_phy() is exacerbated by this new background poller, which
turns it into an infinite background loop and a guaranteed crash on teardown.

If phylink_bringup_phy() fails later in its execution (for example, if
phy_eee_rx_clock_stop() returns an error), it returns that error but leaves
pl->phydev pointing to the PHY:

drivers/net/phy/phylink.c:phylink_bringup_phy() {
    ...
    pl->phydev = phy;
    ...
    ret = phy_eee_rx_clock_stop(phy, pl->config->eee_rx_clk_stop_enable);
    if (ret == -EOPNOTSUPP)
        ret = 0;
    ...
    return ret;
}

Because pl->phydev remains populated after the failure, the poller calls
phy_detach() which drops the refcount. On the next poll cycle,
phylink_attach_phy() will unconditionally return -EBUSY because pl->phydev
is already set.

Furthermore, when the interface is later brought down and
phylink_disconnect_phy() is called, it finds pl->phydev set and calls
phy_disconnect(). This calls phy_detach() a second time on the
already-detached PHY, causing a double-put and use-after-free.

Should phylink_bringup_phy() clear pl->phydev on error, or should the caller
clear it if the bringup fails?

> +		else if (!test_bit(PHYLINK_DISABLE_STOPPED,
> +				   &pl->phylink_disable_state))
> +			/* phylink_start() starts the PHY it finds attached,
> +			 * and ran long before this one turned up.
> +			 */
> +			phy_start(phy_dev);
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260829052546.1152446-1-f@lex.la?part=8

  reply	other threads:[~2026-08-30  5:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29  5:25 [RFC PATCH net-next 0/9] net: survive a PHY whose firmware arrives after the MAC probes Aleksei Sviridkin
2026-08-29  5:25 ` [RFC PATCH net-next 1/9] dt-bindings: net: add Airoha EN8811H PHY MCU Aleksei Sviridkin
2026-08-29  5:25 ` [RFC PATCH net-next 2/9] dt-bindings: net: ethernet-controller: add slow-to-probe Aleksei Sviridkin
2026-08-30  5:26   ` sashiko-bot
2026-09-04  0:29   ` Andrew Lunn
2026-08-29  5:25 ` [RFC PATCH net-next 3/9] net: phy: air: type the buckpbus core on the bus and address Aleksei Sviridkin
2026-09-04  0:48   ` Andrew Lunn
2026-08-29  5:25 ` [RFC PATCH net-next 4/9] net: phy: air: move the EN8811H firmware download into the library Aleksei Sviridkin
2026-09-04  1:16   ` Andrew Lunn
2026-08-29  5:25 ` [RFC PATCH net-next 5/9] net: phy: air: skip the download when the MD32 is already running Aleksei Sviridkin
2026-08-29  5:25 ` [RFC PATCH net-next 6/9] net: mdio: add Airoha EN8811H MDIO device driver Aleksei Sviridkin
2026-08-30  5:26   ` sashiko-bot
2026-09-04  1:36   ` Andrew Lunn
2026-08-29  5:25 ` [RFC PATCH net-next 7/9] net: mdio: en8811h: add the nested pass-through bus Aleksei Sviridkin
2026-09-04  1:43   ` Andrew Lunn
2026-08-29  5:25 ` [RFC PATCH net-next 8/9] net: phylink: wait for PHYs that are known to probe late Aleksei Sviridkin
2026-08-30  5:26   ` sashiko-bot [this message]
2026-08-29  5:25 ` [RFC PATCH net-next 9/9] net: phylink: report no link modes while a late PHY is missing Aleksei Sviridkin
2026-08-30  5:26   ` 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=20260830052623.408C81F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=f@lex.la \
    --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