Article View: linux.kernel.netdev
Article #11581Re: [PATCH net v3 05/14] net: pse-pd: do not reach a freed PHY from the notification worker
From: netdev-bot+sashiko
Date: Thu, 05 Nov 2026 10:08
Date: Thu, 05 Nov 2026 10:08
135 lines
12826 bytes
12826 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch changes what `pse_control::attached_phydev` means and
how it must be locked, but the kernel-doc was not updated to match.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
`pse_send_ntf_worker()` uses the net_device without holding aโฆ
--
net: pse-pd: do not reach a freed PHY from the notification worker
With this patch, pse_send_ntf_worker() looks up the pse_control and reads
attached_phydev under pse_list_mutex. It no longer relies on a reference
to the pse_control, so a removed PHY can no longer be reached. It also
clears attached_phydev and warns when a second PHY takes the same PI.
> diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
> index eab7e25f2039b..af9eb29792706 100644
> --- a/drivers/net/pse-pd/pse_core.c
> +++ b/drivers/net/pse-pd/pse_core.c
[ ... ]
> @@ -268,6 +266,7 @@ pse_control_find_by_id(struct pse_controller_dev *pcdev, int id)
> static struct net_device *pse_control_get_netdev(struct pse_control *psec)
> {
> ASSERT_RTNL();
> + lockdep_assert_held(&pse_list_mutex);
>
> if (!psec || !psec->attached_phydev)
> return NULL;
[Severity: Low]
This isn't a bug, but should the kernel-doc be updated to match the new
rules?
pse_control_find_by_id() got a "Must be called with pse_list_mutex held"
note. The kernel-doc of pse_control_get_netdev() still only says:
* Return: netdev pointer or NULL
The struct pse_control doc in pse_core.c also still describes the field as:
* @attached_phydev: PHY device pointer attached by the PSE control
After this patch, pse_control_get_internal() sets attached_phydev to NULL
as soon as a second PHY shares the PI. It stays NULL while PHYs still hold
the pse_control.
The field can also now only be read under pse_list_mutex. That rule is
written down only in the block comment inside pse_send_ntf_worker().
Could the struct doc and the pse_control_get_netdev() doc mention the
locking requirement and the shared-PI NULL case?
[ ... ]
> @@ -1015,13 +1014,23 @@ static void pse_send_ntf_worker(struct work_struct *work)
> struct net_device *netdev;
> struct pse_control *psec;
>
> - psec = pse_control_find_by_id(pcdev, ntf.id);
> + /* If attached_phydev is set, it names the only PHY that
[ ... ]
> + */
> rtnl_lock();
> + mutex_lock(&pse_list_mutex);
> + psec = pse_control_find_by_id(pcdev, ntf.id);
> netdev = pse_control_get_netdev(psec);
> if (netdev)
> ethnl_pse_send_ntf(netdev, ntf.notifs);
[Severity: High]
This is a pre-existing issue, but is the net_device itself still left
unprotected here?
The new locking keeps the phy_device alive. No reference is taken on
psec->attached_phydev->attached_dev, though.
ethnl_pse_send_ntf() dereferences that pointer in ethnl_fill_reply_header()
(dev->ifindex, dev->name) and in ethnl_multicast() (dev_net(dev)). Both
calls come after genlmsg_new(GFP_KERNEL), which can sleep.
Neither rtnl nor pse_list_mutex appears to keep the netdev alive. The
comment in phy_detach_internal() says:
* Drivers may detach without RTNL while dev is unregistered,
Also, free_netdev() asserts RTNL only while reg_state is
NETREG_UNREGISTERING. For a device that is already NETREG_UNREGISTERED it
goes straight to put_device().
As an in-tree example, hisi_femac_drv_remove() does:
unregister_netdev(ndev);
phy_disconnect(ndev->phydev);
clk_disable_unprepare(priv->clk);
free_netdev(ndev);
The last two calls there run without rtnl. Can this sequence happen?
worker hisi_femac_drv_remove()
unregister_netdev(ndev)
(rtnl released)
rtnl_lock()
mutex_lock(&pse_list_mutex)
pse_control_get_netdev()
returns attached_dev (still set)
ethnl_pse_send_ntf()
genlmsg_new(GFP_KERNEL) sleeps
phy_disconnect()
free_netdev()
put_device() frees the netdev
ethnl_fill_reply_header(skb, netdev, ...)
reads the freed netdev
The old worker also passed a netdev it held no reference to into
ethnl_pse_send_ntf(), so this predates the patch. The commit message only
covers the phy_device, and the code is unchanged at the end of the series.
Does the lifetime of the net_device need to be pinned here as well, in
addition to the phy_device?
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103220217.1131971-1-github%40szelinsky.de
Technical Details
Message-ID:
<179387331238.488856.9819726671704590547@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357203-linux-kernel-netdev=dewy.ruReferences:
<20261103220217.1131971-6-github@szelinsky.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357203-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v3 05/14] net: pse-pd: do not reach a freed PHY from the notification worker Date: Thu, 05 Nov 2026 10:08:32 +0000 Organization: Usenet Network Message-ID: <179387331238.488856.9819726671704590547@kernel.org> References: <20261103220217.1131971-6-github@szelinsky.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3611913"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:WPYJ8wZkAwH9S4S9A3zdT/334x8= sha256:W4v4OB61ZbPiL5qvy80CVjRIgKQW8nfFjYbZcAssrOI= sha1:HZcD/FCZkFLzqHg2VfenCHta4LA= sha256:2yvoMWKEw/JMsPxmWn8+rmRgsgyZYHMz1jnKPPf00+A= 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 BDEC2112F08; Thu, 5 Nov 2026 13:25:27 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 Elk3ECo_cLJu; Thu, 5 Nov 2026 13:25:24 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-357203-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id E1342112EF5; Thu, 5 Nov 2026 13:25:15 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 40E9F456B0; Thu, 5 Nov 2026 10:12:17 +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=1793873315; b=w2Wh1wixIqxss5ILGsa5T0Gsi//iRFD+KCP2/7LBiCfuzcxnzJbuqHaJyRXI4l1OP2rt hQZq8FZbEAmnxNRrND5dnnhNNZR/Aijo2LmrdoD9RvPCeigrPK+DPR54EayMrTYELMiGr yhlmMBODqxYxz05LVJu6IvqWEMlfZWmNbhMcM8lwtuTUf9ZPKDDajosfTZARUfdq6AZ6L Xqcj8M5eYgdW3JCzerVWnAjssgEOpr3buxxM+gWuKLjPwJMm+lveXo9GxDudj9t69BDyx 91PSir9DRIxpxDXpdR4ZdF6jqtTIj+pS5NJOIVKmG+4zgcnzITUNwz1fNsOVG4Mvuyg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793873315; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=TEM5oG0EbwSOS98Fx4qqr6WHxDPmtVe3raulzRfg0YI=; b=b8M5GPzQWnGacKFaIcEd/Fk+L72TThoIvJrNv/UfdU6qPtsCxkNlfTy6g/3JpdU5L0BU T0t87+cMvIdRKr8svA3vKmW3jgvvW3+lE350NmrcthHAV+GF/ncKPEy7Fda1rNnsy/s4M weTY1TJDxv/azuSPXI3K+eTwFuaFpSg4FDXt42YLCU7qbX4ThdC3rS8GZ3wuAzC1tNoyX mV8hGfois4AChnJ+bHHJLqoYIR0aHcy7ExC+G5U5OFCkObRw5WvAM6NrEE1LhFUD2bOuo PF0WMfOwKyllCBQ7OZu+yYZelUoxn0ybNF1MVHWwqwk0rxaLD05CbVkJc6pR0ZnwiVw== 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=XVw1Ne30; 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 5F1EF6083619; Thu, 5 Nov 2026 10:08:35 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XVw1Ne30 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=1793873314; b=mfg7A3RpyaiEWOpYbI4vpoRH78d6ZRCnoqVdozkGmFg6KedHC3Y69yqrLaWQjkog71XZ cfEo3ZW7yT6m07Ux7cJOnpK3psYeBsgVvVKbBsVEWGG6vywbJ4jbaHZc0R/27NwQIrX14 3bSV/59HU8QpI51gpKqwQ15t3NM5IcihnMnUcxhyk1HUStMZ41RThq98aar+kBHl3vvSA LJnp+icy4lSfLOm7Gvg3DPTtNZdjPDk4RK4bIrHmaCzWK2jjErFmVw2cH3SLo9wKWCdDt LdZzvKYfMk9YIPGKSlF8TR/SJsQTqipZdXLqVYfdDg4Sdar/LQqoxjvj7ZDCr/zkyVg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793873314; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=TEM5oG0EbwSOS98Fx4qqr6WHxDPmtVe3raulzRfg0YI=; b=tmtFIKM6AF/ZGVxGWhAeSrVbvzrE/G950IIITHgWSNBW63Txs9wbCX9j9yRdcLge57oi yHSWL+vKAhphh5NFRxWFbAxiJ4xwpj8zH//2kNk+VweVs7dVVFOO2DqhdA+zckey1rkKm LnT7jy++UGN3SUAuCSiVPuUSSgWXxtx1NUjHhFAQ8Tq2JuqBOgRrEYUjh8nvCgbbdfhva v4ZBFHDkkW9tdSWLiO2QmR6oGf1CDAXqryDC8VW6I7DwlKvjyHB2Ed/AEOQlCDQ1T4OBG jnQTZvsY0WQVBAfXn4zq8fjnZAigFNRWUJW0Fgw7wAlz8CTPfqvK7FfQx/ziDIY229A== 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=XVw1Ne30; 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 3D5B3606EE86; Thu, 5 Nov 2026 10:08:34 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4D9D1F00919; Thu, 5 Nov 2026 10:08:32 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793873313; bh=TEM5oG0EbwSOS98Fx4qqr6WHxDPmtVe3raulzRfg0YI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=XVw1Ne30HCouQB1rwdBXS0bjIUenJoHnpLT80ZPc+Mc82gb3zxipikX7c7XaP8zTY Hdlthv/tBNDBl3pwdCGK3UCM1Jv6O/IXCuhmnAXDxp95tY2xz5RN3dgGbw5IDsnRIG 0PGLpKaNEQpc7N9yYFCiHDR8ArS1Igmst9EZlJE3MekyXmkcFAP04HdP64RyZPq1AU XgI5mGV1LqHwBc6vdArl4jSbQICyS+xGzfWUc5sHbezomj1Q5bi1vy7Rbs/LqrpEY/ 748dFmw0C7esiu3ykmfoKH2bP8eq9fgxMAB5mpS1m1KRXNGveP1m0p82XKBTy+NTWG ftiw1w+ecs+pA== X-Cc: o.rempel@pengutronix.de, kory.maincent@bootlin.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, broonie@kernel.org, lgirdwood@gmail.com, maxime.chevallier@bootlin.com, kyle.swenson@est.tech, ross@r-sc.ca, netdev-bot+sashiko@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org X-In-Reply-To: <20261103220217.1131971-6-github@szelinsky.de> X-sashiko-severity: Low 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