🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Arun Iyengar via B4 Relay Sun, 15 Nov 2026 09:05
[PATCH net-next v3] net: stmmac: dwmac-sun8i: Fix use-after-free in the MDIO mux error path
#16584
Author: Arun Iyengar via B4 Relay
Date: Sun, 15 Nov 2026 09:05
49 lines
12400 bytes
From: Arun Iyengar <aiyengar1990@gmail.com>

If mdio_mux_init() fails after the internal PHY was powered, the error
path releases rst_ephy and ephy_clk before sun8i_dwmac_exit() uses them
to unpower it. Unpower the PHY first, as sun8i_dwmac_remove() does.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Found by Sashiko's review of another dwmac-sun8i series of mine.
Build-tested only (arm64 and arm, W=1): I have no board with the
internal PHY (H3, H5 or V3s), so the error path was not exercised.

Developed with Claude (Anthropic); I reviewed it.
---
Changes in v3:
- Drop the Fixes tag (Andrew Lunn)
- Shorter commit message
- Link to v2: https://patch.msgid.link/20261113-sun8i-emac-mux-uaf-v2-1-6203666b2687@gmail.com

Changes in v2:
- Target net-next instead of net, drop Cc: stable (Andrew Lunn)
- Shorter commit message
- Rebased onto net-next
- Link to v1: https://patch.msgid.link/20261112-sun8i-emac-mux-uaf-v1-1-308ae7e6fcf2@gmail.com
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 2ece7ba9dd73..898560e8e95c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1245,6 +1245,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
 	return 0;
 
 dwmac_mux:
+	sun8i_dwmac_unpower_internal_phy(gmac);
 	reset_control_put(gmac->rst_ephy);
 	clk_put(gmac->ephy_clk);
 dwmac_remove:

---
base-commit: 6964ff21c5d8b75649211a52dbfd92753e605649
change-id: 20261112-sun8i-emac-mux-uaf-1ba885219fee

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>
Re: [PATCH net-next v3] net: stmmac: dwmac-sun8i: Fix use-after-free in the MDIO mux error path
#16677
Author: Chen-Yu Tsai
Date: Sun, 15 Nov 2026 15:17
70 lines
11731 bytes
On Sun, Nov 15, 2026 at 5:05 PM Arun Iyengar via B4 Relay
<devnull+aiyengar1990.gmail.com@kernel.org> wrote:
>
> From: Arun Iyengar <aiyengar1990@gmail.com>
>
> If mdio_mux_init() fails after the internal PHY was powered, the error
> path releases rst_ephy and ephy_clk before sun8i_dwmac_exit() uses them
> to unpower it. Unpower the PHY first, as sun8i_dwmac_remove() does.

And sun8i_dwmac_remove() also indirectly calls sun8i_dwmac_exit() through
stmmac_pltfr_remove() after reset_control_put() and clk_put(), so it is
no better.

I think the correct fix is to move stmmac_pltfr_remove() before the
*_put() calls (but still after mdio_mux_uninit() in sun8i_dwmac_remove).

>
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
> ---
> Found by Sashiko's review of another dwmac-sun8i series of mine.
> Build-tested only (arm64 and arm, W=1): I have no board with the
> internal PHY (H3, H5 or V3s), so the error path was not exercised.
>
> Developed with Claude (Anthropic); I reviewed it.

It feels like your agent needs to do a bit more deep diving through the
surrounding code.

> ---
> Changes in v3:
> - Drop the Fixes tag (Andrew Lunn)
> - Shorter commit message
> - Link to v2: https://patch.msgid.link/20261113-sun8i-emac-mux-uaf-v2-1-6203666b2687@gmail.com
>
> Changes in v2:
> - Target net-next instead of net, drop Cc: stable (Andrew Lunn)
> - Shorter commit message
> - Rebased onto net-next
> - Link to v1: https://patch.msgid.link/20261112-sun8i-emac-mux-uaf-v1-1-308ae7e6fcf2@gmail.com
> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 2ece7ba9dd73..898560e8e95c 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -1245,6 +1245,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
>         return 0;
>
>  dwmac_mux:
> +       sun8i_dwmac_unpower_internal_phy(gmac);
>         reset_control_put(gmac->rst_ephy);
>         clk_put(gmac->ephy_clk);
>  dwmac_remove:
>
> ---
> base-commit: 6964ff21c5d8b75649211a52dbfd92753e605649
> change-id: 20261112-sun8i-emac-mux-uaf-1ba885219fee
>
> Best regards,
> --
> Arun Iyengar <aiyengar1990@gmail.com>
>
>
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