From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795993583; b=GylaJPorTfdok4SRLOPc+vFikS2Kfx/gpjVk3AqcLYMHGF2t6Pk6HweY9H6oqWpettdr dHg4hISsbMAZUb59mgQCmIqJPA+yPD5buccp8rS184sW5nHTQvRLzMu/FMEupY0ls+S4x 3/owSzyKoYjGO7DnBuTJhhxPAUjFkpCIUwNYBEZuPsHvzUHwI2RmgsSr9fFcKW/z3c80J wMn+lbihNA3xCt/QjzQ3D13dY4SC8Xq7Ei8R61tg3TDHTvLFTYHZIRLvNSW1cS/AuOe+e 6gUKj3ga4bKkLJDaM1cpJ3gceWRPS6HAFB9X9jJw3QSGGn5Toc/XBUPd3J6TmRFZldw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795993583; 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=mFlRMllbnEgs9m8eTLM7W1gcXaFMqfhVg9uNJqF6cwaB7IxjrD3tcfEBfncAyrPHfemT tEX8LB3idAuOEn92XFC1yPkYZORx8zZzBRoNq75VrmKZxgbyxrAgzMQVIOCyOoU3b6AN2 KnKxFuWQShoE/YCaB0lXgXHZeQBjfYJc86e+mnNhVVFzC8yhf6czHX2J6UEMSSNAmdyIE w6E32aFY0K9vUi09k9z57gnA7D1mHALkBtO6b1XoouJ/IUQWsSz9PZX3lU6cV8b9N7RFK N/b4OI3Ha96ntUAotN7HccXbP1EpH03EilDAEbxAlmosfIUGsGEzpZ8oHjVhqSDI3cw== 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.54 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 A6E2F606A33B for ; Sun, 29 Nov 2026 23:06:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A6E2F606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-490c3ae81d3so6193064f8f.2 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=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/lSsNcM4UPBQNq7Qom6HmGy38=; b=ka8BKcLZEbaldZ4Juka5PgDmQGSv0tDYb1Lz/WM/gj+CZcLm3cPGtXyOHKk74RikJQ K+QA/5hyz7Z5CxUUml3UA5nMrKjIDY/GyFtxbG7311HHZgvGQ0BDbaK9JWOnfTkTlP76 f/XXf+3dCMhuPtaSJqI9nPs6uCUxf2Z9kzcTsbSSaRWKJmw/+581Oc06SBjOM7IUOiGK S0c1WMCpPeJ+vtJxVA6YTtjgcMPcLpnAM4WwgkRhTgOw2QhW624Eic+KBkgiyfvA/D5r cgbuZysIPTiEE/E7VGNmoJOp+6OQ4Tn5UJiV1TGdrkwdpsOySiqaEqfnYXLRd+Tf+qJa Womg== X-Forwarded-Encrypted: i=1; AL+hErELX37dkrk3spal3mFAUNRsjQ5VBL6tZ3PKa+NS8Kj2AUA4bNuiq14XDt/7cvVNB4qX5ymXjE8HPo0=@vger.kernel.org X-Gm-Message-State: APuU4Z9fvuMlt9Kjf9ec269xhzDHsYEvS5tsEQpxdhZXcsl1SDwgQRBO o/UbypgBIypuYkN6lpoQd3sVB3qOviR+Gxc0RGW2c+xFdIoFYfGe7i5P X-Gm-Gg: AZFdTZcdAVtAdXqDQOP63gzn0rt9oOk+6hOEIvw+kKxzNvm35sqQrxkwPtoWOj6/V+n 1/yakEOt9JUUvai61To3vXgELqHpAIx1c5cvynfeH1qwnjUuBbs3K6OO29z9MQzvd/t0poEjAVo Zr71rzIdmcc7TmPXJ0xaVCVUV8KAsmE/4rkTjCHCGeg9gBT/eeKvZQp7Xqx48Dj3pP8cVg/YdOW sGKzxKj0dPfaEPE9dPVMLwPOMIxAq0IdOjiErv58syQi9xGreAKciMEQ4+8ye/mLUyW4oMi7KjA 3uwy5doAa1bNaiPEpXi/ngmR0bD6WRF6ETIufy1wUb4zyv3CqhIgXp7feN8Xi2xXguJp3W5GxVs aVInyyArQcmczGb7AYlvgGJJJQoZYYLPOb1mShOep8qwooTSasym6wVKgViao1iwvCskxvaXpG2 Uh5xQi+DAbTXwYInbUMZYm2qYqq++6kJgQjWJ2KkjzdF96yTLqsE1YcChxvKWLm0HSDcWvmBMNT Ws+gF59nUqvek8QUkwydM7FKmv/P5dW7S1wNm8i+F/KLumTSJnnqw/cxSsKulIjuuZH4TiqKp48 SfGL8Soc8bW3P6gAdhezJ3bPMiXugr5eS6yTM3TS6mrOi41hpvl54ikHo0FVHacNq7VPvUfFV1m q1o0xFEdr3wDwnNFfog== 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-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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