From: sashiko-bot@kernel.org
To: "Maxime Chevallier" <maxime.chevallier@bootlin.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver
Date: Sat, 05 Dec 2026 11:08:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-251452@kernel.org> (raw)
In-Reply-To: <20261204110622.1106492-12-maxime.chevallier@bootlin.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net: phy: mux: unsynchronized mii_mux_auto_remove() vs
phy_mux_detach()
- [Medium] net: phy: unsynchronized pl->mux access and detach vs
phy_mux_unregister()
--
commit 3ddf01a7f8c108024edc40420dc253bccef488c1
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>
net: phy: mux: Add the mii-mux-auto driver
This commit adds the mii-mux-auto platform driver for hardware-switched
two-port MII multiplexers, validating the port fwnodes, registering the mux
with the phy_mux core, and unregistering and freeing it on removal.
> diff --git a/drivers/net/phy/mux/mii_mux_auto.c b/drivers/net/phy/mux/mii_mux_auto.c
> new file mode 100644
> index 0000000000000..980cc2c242ba7
> --- /dev/null
> +++ b/drivers/net/phy/mux/mii_mux_auto.c
> @@ -0,0 +1,99 @@
[ ... ]
> +static void mii_mux_auto_remove(struct platform_device *pdev)
> +{
> + struct phy_mux *mux = platform_get_drvdata(pdev);
> +
> + phy_mux_unregister(mux);
> + phy_mux_free(mux);
> +}
[Severity: Medium]
Can mii_mux_auto_remove() race with an unlocked phy_mux_detach() and cause a
use-after-free on struct phy_mux or struct phylink?
phy_mux_attach() adds a DL_FLAG_STATELESS device link, which does not force
consumers to unbind when mii-mux-auto is removed. phy_mux_unregister() only
holds rtnl_lock() around mux->pops->detach(), and phy_mux_free() immediately
destroys the ports and frees mux.
phy_mux_detach() takes neither rtnl_lock() nor phy_mux_mutex.
phylink_destroy() calls phylink_detach_mux() -> phy_mux_detach() unlocked
before freeing pl, which is reachable with pl->mux set if mvpp2_open() fails
in request_irq() and mvpp2_port_remove() later runs:
CPU0 CPU1
mii_mux_auto_remove() mvpp2_port_remove()
phy_mux_unregister(mux) phylink_destroy(pl)
rtnl_lock() phylink_detach_mux(pl)
mux->pops->detach(mux, pl) phy_mux_detach(mux)
phy_mux_stop(mux)
rtnl_unlock()
phy_mux_free(mux)
phy_mux_port_destroy(port)
kfree(mux)
phy_mux_detach_phys(mux)
<-- use-after-free
In the reverse ordering, phylink_destroy() can free pl while
phy_mux_unregister() calls mux->pops->detach(mux, pl), or both paths can
double-detach the PHYs and devlink. Using a managed device link or
serializing teardown with phy_mux_mutex would prevent this.
[Severity: Medium]
Can mii_mux_auto_remove() also race with the unlocked pl->mux check in
phylink_fwnode_phy_connect()?
Callers such as ocelot_port_phylink_create() and dsa_user_phy_setup() invoke
phylink_of_phy_connect() -> phylink_fwnode_phy_connect() without holding
rtnl_lock(). phylink_attach_mux() sets pl->mux under phy_mux_mutex and then
drops it before phylink_fwnode_phy_connect() checks if (pl->mux):
CPU0 CPU1
phylink_fwnode_phy_connect() mii_mux_auto_remove()
phylink_attach_mux() phy_mux_unregister(mux)
mutex_lock(&phy_mux_mutex)
pl->mux = mux
mutex_unlock(&phy_mux_mutex)
mutex_lock(&phy_mux_mutex)
list_del(&mux->node)
mutex_unlock(&phy_mux_mutex)
rtnl_lock()
phylink_mux_detach()
pl->mux = NULL
rtnl_unlock()
if (pl->mux) <-- reads NULL
fwnode_get_phy_node(fwnode)
Because pl->mux is read as NULL, phylink_fwnode_phy_connect() falls through
to fwnode_get_phy_node() and can fail probe with -ENODEV, return 0 without
an attached mux or PHY, or attach a fallback phy-handle while
pl->sfp_behind_mux remains set.
Separately, phylink_destroy() calls phylink_detach_mux() unlocked before
kfree(pl), which can race with mii_mux_auto_remove() -> phy_mux_unregister()
and phy_mux_free() to cause a use-after-free on mux or pl.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=11
next prev parent reply other threads:[~2026-12-05 11:08 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 01/12] dt-bindings: net: Add Ethernet " Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 02/12] net: phy: Introduce phy_mux, a MII multiplexer representation Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 03/12] net: phy: Don't create the sysfs links for PHYs behind a mux Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 07/12] net: phylink: Factor out phylink_clear_phydev() Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 08/12] net: phy: phy_mux: Add phy_mux_set_mac_managed_pm() Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 10/12] net: phylink: Support an SFP cage behind " Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot [this message]
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
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-251452@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--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.