Thread View: linux.kernel.netdev
10 messages
10 total messages
Started by Kimberly Morris
Wed, 18 Nov 2026 10:33
[PATCH net 0/2] net: phy: fix timestamping lifetime after probe failure
Author: Kimberly Morris
Date: Wed, 18 Nov 2026 10:33
Date: Wed, 18 Nov 2026 10:33
46 lines
13754 bytes
13754 bytes
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(+)
[PATCH net 1/2] net: phy: restore timestamping state on probe failure
Author: Kimberly Morris
Date: Wed, 18 Nov 2026 10:34
Date: Wed, 18 Nov 2026 10:34
105 lines
15693 bytes
15693 bytes
A PHY driver can install a devm-backed mii_timestamper and select it as
the default before its probe sequence has completed. If a later probe
step fails, the driver core releases the driver's devres, but the
phy_device retains both timestamping fields.
If the generic PHY driver later attaches, skb_defer_rx_timestamp() can
dereference the freed mii_timestamper. This also affects non-PTP packets
because the receive path tests hwtstamp_set before classifying the
packet.
Save the incoming mii_ts and default_timestamp state and restore it on
every probe error path. Restoring the previous values also preserves a
timestamper installed externally before the probe.
On an x86_64 KASAN kernel, a KUnit reproducer using a real mii_bus,
phy_device and phy_driver triggered a slab use-after-free after the
failed probe, driver-core devres cleanup and generic-PHY fallback. The
same test passes after this change.
Fixes: 39db6be781cd ("net: phy: broadcom: Add PTP support for some
Broadcom PHYs.")
Cc: stable@vger.kernel.org
Signed-off-by: Kimberly Morris <gy770616@gmail.com>
---
drivers/net/phy/phy_device.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index b39e945..4017568 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -3812,8 +3812,10 @@ EXPORT_SYMBOL_GPL(fwnode_get_phy_node);
static int phy_probe(struct device *dev)
{
struct phy_device *phydev = to_phy_device(dev);
+ struct mii_timestamper *mii_ts = phydev->mii_ts;
struct device_driver *drv = phydev->mdio.dev.driver;
struct phy_driver *phydrv = to_phy_driver(drv);
+ bool default_timestamp = phydev->default_timestamp;
int err = 0;
phydev->drv = phydrv;
@@ -3951,6 +3953,9 @@ static int phy_probe(struct device *dev)
phydev->drv->remove(phydev);
out_reset:
+ phydev->mii_ts = mii_ts;
+ phydev->default_timestamp = default_timestamp;
+
/* Re-assert the reset signal on error */
phy_device_reset(phydev, 1);
--
2.55.0.windows.3
On Wed, 18 Nov 2026 05:33:45 -0500, Kimberly Morris <gy770616@gmail.com> 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(+)
[PATCH net 2/2] net: phy: broadcom: release PTP clock with PHY devres
Author: Kimberly Morris
Date: Wed, 18 Nov 2026 10:34
Date: Wed, 18 Nov 2026 10:34
115 lines
15743 bytes
15743 bytes
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@vger.kernel.org
Signed-off-by: Kimberly Morris <gy770616@gmail.com>
---
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@gmail.com> 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(+)
Re: [PATCH net 0/2] net: phy: fix timestamping lifetime after probe failure
Author: netdev-bot+sinfo
Date: Wed, 18 Nov 2026 10:38
Date: Wed, 18 Nov 2026 10:38
19 lines
8549 bytes
8549 bytes
Hi! This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information: - How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan. Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. *IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages. -- The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Re: [PATCH net 0/2] net: phy: fix timestamping lifetime after probe failure
Author: Kimberly Morris
Date: Wed, 18 Nov 2026 10:57
Date: Wed, 18 Nov 2026 10:57
39 lines
13896 bytes
13896 bytes
> - How the issue was discovered, e.g. hit in production, hit during > development, syzbot report, manual code inspection, LLM or static > analysis tool scan. The issue was found during a targeted source audit of PHY hardware timestamping lifetime and probe-error paths. The source audit was assisted by an LLM; it was not a production report or a syzbot finding. The resulting hypothesis was then validated against the current Linux source with a focused KUnit/KASAN reproducer. The test registers a real mii_bus, phy_device and phy_driver, follows phylib's probe failure and the driver core's devres cleanup, attaches the generic PHY driver, and calls skb_defer_rx_timestamp() with a non-PTP skb. KASAN reported the use-after-free before the fix, and the same test passed after the fix. The concrete BCM54210E/BCM54213PE publication-before-failure ordering and the missing PHC cleanup were also checked directly in the driver source. No physical hardware reproduction has been completed. On Wed, 18 Nov 2026 10:38:42 +0000, netdev-bot+sinfo@kernel.org wrote: > Hi! > > This is an automated message. This series looks like a fix, but its > commit messages seem to be missing some information: > > - How the issue was discovered, e.g. hit in production, hit during > development, syzbot report, manual code inspection, LLM or static > analysis tool scan. > > Please do not repost the series just to address the above. Instead, > reply to this email with the missing information, so that reviewers > can take it into account. > > *IMPORTANT*: If you do repost (for other reasons) - please include > the relevant info in the cover letter or commit messages. > -- > The evaluation is done by an LLM so it may be wrong, if you think > that is the case please reply and explain.
Re: [PATCH net 1/2] net: phy: restore timestamping state on probe failure
Author: Andrew Lunn
Date: Wed, 18 Nov 2026 14:05
Date: Wed, 18 Nov 2026 14:05
10 lines
8587 bytes
8587 bytes
> Fixes: 39db6be781cd ("net: phy: broadcom: Add PTP support for some
> Broadcom PHYs.")
> Cc: stable@vger.kernel.org
Does this bother anybody?
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
Andrew
Re: [PATCH net 2/2] net: phy: broadcom: release PTP clock with PHY devres
Author: Andrew Lunn
Date: Wed, 18 Nov 2026 14:08
Date: Wed, 18 Nov 2026 14:08
43 lines
9504 bytes
9504 bytes
> +static void bcm_ptp_remove(void *data)
> +{
> + struct bcm_ptp_private *priv = data;
> + struct phy_device *phydev = priv->phydev;
Reverse Christmas tree.
> +
> + 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);
Consider if it makes more sense to not use devm_.
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
says:
Netdev remains skeptical about promises of all “auto-cleanup” APIs,
including even devm_ helpers, historically.
Andrew
Re: [PATCH net 1/2] net: phy: restore timestamping state on probe failure
Author: Andrew Lunn
Date: Thu, 19 Nov 2026 13:23
Date: Thu, 19 Nov 2026 13:23
50 lines
10293 bytes
10293 bytes
On Wed, Nov 18, 2026 at 05:34:05AM -0500, Kimberly Morris wrote:
> A PHY driver can install a devm-backed mii_timestamper and select it as
> the default before its probe sequence has completed. If a later probe
> step fails, the driver core releases the driver's devres, but the
> phy_device retains both timestamping fields.
>
> If the generic PHY driver later attaches, skb_defer_rx_timestamp() can
> dereference the freed mii_timestamper. This also affects non-PTP packets
> because the receive path tests hwtstamp_set before classifying the
> packet.
This is very theoretical. It means root has unloaded the device
specific driver leaving just genphy. Very unlikely.
> Fixes: 39db6be781cd ("net: phy: broadcom: Add PTP support for some
> Broadcom PHYs.")
> Cc: stable@vger.kernel.org
Since this never happens, it bothers nobody, net-next.
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -3812,8 +3812,10 @@ EXPORT_SYMBOL_GPL(fwnode_get_phy_node);
> static int phy_probe(struct device *dev)
> {
> struct phy_device *phydev = to_phy_device(dev);
> + struct mii_timestamper *mii_ts = phydev->mii_ts;
> struct device_driver *drv = phydev->mdio.dev.driver;
> struct phy_driver *phydrv = to_phy_driver(drv);
> + bool default_timestamp = phydev->default_timestamp;
> int err = 0;
>
> phydev->drv = phydrv;
> @@ -3951,6 +3953,9 @@ static int phy_probe(struct device *dev)
> phydev->drv->remove(phydev);
>
> out_reset:
> + phydev->mii_ts = mii_ts;
> + phydev->default_timestamp = default_timestamp;
> +
The basic fix is wrong. If probe fails, everything done so far should
be undone. When probe is entered, there is no stamper. If probe exists
with an error, there should be no stamper.
Andrew
Re: [PATCH net 2/2] net: phy: broadcom: release PTP clock with PHY devres
Author: Andrew Lunn
Date: Thu, 19 Nov 2026 13:27
Date: Thu, 19 Nov 2026 13:27
15 lines
8616 bytes
8616 bytes
> +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) {
How can that not be true?
Andrew
---
pw-bot: cr
Re: [PATCH net 0/2] net: phy: fix timestamping lifetime after probe failure
Author: Andrew Lunn
Date: Thu, 19 Nov 2026 13:28
Date: Thu, 19 Nov 2026 13:28
12 lines
8650 bytes
8650 bytes
On Wed, Nov 18, 2026 at 05:33:45AM -0500, Kimberly Morris 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. This text is used as the merge commit message. So it should be kept formal. Andrew
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads