Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B19F2797AC for ; Wed, 25 Feb 2026 10:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772013691; cv=none; b=uLLk8+VFADJYiOZZWx8+3roR4x0hAYKKkUf7oB8oc2GEGlMlbHk+143ikSt3ZeoA/UxDLwMlHXgSt/TwI8u5MYa1l2bYjXxTfA9GVos30RXcpb/sm407BlyS0tO+imBlSnhmbCXkIFsU6DDfG7+Wavw+jQd4qs7e23rva68/Bgk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772013691; c=relaxed/simple; bh=wftJBCl/vWiQW7kZNuJyhe/wrFaM9lJOofFztIZiuK8=; h=From:To:Cc:Subject:MIME-Version:Content-Disposition:Content-Type: Message-Id:Date; b=GSonlFXgONUwi64DHlwsvpUgUcfigFVzegAjUP32mH/yazxPLxdXdu2kQMehEAuFsVybTc+/Qn7AVt2GaEWwbHxwKuvgajLKUjMsd5Qsw4MdlGfinn5msZuc6HZ7S/JGHCVUgYEn5nTwhMODIjHpDSAh6dOjP7SAJt6wsH3+WRY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=b81YPu5K; arc=none smtp.client-ip=78.32.30.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="b81YPu5K" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:Reply-To:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=odC0PopPEA/tOfTIBbe/FUrifUTRh+GoHfGQHk9LwPU=; b=b81YPu5KAlT+TCHG1tAH3zmUsq 5SMQWzwsxThMHslwKd9Oa5FYW/EWAgewCbEJM2eexmQMlTFaXCnSAI/C8ZCwBlxtKIdhN8vRTmpVm p5hzXKO6jtF6Ib1zlvh4qvfDUUTOZQMGsVMs2bxf0OW+NECM1Q4/4e294ll6DpNM9xn7LJ0EqFfji yErkAkwq2M3k+NaWNFVpZWNKz7jz0uzHdLcVZVFhx5rhh4V1CVFDWvlhtGlGqYjGCE8Gf3cVLnY0C CE4P7BKS6xP6CGBMjemCUGEGGRSM7W+Z0hnPahGFG3wViqGhn5jHnf83eof1ikxV6HT3wKKpzpxh/ LEWnG6hg==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:58662 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vvBho-000000006OO-3bIq; Wed, 25 Feb 2026 10:01:20 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.98.2) (envelope-from ) id 1vvBhn-0000000ArCg-4C4u; Wed, 25 Feb 2026 10:01:20 +0000 From: "Russell King (Oracle)" To: Andrew Lunn Cc: Alexandre Torgue , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Jose Abreu , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, netdev@vger.kernel.org, Paolo Abeni Subject: [PATCH net-next v2] net: stmmac: ptp: limit n_per_out Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Wed, 25 Feb 2026 10:01:19 +0000 ptp_clock_ops.n_per_out sets the number of PPS outputs, which the PTP subsystem uses to validate userspace input, such as the index number used in a PTP_CLK_REQ_PEROUT request. stmmac_enable() uses this to index the priv->pps array, which is an array of size STMMAC_PPS_MAX. ptp_clock_ops.n_per_out is initialised using priv->dma_cap.pps_out_num, which is a three bit field read from hardware. Documentation that I've checked suggests that values >= 5 are reserved, but that doesn't mean such values won't appear, and if they do, we can overrun the priv->pps array in stmmac_enable(). stmmac_ptp_register() has protection against this in its loop, but it doesn't act to limit ptp_clock_ops.n_per_out. Fix this by introducing a local variable, pps_out_num which is limited to STMMAC_PPS_MAX, and use that when initialising the array and setting priv->ptp_clock_ops.n_per_out. Print a warning when we limit the number of outputs. Reviewed-by: Simon Horman Signed-off-by: Russell King (Oracle) --- This could be a user exploitable bug (although one has to be root so the gun is already pointing at one's foot.) This is the commit which introduced the problem: Fixes: 9a8a02c9d46d ("net: stmmac: Add Flexible PPS support") v2: add warning print --- .../net/ethernet/stmicro/stmmac/stmmac_ptp.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index 3e30172fa129..98da499ba3b1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -334,14 +334,19 @@ const struct ptp_clock_info dwmac1000_ptp_clock_ops = { */ void stmmac_ptp_register(struct stmmac_priv *priv) { + unsigned int pps_out_num = priv->dma_cap.pps_out_num; int i; - for (i = 0; i < priv->dma_cap.pps_out_num; i++) { - if (i >= STMMAC_PPS_MAX) - break; - priv->pps[i].available = true; + if (pps_out_num > STMMAC_PPS_MAX) { + dev_warn(priv->device, + "pps outputs (%u) exceeds driver maximum, limiting to %u\n", + pps_out_num, STMMAC_PPS_MAX); + pps_out_num = STMMAC_PPS_MAX; } + for (i = 0; i < pps_out_num; i++) + priv->pps[i].available = true; + /* Calculate the clock domain crossing (CDC) error if necessary */ priv->plat->cdc_error_adj = 0; if (priv->plat->core_type == DWMAC_CORE_GMAC4) @@ -350,8 +355,8 @@ void stmmac_ptp_register(struct stmmac_priv *priv) /* Update the ptp clock parameters based on feature discovery, when * available */ - if (priv->dma_cap.pps_out_num) - priv->ptp_clock_ops.n_per_out = priv->dma_cap.pps_out_num; + if (pps_out_num) + priv->ptp_clock_ops.n_per_out = pps_out_num; if (priv->dma_cap.aux_snapshot_n) priv->ptp_clock_ops.n_ext_ts = priv->dma_cap.aux_snapshot_n; -- 2.47.3