From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Jose Abreu <Jose.Abreu@synopsys.com>,
linux-arm-kernel@lists.infradead.org,
linux-stm32@st-md-mailman.stormreply.com, netdev@vger.kernel.org,
Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next] net: stmmac: ptp: limit n_per_out
Date: Mon, 23 Feb 2026 12:20:47 +0000 [thread overview]
Message-ID: <E1vuUvf-0000000AfhS-0lJR@rmk-PC.armlinux.org.uk> (raw)
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.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
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")
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 13 +++++++------
1 file changed, 7 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..cf5506bf2198 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -334,13 +334,14 @@ 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;
+ if (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;
@@ -350,8 +351,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
next reply other threads:[~2026-02-23 12:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 12:20 Russell King (Oracle) [this message]
2026-02-24 9:26 ` [PATCH net-next] net: stmmac: ptp: limit n_per_out Simon Horman
2026-02-24 10:02 ` Russell King (Oracle)
2026-02-24 11:29 ` Simon Horman
2026-02-25 2:18 ` Jakub Kicinski
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=E1vuUvf-0000000AfhS-0lJR@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=Jose.Abreu@synopsys.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox