Article View: linux.kernel.netdev
Article #19645Re: [PATCH net v5 05/14] net: pse-pd: do not reach a freed PHY from the notification worker
From: netdev-bot+sashiko
Date: Fri, 20 Nov 2026 06:41
Date: Fri, 20 Nov 2026 06:41
134 lines
13050 bytes
13050 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 new kernel-doc implies that a NULL attached_phydev is
temporary, but the code makes it permanent.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
pse_send_ntf_worker() can still use a freed net_device.
--
net: pse-pd: do not reach a freed PHY from the notification worker
The notification worker used to keep a reference on the pse_control and
then dereference psec->attached_phydev, which could already be freed. With
this patch the worker looks up the pse_control and reads attached_phydev
under pse_list_mutex, nested inside rtnl. When a second PHY takes a shared
PI, pse_control_get_internal() now clears attached_phydev and warns.
> diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
> index 0894613515e0d..b8cba6f86a7fd 100644
> --- a/drivers/net/pse-pd/pse_core.c
> +++ b/drivers/net/pse-pd/pse_core.c
> @@ -31,7 +31,9 @@ static DEFINE_MUTEX(pse_pw_d_mutex);
> * @list: list entry for the pcdev's PSE controller list
> * @id: ID of the PSE line in the PSE controller device
> * @refcnt: Number of gets of this pse_control
> - * @attached_phydev: PHY device pointer attached by the PSE control
> + * @attached_phydev: PHY device pointer attached by the PSE control, or NULL
> + * when several PHYs share the PI. Read it only under
> + * pse_list_mutex.
[Severity: Low]
This isn't a bug, but "NULL when several PHYs share the PI" reads as if
the field is only NULL while the PI is shared. Is that what is intended?
The only writes to attached_phydev are the assignment when the pse_control
is created and the new clear in pse_control_get_internal(). Neither
pse_control_put() nor __pse_control_put_internal() sets it back.
So if PHY A and PHY B share a PI and B is removed, only A holds the
pse_control, but attached_phydev stays NULL. The commit message describes
this:
Events for that PI are then no longer reported, even after one PHY goes
away.
The new pse_control_get_netdev() kernel-doc has the same problem:
Return: netdev pointer, or NULL if no single PHY is attached
It also leaves out the NULL return when the single PHY has no
attached_dev.
Would wording like "NULL once the PI has been shared by several PHYs"
match the code better?
[ ... ]
> @@ -1014,13 +1017,18 @@ 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);
> + /* pse_control_put() frees the pse_control under
> + * pse_list_mutex before its PHY is freed, so the mutex
> + * keeps attached_phydev valid.
> + */
> 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, not one introduced by this patch, but can
the worker still use a freed net_device here?
pse_control_get_netdev() returns psec->attached_phydev->attached_dev
without taking a netdev reference. ethnl_pse_send_ntf() then dereferences
it in ethnl_fill_reply_header() and ethnl_multicast().
Neither rtnl nor pse_list_mutex excludes the paths that clear attached_dev
or free the netdev. phy_detach_internal() clears it without needing rtnl:
drivers/net/phy/phy_device.c:phy_detach_internal() {
...
phydev->attached_dev->phydev = NULL;
phydev->attached_dev = NULL;
...
}
Its own comment says "Drivers may detach without RTNL while dev is
unregistered". free_netdev() on a NETREG_UNREGISTERED device does not need
rtnl either.
usbnet_disconnect() is one example of a remove path that does all of this
outside rtnl:
CPU0 (usbnet_disconnect) CPU1 (pse_send_ntf_worker)
unregister_netdev(net);
rtnl_lock();
mutex_lock(&pse_list_mutex);
netdev = pse_control_get_netdev(psec);
/* attached_dev still set */
->unbind()
smsc95xx_unbind()
phy_disconnect()
free_netdev(net);
ethnl_pse_send_ntf(netdev, ...);
The PHY stays on the MDIO bus in this sequence, so psec and attached_phydev
remain valid, and the new pse_list_mutex scheme does not cover the netdev.
Does the worker also need a lifetime guarantee for the netdev? For
example, a netdev reference taken when the PHY is attached, or a reg_state
check together with serialisation against phy_detach.
> + mutex_unlock(&pse_list_mutex);
> rtnl_unlock();
> - pse_control_put(psec);
> }
> }
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118183957.2031311-1-github%40szelinsky.de
Technical Details
Message-ID:
<179515690895.3136.4077280921885475671@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367708-linux-kernel-netdev=dewy.ruReferences:
<20261118183957.2031311-6-github@szelinsky.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367708-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v5 05/14] net: pse-pd: do not reach a freed PHY from the notification worker Date: Fri, 20 Nov 2026 06:41:48 +0000 Organization: Usenet Network Message-ID: <179515690895.3136.4077280921885475671@kernel.org> References: <20261118183957.2031311-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="3084774"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:4jhCbpeqTp16dM6IC8Igw4dxUss= sha256:0pIkeVAh3Ks7ssYuUAkhDr6o/sMWpWmL6ZmxYMl/3/8= sha1:wlseSrFeji4vLZq0g7yqG7708Qc= sha256:dmOfOKq5AaFiubZQW3IATp5zR/ZhrC+inGuHZdxfGwU= 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 765781158CD; Fri, 20 Nov 2026 09:42:28 +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 w3xB85e_DcaM; Fri, 20 Nov 2026 09:42:24 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-367708-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 B7C301158A8; Fri, 20 Nov 2026 09:42:16 +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 50872688B1E; Fri, 20 Nov 2026 06:42:16 +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=1795156916; b=MvnN0RfUMQyKkkAd2iRlKlfEA/+qKSxwG3IvbFqIgegEShH8EufIgMk2FUtpHbCJP7Bi QFiMAuULhkHTpKPfrEuX6dlKlIM97f5UOHWIO1MPVHNXVRjJOPcF5GD2DgL40dWH/BMbW XPT9cYJcYNdoB+t1vOpTUq2QjRTEY/oEVsl8r2az3mz7CnmxcdvWC5KK7r+rtk0mC+f9R TntpEsuWfGjIOjLk4wFzzGu/6mykzAMELyl8gQVvLKOr1iCT1ItzeYZgaUoG72ihoc0KY iroKFG+wG+B+a8Umb9T03jnigV8j7lMcT0rUjHlb/mPB9s7GKBHmJmj+Phtsfhrj0rg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795156916; 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=IRZ/wGMOyJ5LcJ+jaX3m0mIFpWsy18PNSRPcCe3MKuE=; b=pbZ5BvIE5vDF6xsdFz8KmhElaEYX0dtFzxqfF0J7PwifyGEic+khRV16tNZrqCWVImxm 1uNdHFDcNcXH3OKHw7bn4DnNMPyxjMkZSeuX2dnR9MEW9Q/fm0prUAgIeiSIT2tV5sAyc AxIDMb+2IUbb7pW4oCVy8pGhfBVudLJmFt9oQ6klBWLPyCPuhomefPpxdgkhH/8rWN0tT clsBnqZIrhTlt/ZoS6fJiNESTXtGH9ReF/JdDPIyeBVclfz9UUtPRd6laZ+aD4+sPUEVu uA0n1dXoqFc1YFs/hJCd96jCvAouwH/uSyI3MENQe4OApIVQqIjtA35MnNWDq4YteTg== 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=fn4gF4jR; 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 8369560A2600; Fri, 20 Nov 2026 06:41:56 +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=fn4gF4jR 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=1795156910; b=IAVIZ7Z8aO64V5FI4nehMWdEdd0pVAPJl65GyWAvl68YLJQru47cSbk5/p6e99e0Vi6w i2+kZxy0wGqbzEI58IK1g97YscXgyENZyaPu9hSv4Q6C2wKkrs2BCA+ebo/9ySJ0BPGD3 Qxoo0U1y6M60oEZkcapxzTxu1WsQbWbqVwMV+ck06ahd3lEqf92UYPyZCkyi4qqLlGTM/ 1GHldukwKP7HcilTE0QZ8/HJ+t+8pXdaOSMNYMKKSKmdDA3EEIKRjGEbYtNSfesKRbbAB 1EVF3m2uEO6rw86jQMDv8onfA1DJ3HUZPtKGiWf8cYfIKW3+XMpB1SK+FGc5uDxp1iQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795156910; 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=IRZ/wGMOyJ5LcJ+jaX3m0mIFpWsy18PNSRPcCe3MKuE=; b=D4hkqXRm6PI4wOT22Y34iMRlBnRC2W2KoItIXoNT+ro//Gmx69NwqPXDUbPW1ij7/Rva Yl0IMAnlUgyIT+l/j2fVDaU7OPILpP+d5gydLId/NMmmLGIS6H6GgrbTNJBqY2OlkuUSa dVW5rn3wh3gU8tFq8BadKIxD+AWo8ABYr5FZ7ze9OgSqfgWTUS84GzqsolQ+fdd7GqmXe 7odA2XOIQspBUyQa+NVBUZRAGc2UBzvCxRihoITdQ8fmynQK4pKRn+wtmjDhxxtgYkDJ4 a+3m0fJZxvC21hXiaSv/UXF6HWoyUOyq+y+shXlpV/4liU58fmq38Z4VuzZ+VJXysCQ== 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=fn4gF4jR; 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 A1A6A606A338; Fri, 20 Nov 2026 06:41:50 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 605AB1F000C4; Fri, 20 Nov 2026 06:41:49 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795156910; bh=IRZ/wGMOyJ5LcJ+jaX3m0mIFpWsy18PNSRPcCe3MKuE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=fn4gF4jRKevviH9eBsmOfW6t6x8UvK2FDmhQAFtog2tZ2O62cXmjn1mdxP9ulVhlB VY34HBtiYo6Y8w9khXRUryF+xU3i08z3RIpfRJKc5jQVUNacxwQ5AoBzRdH/K8mBiN EbrlwteoEs0YZDGh9/F2wWzeN633n5rRY7BLMCx23Tpu+JSZ5YVFmbfqF1cao4/w4i kWyrFlqzeLOnqf+SejstU9dMhC7Qc76IDjVGy0YNSPsS13EX2kmEV4oO8YQG8HCg/m rXmDyE0BiGKjYnGCVpenCl5EY06kF26kxbS/5hyKkY1RbQuxWH10gm7waot9XiMZmg sCrjO13r2764g== 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: <20261118183957.2031311-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