From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48F69606A325 for ; Sun, 29 Nov 2026 23:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=qsq5hr3x; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Nsoe1wsn DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=vCSuUob2CmrulIg2RJ/lSsNcM4UPBQNq7Qom6HmGy38=; b=qsq5hr3xJY6K6o cqIvFmd/ZmUcBoqDRfj0hRaUT1GFAv6KaWNLazIQrg4qhUuHgvWZxLk30QKw7g2gUKDNIPDh4VU/V CVALxoHaFGFLsfPiz9f3Ae/C91nupIIdMjJo42EYEMh2tA+putygseMeoXD6/V9JwDBSL1JjpF8zJ 6MgNOc5KqDHgq9UyFU+Gan3kMl8s1DmJEBdqPgtQDny2LMI6TxJhwRNpBjW3cfgKAKZBy1lqWF6nK 9TUyuB6l/Kvct79zDZPaYNMvDXEnPuBLk5Crnq8XDu2MglZYXRvd3z+jLo9OEbcn8B/YEqvTtv6uy RNecsAvtGPgw4n/QrJNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXnyj-00000002ZYI-3hc3; Sun, 29 Nov 2026 23:06:41 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXnyQ-00000002ZM1-3xOX for linux-arm-kernel@lists.infradead.org; Sun, 29 Nov 2026 23:06:26 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-4ac109a8a12so5814454f8f.3 for ; Sun, 29 Nov 2026 15:06:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795993581; x=1796598381; darn=lists.infradead.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=Nsoe1wsnCemo9DcuDDsu4/vnlcSP/7bJsNBhNVKurDrt3ishkz/59psQQ6Z/qLg+fq HpPJEvoIfOx1tiKTnmkxGXLUf2wkR3MsmowtQdQcSjnj15+r+pFOYntkAYmNKOMMSz4E 17g/S/kumW3qImdPLN9OCZwi620/sVUtE4NmfNPQxC8cZw5+yi3zN9nkzO3hFAGStdet r1lYComxelvYfz98MqMF+2CqJtJoWkm9ogGaPizHSoZ07igclomF9lxQxaAeUKPse7Jh r1FlJNBvhHjfhJVQUQP4YvR8NAtsw84MZ0ZNltbIMi8eRZwjdJCK4FUui6Z6Kaew6ugp k+FA== 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/lSsNcM4UPBQNq7Qom6HmG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/cVL1HhI+qbCghe8HixbSxFNwBV/xj0Lmr/NnYBo+JZ3Xqlk39Ku9K 9/H3zsyBWYudrZfj/dD/zlay0GJ7jXxCPxX4jMXcF9Z1I0Q3QdU7qhpX/1Au7cda5icBzEhwjP/ wn+FOYoCWPfPqayZck47XQs320q8WQl4xYtKmnJ0DEVMgv6qPFQ3zUC4TDKZ3emp4oTCMate9bS EqSVjFdvaVUGx0TDgDg== 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) 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) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Willem de Bruijn , Simon Horman , Jonathan Corbet , Shuah Khan , Randy Dunlap , Christian Marangi , Lorenzo Bianconi , Heiner Kallweit , Russell King , Maxime Chevallier , Philipp Zabel , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, llvm@lists.linux.dev 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 Message-ID: <20261129230558.612526-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261129230558.612526-1-ansuelsmth@gmail.com> References: <20261129230558.612526-1-ansuelsmth@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261129_150623_038953_C532C040 X-CRM114-Status: GOOD ( 18.94 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- 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 #include #include +#include #include #include #include @@ -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