[PATCH net 2/2] net: phy: broadcom: release PTP clock with PHY devres
From: Kimberly Morris
Date: Wed Nov 18 2026 - 05:34:25 EST
bcm_ptp_probe() registers a PHC whose ptp_clock_info and MII timestamper
are embedded in devres-managed private data. The enclosing PHY probe can
still fail while acquiring the wakeup GPIO, requesting its IRQ or
enabling wakeup. Driver-core cleanup then frees the private data without
unregistering the PHC, leaving pointers to freed memory in both the PTP
core and the phy_device.
Register a managed cleanup action after publishing the timestamper. The
action removes the driver-owned timestamper, unregisters the PHC and
purges the transmit queue before the private data is released. The same
action also supplies the missing cleanup for normal driver removal.
Fixes: 39db6be781cd ("net: phy: broadcom: Add PTP support for some
Broadcom PHYs.")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Kimberly Morris <gy770616@xxxxxxxxx>
---
drivers/net/phy/bcm-phy-ptp.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/net/phy/bcm-phy-ptp.c b/drivers/net/phy/bcm-phy-ptp.c
index 443917c..085cc31 100644
--- a/drivers/net/phy/bcm-phy-ptp.c
+++ b/drivers/net/phy/bcm-phy-ptp.c
@@ -917,10 +917,25 @@ static void bcm_ptp_init(struct bcm_ptp_private *priv)
priv->phydev->mii_ts = &priv->mii_ts;
}
+static void bcm_ptp_remove(void *data)
+{
+ struct bcm_ptp_private *priv = data;
+ struct phy_device *phydev = priv->phydev;
+
+ if (phydev->mii_ts == &priv->mii_ts) {
+ phydev->mii_ts = NULL;
+ phydev->default_timestamp = false;
+ }
+
+ ptp_clock_unregister(priv->ptp_clock);
+ skb_queue_purge(&priv->tx_queue);
+}
+
struct bcm_ptp_private *bcm_ptp_probe(struct phy_device *phydev)
{
struct bcm_ptp_private *priv;
struct ptp_clock *clock;
+ int err;
switch (BRCM_PHY_MODEL(phydev)) {
case PHY_ID_BCM54210E:
@@ -949,6 +964,10 @@ struct bcm_ptp_private *bcm_ptp_probe(struct
phy_device *phydev)
priv->phydev = phydev;
bcm_ptp_init(priv);
+ err = devm_add_action_or_reset(&phydev->mdio.dev, bcm_ptp_remove, priv);
+ if (err)
+ return ERR_PTR(err);
+
return priv;
}
EXPORT_SYMBOL_GPL(bcm_ptp_probe);
--
2.55.0.windows.3
On Wed, 18 Nov 2026 05:33:45 -0500, Kimberly Morris <gy770616@xxxxxxxxx> wrote:
> Hello,
>
> Following Greg's request for an applyable patch, this series addresses the
> automatic PHY probe-failure lifetime path from the earlier report. It does
> not rely on the root-only sysfs driver-unbind trigger.
>
> A PHY driver can publish a devres-backed mii_timestamper before its probe
> has completed. If a later probe step fails, driver-core cleanup frees the
> owner while the phy_device can retain the published timestamping state. A
> later generic-PHY fallback can then reach the freed object from
> skb_defer_rx_timestamp(). Broadcom BCM54210E/BCM54213PE also leaves a
> registered PHC backed by the same freed storage.
>
> Patch 1 restores the timestamping state that existed before phy_probe().
> Patch 2 adds the missing managed Broadcom PHC and timestamper cleanup.
>
> I reproduced the first issue on an x86_64 KASAN kernel with a KUnit test
> that registers a real mii_bus, phy_device and phy_driver, follows the real
> failed-probe and devres cleanup paths, attaches the generic PHY driver, and
> passes a non-PTP skb to skb_defer_rx_timestamp(). Before the fix KASAN
> reported a slab use-after-free; after the fix the test passed without a
> KASAN report.
>
> Tested on:
>
> - upstream master 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
> - net/main 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5
>
> The submitted series is generated against current upstream master
> 63fdb511c27afcebce797e3db580b3534ddfa639. I have not tested it on physical
> BCM54213PE hardware, and I am not claiming an attacker-controlled probe
> failure, privilege escalation, or code execution.
>
> Please let me know if the rollback belongs in individual PHY drivers rather
> than phylib core.
>
> Thank you.
>
> Kimberly Morris (2):
> net: phy: restore timestamping state on probe failure
> net: phy: broadcom: release PTP clock with PHY devres
>
> drivers/net/phy/bcm-phy-ptp.c | 19 +++++++++++++++++++
> drivers/net/phy/phy_device.c | 5 +++++
> 2 files changed, 24 insertions(+)