All of lore.kernel.org
 help / color / mirror / Atom feed
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 v20 02/15] net: phylink: make PCS phylink instance access RCU protected
Date: Sun, 15 Nov 2026 10:45:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-215393@kernel.org> (raw)
In-Reply-To: <20261114104426.235620-3-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] net: phylink: NULL deref and stale pointer in
  phylink_major_config()
- [Low] net: phylink: missing Fixes trailer for commit 24699cc1ff3e
--

commit 85080154c47d10a2333a2099ea90e555d71ad4e7
Author: Christian Marangi <ansuelsmth@gmail.com>

> net: phylink: make PCS phylink instance access RCU protected
>
> In the context of phylink_pcs_change(), phylink instance is dereferenced
> from the pcs pointer present in the phylink_pcs struct.
>
> There is currently a fragility where this pcs pointer is never set NULL in
> phylink_destroy() and would reference invalid memory after phylink instance
> is freed.
>
> In this scenario, if a PCS driver calls phylink_pcs_change(), invalid
> memory can be dereferenced and phylink_link_changed() is called on freed
> memory.
>
> To address this, make the phylink instance saved in phylink_pcs struct RCU
> protected and access it under RCU lock.
>
> Also correctly reset the phylink instance pointer on phylink_destroy() and
> syncronyze RCU to catch an execution of phylink_pcs_change().
>
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>

[Severity: Low]
Since this fixes a use-after-free in phylink_pcs_change(), should it
include a Fixes tag for 24699cc1ff3e ("net: phylink: add support for PCS
link change notifications")?

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 6c339b25926cc..51c147eb8c2b6 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -1300,10 +1301,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(pcs->phylink, NULL);
>  
>  		if (pcs)
> -			pcs->phylink = pl;
> +			rcu_assign_pointer(pcs->phylink, pl);
>  
>  		pl->pcs = pcs;
>  	}

[Severity: High]
Should this clear pl->pcs->phylink instead of pcs->phylink?

When switching from an active PCS to an interface mode where pcs is NULL,
dereferencing pcs->phylink causes a NULL pointer dereference, regressing
0e4d7df2f3b2 ("net: phylink: fix NULL pointer deref in
phylink_major_config()").  When switching between two non-NULL PCS
instances, the old pl->pcs->phylink is never cleared, leaving a dangling
pointer to pl after phylink_destroy() frees it.

This regression is fixed later in the series by commit "net: phylink:
introduce internal phylink PCS handling".

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261114104426.235620-1-ansuelsmth@gmail.com?part=2

  reply	other threads:[~2026-11-15 10:45 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 10:43 [PATCH net-next v20 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 01/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 02/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-15 10:45   ` sashiko-bot [this message]
2026-11-14 10:43 ` [PATCH net-next v20 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 05/15] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 06/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 07/15] net: phylink: add capabilities helper and track modified advertising Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 10/15] net: Document PCS subsystem Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 15/15] net: airoha: add phylink support Christian Marangi
2026-11-15 10:45   ` sashiko-bot
2026-11-14 13:27 ` [PATCH net-next v20 00/15] net: pcs: Introduce support for fwnode PCS Frank Wunderlich

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-215393@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.