Article View: linux.kernel.netdev
Article #24248[PATCH net-next v23 01/15] net: phylink: make PCS phylink instance access RCU protected
From: Christian Marangi
Date: Sun, 29 Nov 2026 23:05
Date: Sun, 29 Nov 2026 23:05
102 lines
13857 bytes
13857 bytes
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 pointer saved in phylink_pcs struct RCU
protected and access it under an RCU read lock. Use rcu_assign_pointer()
to update the pointer in phylink_major_config().
Also correctly reset the phylink instance pointer on phylink_destroy() and
unconditionally synchronize RCU to wait for any in-flight
phylink_pcs_change() calls, even if phylink_major_config() already cleared
the association.
Fixes: 24699cc1ff3e ("net: phylink: add support for PCS link change notifications")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/phy/phylink.c | 22 +++++++++++++++++++---
include/linux/phylink.h | 2 +-
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index d1f1142a98a4..d736604b86f4 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -17,6 +17,7 @@
#include <linux/phy_link_topology.h>
#include <linux/phy_port.h>
#include <linux/phylink.h>
+#include <linux/rcupdate.h>
#include <linux/rtnetlink.h>
#include <linux/spinlock.h>
#include <linux/timer.h>
@@ -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;
}
@@ -2157,6 +2158,16 @@ 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);
+
+ /*
+ * Unconditionally wait for readers that may have obtained this
+ * phylink through a PCS while phylink_major_config() was clearing
+ * the association.
+ */
+ synchronize_rcu();
+
cancel_work_sync(&pl->resolve);
kfree(pl);
}
@@ -2621,10 +2632,15 @@ EXPORT_SYMBOL_GPL(phylink_mac_change);
*/
void phylink_pcs_change(struct phylink_pcs *pcs, bool up)
{
- struct phylink *pl = pcs->phylink;
+ struct phylink *pl;
+ rcu_read_lock();
+
+ pl = rcu_dereference(pcs->phylink);
if (pl)
phylink_link_changed(pl, up, "pcs");
+
+ rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(phylink_pcs_change);
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index a7b6294cc4a0..27515d0bc57e 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -494,7 +494,7 @@ struct phylink_pcs_ops;
struct phylink_pcs {
DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
const struct phylink_pcs_ops *ops;
- struct phylink *phylink;
+ struct phylink __rcu *phylink;
bool poll;
bool rxc_always_on;
};
--
2.55.0
Technical Details
Message-ID:
<20261129230558.612526-2-ansuelsmth@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373691-linux-kernel-netdev=dewy.ruReferences:
<20261129230558.612526-1-ansuelsmth@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373691-linux-kernel-netdev=dewy.ru
From: ansuelsmth@gmail.com (Christian Marangi)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v23 01/15] net: phylink: make PCS phylink instance access RCU protected
Date: Mon, 30 Nov 2026 00:05:31 +0100
Organization: Usenet Network
Message-ID: <20261129230558.612526-2-ansuelsmth@gmail.com>
References: <20261129230558.612526-1-ansuelsmth@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1280789"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Ed9M2ooi+mwhTqFIazKLwgiR4fY= sha256:TaQniIWGkmKF5xr0izYBTBdnQ+M4ozTIDoypwXxk2LI=
sha1:bmwOBPBgTbdGQ4Nb9u7DuigcgI4= sha256:hppJZlayHcHgKEGAou9lh5XOVrHvR6GHPLkk4c9kxEM=
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 285BD125F08; Mon, 30 Nov 2026 02:06:51 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
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=gmail.com
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 SWHN9rYAR_Gr;
Mon, 30 Nov 2026 02:06:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373691-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id CE15F125FB1; Mon, 30 Nov 2026 02:06:35 +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 1B7D427556; Sun, 29 Nov 2026 23:06:26 +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=1795993583;
b=zbzfDtlE+P4chMvwV83Fcw+MsSqGwr0ZD00Phya7CkWxb1HU5cs0zDc/DbAt1ySB9NyG
2byiDeX01kSNxYIJqzIHyFSbLT8Xi6FogdVL0JEQCud7MdqxQSK/LLxV3bYiZR1vjzo1H
jDt8WFr21wzXldKPcJzwJU2TlspNhhM3py59QhCwFwkSfYmhoAKIQgScRTkROfT0HyOEG
8Cae07XGkgWsvK22qk47dEymaFAunsYjI3cyAVwelCAM8Wa4jimIUmWhGeSBFAuOG3884
7sc19eeYFCPr2gm8fBgdKvjanKyVtoyjHoYOfKGQiUApHhRflKKtHq+hgy2MZclIJuw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795993583;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To: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=vCSuUob2CmrulIg2RJ/lSsNcM4UPBQNq7Qom6HmGy38=;
b=uFQvYziIS8EabkiU0/BjOsdzkQWrpot45wi1rCcQjQIVrzsy5Fe934j6qfZ+9l2aZjzA
eK/e6c2/TRLpJiGTIJjBjwDyYERWGVCQYhfFN5c68AtXjDh6kEOOGcCtaP13BhzYytVM6
Q7FvgisetS+60KgWVIAUDAdAx0s5a6Pc1ELVMI5QuJTIo1cUraDmahaxPtaAtVqDC+pkl
AIxCiXx03xrunlCfvmsg+AGSdYsCom/QArB/IvAKCFcb959Oh+CAWLJQfchr1Oy0mKjY+
ohe4zhSzQBJrjjmmjL+/TonLV/3Za2nE7rwCluG5zWhwYTEaoRGAQ/UDKxhLnJm+yOg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=NVGA9f10;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 B6679606A692;
Sun, 29 Nov 2026 23:06:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=NVGA9f10
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.48
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795993582;
b=C6tkaOLEzGRKMxvlofHtsHoZxTIHPkkq60ggZv12/ed7PkrCn7T3uBr1wJiplO3KqfxW
3QKZywn9ehmf3fE5g5cfyquMZQy2IMK8yBp9fAieUkg5+NoSHGDCGWGN3izGt3M5lw7t4
FrFi8xVYTbE6mUBBGtiIyxBHeiVGx0eAhp7gIKEeXGeaVjl+EsfB+OXvjEv7fnxyhDKMH
W5ZE/XQ2EZXJZ32afV0/IaalTI2GtbbV+tC3EuvMqOH/nQQfOumWU/sex3HHH6LjbeF72
9iGm8eMIfw38XfY1JZKz38OSWthgAfQGNZBPlgK9B6jliUDdvOJpZEa2Ps3uiMcRctw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795993582;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
MIME-Version:Content-Transfer-Encoding;
bh=vCSuUob2CmrulIg2RJ/lSsNcM4UPBQNq7Qom6HmGy38=;
b=HaiO0I+OT0wlPNjlQtJ0HvjpDDZPDQc0izKrjBk+MBw/bPYJ7/t7Rs5KblMD8ce1WjcY
+pYakQOkekaP5Zv7R8Bb0sRPd3YUxZ7w65GsCr4X7MVcPJqauB20leGnlX776Y0nhRBXH
JHuIT7Cw8IEexDqTGUlvDH01MMwYNPqbE+Ahi9zwhh8QFXoh0Uo/LFot0leyq+pkR3fr0
5wmKM6lvCy3g4rcG21OqjDAiy0E6Gtp+Z5NjQX0osK4kDLslsImLuMTJxMw+KBVKX33ZO
2wIFXoWo7NawQ+Hf6MXzoM/JtamvIalkmVhnV08REWgczZ7UzcdIC9EytfmIPc/RFfQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=NVGA9f10;
arc=none smtp.remote-ip=209.85.221.48
X-Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95569606A337
for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 23:06:22 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 95569606A337
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-4a2f4ca0dcfso5640491f8f.1
for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 15:06:22 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795993581; x=1796598381; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:to:from:from:to:cc:subject:date:message-id
:reply-to:content-type;
bh=vCSuUob2CmrulIg2RJ/lSsNcM4UPBQNq7Qom6HmGy38=;
b=NVGA9f10AqpygOcVHD0X8nDtxyIRBCwf3DAF1mgT92fzPxgm13x4WxA8LdI+6NGENP
GCEgJ0cPq83wjsDYOLQ4blHNLT9gN8aPqU9JaEqnk6MNlvdwq5mVfFUZkxcV2hyngfLS
Y5k9oNxuBO8iIrHVd4OrCviEOx6MWTeXUEPSpuZ6L0khE2niWUQK+7XYOiN3gjogw7dz
ZqGulrirhGzxBz0CQlqJxmZwkByQA6cXkrLk0XIeDaHagETSlIr1pdnnB+NVqFvsSzEM
eT0Ys/j+GhRNg+BhXgP98vSFg4YRW9vngwoIH0TUu3XsOQOud4X+T4DWbEdgxp7iCSaZ
HoUg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795993581; x=1796598381;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to
:cc:subject:date:message-id:reply-to:content-type;
bh=vCSuUob2CmrulIg2RJ/lSsNcM4UPBQN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j+l86yut/786Mox8lAWgCMZtdzzuALui0hMCMky8XkyX0oPvOG2W8x
zu/Qut7k54pjLQGZfnK5lLkeStHVISZcUFZgi8WP4VyTbj1xY5wlG1RRtmD4+VqaNnHi9jTj/aS
Q38SCqsE2ilxnQIhaWsagr2s9/yFb7bGE4c2tl1wH3VbetItDQli0eOaYldcSIfdYN5emuYUVrm
P5/+J6xdypEkAoHQaNA==
X-Received: by 2002:a05:6000:2401:b0:4b4:2ce4:6dc4 with SMTP id ffacd0b85a97d-4b42ce46e8amr44931257f8f.48.1795993580865;
Sun, 29 Nov 2026 15:06:20 -0800 (PST)
X-Received: from Ansuel-XPS24 (93-34-92-103.ip49.fastwebnet.it. [93.34.92.103])
by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-4ab6c4353d6sm58448894f8f.56.2026.11.29.15.06.19
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sun, 29 Nov 2026 15:06:20 -0800 (PST)
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261129230558.612526-1-ansuelsmth@gmail.com>
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