Article View: linux.kernel.netdev
Article #17008[PATCH net-next v2 1/2] net: tn40xx: avoid early firmware node release
From: Johan Hovold
Date: Mon, 16 Nov 2026 09:11
Date: Mon, 16 Nov 2026 09:11
48 lines
9734 bytes
9734 bytes
The mdiobus allocated by tn40_mdiobus_init() has no primary firmware
node so its firmware node pointer points to the secondary software node
added by device_add_software_node() and whose reference is released by
device_remove_software_node().
As device_remove_software_node() clears the firmware node pointer, any
reference taken by __mdiobus_register() needs to dropped before removing
the software node.
Add a comment explaining why the driver drops a reference it never took
itself, and only drop the firmware node reference if it was actually
taken by __mdiobus_register() as indicated by the bus state.
Note that __mdiobus_register() will essentially only return early
without taking the reference during development when the bus structure
has not been properly initialised. And currently, not even that would
lead to a use-after-free as the child PHY node holds a reference to the
parent MDIO node, the child is deregistered before the parent, and
software_node_unregister() returns early if the parent node has already
been freed.
Cc: Hans-Frieder Vogt <hfdevel@gmx.net>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/net/ethernet/tehuti/tn40_mdio.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/tehuti/tn40_mdio.c b/drivers/net/ethernet/tehuti/tn40_mdio.c
index fb1a4a2e4dbc..438f0d86c2a1 100644
--- a/drivers/net/ethernet/tehuti/tn40_mdio.c
+++ b/drivers/net/ethernet/tehuti/tn40_mdio.c
@@ -157,7 +157,12 @@ void tn40_swnodes_cleanup(struct tn40_priv *priv)
{
/* cleanup of swnodes is only needed for AQR105-based cards */
if (priv->pdev->device == PCI_DEVICE_ID_TEHUTI_TN9510) {
- fwnode_handle_put(dev_fwnode(&priv->mdio->dev));
+ /*
+ * drop any reference taken by __mdiobus_register() before
+ * device_remove_software_node() clears the fwnode pointer
+ */
+ if (priv->mdio->state != MDIOBUS_ALLOCATED)
+ fwnode_handle_put(dev_fwnode(&priv->mdio->dev));
device_remove_software_node(&priv->mdio->dev);
software_node_unregister_node_group(priv->nodes.group);
}
--
2.56.1
Technical Details
Message-ID:
<20261116091149.730586-2-johan@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364128-linux-kernel-netdev=dewy.ruReferences:
<20261116091149.730586-1-johan@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364128-linux-kernel-netdev=dewy.ru From: johan@kernel.org (Johan Hovold) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v2 1/2] net: tn40xx: avoid early firmware node release Date: Mon, 16 Nov 2026 10:11:48 +0100 Organization: Usenet Network Message-ID: <20261116091149.730586-2-johan@kernel.org> References: <20261116091149.730586-1-johan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2018781"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:B69IzWdVC95P8u4S+ATk2a7ls24= sha256:2hSYKZ5rLJnQbZKk8WWqtPdAjVT/1DGjfHaFWvWPUBA= sha1:rh/EWaRJKupcbzzatBFrzzAojIw= sha256:hAGGuSbOd8bmkLbAwhppCjUtzDmvMHs1h3RLVewuywk= 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 4C160114B71; Mon, 16 Nov 2026 12:13:01 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[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 GsRwuMX1_FlT; Mon, 16 Nov 2026 12:12:58 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-364128-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id E7373114B6D; Mon, 16 Nov 2026 12:12:48 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id DCB336013B5; Mon, 16 Nov 2026 09:12:46 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1794820359; b=z+adNkXQRyvSncKSZoM6L6g77DQc208HCNb8e0T27ORJE7EGkNMX/RohEbSA+CtNZRsL DDnVpjRLV/9X8Wq6pJBzeFAjiFPb4+3b8F9d4SnMLTw1wqkmu3MBF8BfmhmCoSVNcUjb5 8xpNipkEndFgvZ7mtWp+PxmLRmAEvPPvSu5q+mNJwh+LYM8sV6WWb62ziq+1/Ij3Fn2C/ y0mWmJ9+fH8G1TRu5fAEN6SCdX0FrLJoDnNWRXQStUagzWrSW5XtVVw4hL/CbDK+uOP37 3KQX2QFa1lznHDmyPiMkTwSibR8AKbqw5rOl4+6jH1PTst4Ro/Ff8+HpuOeX19am0AA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794820359; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=Da04wmYwtqF0rkK+5K+q7oVszxerDFXdV47u8Mj7Xow=; b=2obEC6XyzNIA3pCe/+eHxHWyS5REV9jhm6OdpBfowP0v39dbuQlBXo18kPlOah9wNL6J AQ5UMUkkSX75AOjdRA1ihLuIkUF0GoegdRJD7nxwbF+uutSMq6cQMvrzBYfrf2I4sEc0f EfIBpyix9+LsRgMvMqCCZyMPs4od3ylDKpJN0kKslyNnLAQrx0HmwrtA2NMTphHGg+o9f OhUqejJiq2iv5k2klXCBfIKjLEiS63aj3glagFs1QlCia8dK8W4XltmII4ctwaSGXEybm KkA7bTWphsOwhAyrCpik4c9jCll0zG0rAiuS1d+iC1HXGB71AZeFELK5pssP64WrXIQ== 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=P2zFV2V5; arc=fail 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 1AA6B606A889; Mon, 16 Nov 2026 09:12:39 +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=P2zFV2V5 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=1794820358; b=GFHjDQI+cn47214tPajw4laFA2YGORdgUD3LoAEWaVXCAjrimmwNB4EQVEDd1fHLEOWp 3dMCvxD84T6RkMr81Vj9nsSiEmBSkWc8dYa2Xr4g/1/SEBGHdDcjFYSYfeCsHe3QOC9SF hW0oZe1TirN7PZamVYYWrG37SdUqy8cNvVdwlERCsindOP493PTBPZLRrwAwA4H59pRSF Sw8fhtE5HXTKZUArhXsa9WTyvXXVPiQZhgNzeE9OIhUdkdyCHSTecc/FmC/mGjjHXVbwQ CfMc+GCoOuLPcpRXhWFJ+1r1ARtH1zW9ONr/1pmQ3eO6th/xTS0RKyXWlu2N/in75tA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794820358; h=Received:DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=Da04wmYwtqF0rkK+5K+q7oVszxerDFXdV47u8Mj7Xow=; b=ceYEkOmgYnMVu1lxjJC9drhaN1dkvBzgSkFDIk1t0t23hlNi4sIXb3pxcbCwG7vbxVkN zk/xPx/pcesuOw6rGw8LvM/VGHhneWZjtba5Ub+9rZiDBcVQC0tLebXI/CU3KVGhodLWj CBSoMC2zSDIYd6pulTWDZaHdN3pxQMghuC8A1GR/qZV/HWoPo8wVMa2T55wrGKO/edqBW ELxWeAgTwn7q54JRB8UvW8rNAFASu/0lpJyDfvfvSu8ISYwO6AADMfAhz3R0Ur1wqzdL1 2ebGrCgFopZrCNWR2+rPrUfZ+elgRgcwBo4iD9tzRwrM568y2co0smORA5LrsIg9lPA== 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=P2zFV2V5; 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 3BBDC606A33D for <netdev@vger.kernel.org>; Mon, 16 Nov 2026 09:12:37 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCDA11F000CF; Mon, 16 Nov 2026 09:12:37 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794820357; bh=Da04wmYwtqF0rkK+5K+q7oVszxerDFXdV47u8Mj7Xow=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=P2zFV2V5JqKzSGMj3knwwbFbWRYaBDoNEER6xWc1yVtAg9EiEXCiquDIld5FtEN6S g4igzAXHvuhCpkV2s2VyDOfLCZPnqWwiXz2SMAQRV3i3JVzj9EtAa8c4PJYGOsOT0p eVsMeBnhwBVavN5HOrxX5YrauA7awtV5BqTXXcgEqWZu1TDOQH7JuqGZ8qbMESHxhW 29FSVVcHeJUMktwWdAdu6NEBZR+RmhZarMUENGMHGoeifsfAb77yk7aIgH7tnW+Wh2 mCcO6AS2sopldVUGGh9nU8zzkNl4eAnqYLfmuxmt2Gdq6ek35tRFwzEYMSFZC2M5+k WV/eyfuv7RLIw== X-Received: from johan by xi.lan with local (Exim 4.100.1) (envelope-from <johan@kernel.org>) id 1xSslP-0000000344S-2Z4j; Mon, 16 Nov 2026 10:12:35 +0100 X-Cc: netdev@vger.kernel.org, Johan Hovold <johan@kernel.org>, Hans-Frieder Vogt <hfdevel@gmx.net> X-Mailer: git-send-email 2.56.1 X-In-Reply-To: <20261116091149.730586-1-johan@kernel.org> 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