From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected
Date: Wed, 18 Nov 2026 12:42:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-220921@kernel.org> (raw)
In-Reply-To: <20261117123956.11981-2-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: phylink: missing RCU grace period when pl->pcs becomes
NULL before destroy
--
commit 68e1704bb1480c2bf9abea1eeb40960aa3c24786
Author: Christian Marangi <ansuelsmth@gmail.com>
net: phylink: make PCS phylink instance access RCU protected
This commit protects pcs->phylink with RCU so that phylink_pcs_change()
safely dereferences the phylink instance under rcu_read_lock() and
phylink_destroy() clears the pointer and waits for a grace period before
freeing the phylink structure.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index e7734e45376cd..d9d0ace2042e5 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -1295,10 +1296,10 @@ static void phylink_major_config(struct phylink *pl, bool restart,
> phylink_pcs_disable(pl->pcs);
>
> if (pl->pcs)
> - pl->pcs->phylink = NULL;
> + rcu_assign_pointer(pl->pcs->phylink, NULL);
>
> if (pcs)
> - pcs->phylink = pl;
> + rcu_assign_pointer(pcs->phylink, pl);
>
> pl->pcs = pcs;
> }
> @@ -2137,6 +2138,11 @@ void phylink_destroy(struct phylink *pl)
> if (pl->link_gpio)
> gpiod_put(pl->link_gpio);
>
> + if (pl->pcs) {
> + rcu_assign_pointer(pl->pcs->phylink, NULL);
> + synchronize_rcu();
> + }
> +
> cancel_work_sync(&pl->resolve);
> kfree(pl);
> }
[Severity: Medium]
Can phylink_destroy() still free pl while phylink_pcs_change() is using it
if a prior phylink_major_config() switched pl->pcs to NULL?
When mac_select_pcs() returns NULL for a new interface mode (for example,
when switching from SGMII to RGMII), phylink_major_config() clears
pl->pcs->phylink and sets pl->pcs = NULL without waiting for an RCU grace
period. If phylink_destroy() then runs, it skips synchronize_rcu()
because pl->pcs is already NULL:
CPU0 CPU1
phylink_pcs_change(old_pcs, ...)
rcu_read_lock()
pl = rcu_dereference(old_pcs->phylink)
phylink_major_config(pl, ...)
rcu_assign_pointer(old_pcs->phylink, NULL)
pl->pcs = NULL
...
phylink_destroy(pl)
if (pl->pcs) -> false
cancel_work_sync(&pl->resolve)
kfree(pl)
phylink_link_changed(pl, ...)
pl->link_failed = true
phylink_run_resolve(pl)
<-- use-after-free
Calling synchronize_rcu() unconditionally in phylink_destroy(), or waiting
for a grace period when unpublishing pl->pcs->phylink, would close this
window.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117123956.11981-1-ansuelsmth@gmail.com?part=1
next prev parent reply other threads:[~2026-11-18 12:42 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-18 12:42 ` sashiko-bot [this message]
2026-11-17 12:39 ` [PATCH net-next v22 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-18 12:42 ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-18 12:42 ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 05/15] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 06/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-18 12:42 ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-18 12:42 ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-18 12:42 ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 10/15] net: Document PCS subsystem Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-18 12:42 ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-18 12:42 ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 15/15] net: airoha: add phylink support Christian Marangi
2026-11-17 12:43 ` [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
2026-11-17 12:47 ` Christian Marangi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-220921@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox