🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16677

Re: [PATCH net-next v3] net: stmmac: dwmac-sun8i: Fix use-after-free in the MDIO mux error path

#16677
From: 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>
>
>
Technical Details
Message-ID: <CAGb2v64aOydKdTWJEhF+0GVc45aap4AsHfF5RrL1pzOHF54D0A@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363734-linux-kernel-netdev=dewy.ru
References: <20261115-sun8i-emac-mux-uaf-v3-1-c69d4189539d@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363734-linux-kernel-netdev=dewy.ru
From: wens@kernel.org (Chen-Yu Tsai)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3] net: stmmac: dwmac-sun8i: Fix use-after-free
 in the MDIO mux error path
Date: Sun, 15 Nov 2026 23:17:17 +0800
Organization: Usenet Network
Message-ID: <CAGb2v64aOydKdTWJEhF+0GVc45aap4AsHfF5RrL1pzOHF54D0A@mail.gmail.com>
References: <20261115-sun8i-emac-mux-uaf-v3-1-c69d4189539d@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1834843"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:dB60IYax1x6HE0g9qXqTvTKop8U= sha256:mctoGFl47k4sGVxSaI6WBBytOKaxN7QfY+Ri1JJ4qsU=
	sha1:lQGUsnQxr7xDNpbyAdqlPuIGMAE= sha256:HhnJOyQwVRuFWYEgRzQ7bG23senumh6JWkaow+GRXos=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 934FF1149D7; Sun, 15 Nov 2026 18:18:03 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id xopFRjAiKTFx;
	Sun, 15 Nov 2026 18:17:52 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-363734-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 0DBAC1149E1; Sun, 15 Nov 2026 18:17:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id A048231C96; Sun, 15 Nov 2026 15:17:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794755853;
	b=q0tGGme6yRzaVC8MCJgSolRtxCWls7Nv72tLR37PM91lYYJGRR5BrtbXOdHhJkimBGMY
	 SHQU1csFM65AMOX8EarpyA5nhr2qTDFceQ7njWLwKuj54stL9/wSblNdtJJAEYSgvNgVN
	 qcwKrO1luTa5UecEz1+QuvhBafX2e5SRHh4ehOkmSKB/TZ2awN9GyHUmybKbyw1ufNiws
	 ebzdEd9RN89dHstLsSeNrRFPXUaZbDGlGF6kr1ZIWz6CmuZC7URKn4h19nvlwbN+RQtm1
	 wi3SMZAEprSEXW/84klBe49cvhwgnWy3XVUHnt52lNoNHqUDqrpiAvKOqlqbVqczyNg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794755853;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:References:In-Reply-To:Reply-To:
	 From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
	 Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
	bh=qIkegvM0vM7wyeDCr9yTjV+nCu5PD6X7FTu58o7P70U=;
	b=iP2vucWljlmp8zrkFCHLAa4FOwdH076u4ESwU3kNBBDMw6E4pmenDrCOoW7xRAoDNvyq
	 7AQYx5tmrzkGEQLmfRjGGqkEEXkwHIsP0GhQ206oYJV3PXpjStpJGI5V6jWXFy7uPnGBq
	 JY6l47JijDHJeQV0G6WEVRX0zwug1K14i6EVuCfwppHBQ7J2FgiUD/AeKm88W+pXMqX4D
	 FbVcmBIyrZV6nRQaBSjiXTfS4PHSKcwywGYGbbe+XaYXG6TxLVCThuKTTUmWtrICDJFfp
	 KbYO+S+iJxN2w9hjmTRlUIEMAt+f7FUKQPzhXXYKHQcwdhwio+4W1P6qA05eDto/NPA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j21gX6zX;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 44006606A335;
	Sun, 15 Nov 2026 15:17:33 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j21gX6zX
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794755852;
	b=cjaxn9AdC+2U9y8f7yJTwGkCeX5zrQrUFAWONBzOXMRlFI86ZdVtHZiHgptx37ypWNqa
	 USpwCHI5CJqso2+83jzzkT8r/v2yI7DfRemYiLFDsnoTmjb+qHk8bUez+uwPKZ0QIZpd7
	 4zQ0DSnkT2xQqGNR6btuOQcy5x79Tpe350alHWpngPvhE2yqrub6+3h6WCAH6n+NDZVbj
	 nY1nwRJ8fJ8Ft6sdKv1Z+p0oLqZ64eKd+zTEup3waeE/+GC4U4RFKDhlM0Tw8m0W7fwLr
	 gHXPWdkp1PdiWj+Ea4HY3a+MTfanA7IaRD21agMwxWamXeHm2XHpGZE+H0vNYwbztaw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794755852;
	h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
	 X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
	 Reply-To:From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:
	 Message-ID:Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
	bh=qIkegvM0vM7wyeDCr9yTjV+nCu5PD6X7FTu58o7P70U=;
	b=fNjflEdfB5Rpke6mfCEqRitbLzXuMe5oiysxQHYsI6jbGtkRlcm+vHr6TlbmHs2fsgrp
	 ZbNsht/mbqPM6WZGTG6xxjc0sFJRZFSS8X9e60XK4wyXomm/ozqAdsy6Pm+aK+Z0jVhYq
	 HXN7BxDol8d1bvdBJC1mtZ9SJLYTKtbpjwNIAJN+TXYT7ZoI/6G0ewyqyW309D1VlgFQV
	 5527EWhy0xYsFsr6H6WkS20AIjgio6MgLyEmvPvuTWQe4KYfMgwfXMlIuiI+jfXHD8s66
	 wtTSGECInAY4+sij3WhyLbSFHyu6Ur0m6Cni9lZpxEgaFamqfqoWcBbjl4MatPaLCQQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j21gX6zX;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60629606A31A
	for <netdev@vger.kernel.org>; Sun, 15 Nov 2026 15:17:32 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id F19FE1F000C5
	for <netdev@vger.kernel.org>; Sun, 15 Nov 2026 15:17:31 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794755852;
	bh=qIkegvM0vM7wyeDCr9yTjV+nCu5PD6X7FTu58o7P70U=;
	h=References:In-Reply-To:Reply-To:From:Date:Subject:To:Cc;
	b=j21gX6zXDBAG6MY8+WrsN8mJnhvZS4pEbMFH0rtgAa1XpBrQm6P08/9TekLTD+bOZ
	 PIRV7sVtKt5MnbaTDLds8nZQQezw0XhqDoxV53rnoMKBc5AYEQn0JaiCJrUPFqPK0U
	 ue+K0988nl5towhzBXn5IbmCl62WlRdtXNyBKNm6GOEarDFZ222c29FIp5MKtwF8Ps
	 mt78rrH1qpiSccpfhI73dCPhARZmJAtGdyDt6z7aestGq9dqS7cjJIIkxP33QBY7SJ
	 ZNHC7iZgah3JsgA7ZSEk1ooZHARvLnjWxkEVoPIywnZk6sikOyQZf9LDZLHYWhgzGj
	 CyCwsPAjqCgUA==
X-Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-3ae25c84207so20432871fa.3
        for <netdev@vger.kernel.org>; Sun, 15 Nov 2026 07:17:31 -0800 (PST)
X-Forwarded-Encrypted: i=1; AL+hErF6JIWykTyMpdSSeudLljd7S9ec6mtiq3YG2ZULFvWtdYfYk3rAfdGJnGKs0zp0L5exuSIzZSE=@vger.kernel.org
X-Gm-Message-State: APuU4Z8mA+YsF6rJUPl154sp3cH41ngYNwS2aJXrCd+iFLUhLTlXerkI
	8p2i7aiOAWe1L3EspORttFSe6cP4/vBsgrBytmr0DwvoB7oDZLRWg+ctC13F01guoRzDFkCG0q0
	HeDZ/R1a2inYJehYVuQd5GZ2QAaqqYhU=
X-Received: by 2002:a05:651c:31d0:b0:3ab:344e:3740 with SMTP id
 38308e7fff4ca-3ae2b41f7efmr26811011fa.2.1794755850446; Sun, 15 Nov 2026
 07:17:30 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261115-sun8i-emac-mux-uaf-v3-1-c69d4189539d@gmail.com>
X-Reply-To: wens@kernel.org
X-Gmail-Original-Message-ID: <CAGb2v64aOydKdTWJEhF+0GVc45aap4AsHfF5RrL1pzOHF54D0A@mail.gmail.com>
X-Gm-Features: AclHuK9BiEy8NKHYdASo3pcVR5VPMQUIfo9KOqeQ5VGeVR52SQ6tBFPl-jC43Jc
X-Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>, Andrew Lunn <andrew+netdev@lunn.ch>, 
	"David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, 
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, 
	Maxime Coquelin <mcoquelin.stm32@gmail.com>, Alexandre Torgue <alexandre.torgue@foss.st.com>, 
	Jernej Skrabec <jernej.skrabec@gmail.com>, Samuel Holland <samuel@sholland.org>, 
	Philipp Zabel <p.zabel@pengutronix.de>, netdev@vger.kernel.org, 
	linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, 
	linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org