Skip to contentSkip to conversation

net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()

PATCH Applied Alexey Kodanev 5 participants 8 messages Jun 16, 2025 – Jun 19, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()

Before calling lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value of PCI11X1X_PTP_IO_MAX_CHANNELS(8). This seems correct and aligns with the PTP interrupt status register (PTP_INT_STS) specifications.

However, lan743x_ptp_io_event_clock_get() writes to ptp->extts[] with only LAN743X_PTP_N_EXTTS(4) elements, using channel as an index:

    lan743x_ptp_io_event_clock_get(..., u8 channel,...)
    {
        ...
        /* Update Local timestamp */
        extts = &ptp->extts[channel];
        extts->ts.tv_sec = sec;
        ...
    }

To avoid an out-of-bounds write and utilize all the supported GPIO inputs, set LAN743X_PTP_N_EXTTS to 8.

Detected using the static analysis tool - Svace.

Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")

---

v2: Increase LAN743X_PTP_N_EXTTS to 8

 drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/lan743x_ptp.h +2 -2
index e8d073bfa2ca..f33dc83c5700 100644
@@ -18,9 +18,9 @@
  */
 #define LAN743X_PTP_N_EVENT_CHAN	2
 #define LAN743X_PTP_N_PEROUT		LAN743X_PTP_N_EVENT_CHAN
-#define LAN743X_PTP_N_EXTTS		4
-#define LAN743X_PTP_N_PPS		0
 #define PCI11X1X_PTP_IO_MAX_CHANNELS	8
+#define LAN743X_PTP_N_EXTTS		PCI11X1X_PTP_IO_MAX_CHANNELS
+#define LAN743X_PTP_N_PPS		0
 #define PTP_CMD_CTL_TIMEOUT_CNT		50
 
 struct lan743x_adapter;
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 36 lines · Alexey Kodanev

Before calling lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value of PCI11X1X_PTP_IO_MAX_CHANNELS(8). This seems correct and aligns with the PTP interrupt status register (PTP_INT_STS) specifications.

However, lan743x_ptp_io_event_clock_get() writes to ptp->extts[] with only LAN743X_PTP_N_EXTTS(4) elements, using channel as an index:

    lan743x_ptp_io_event_clock_get(..., u8 channel,...)
    {
        ...
        /* Update Local timestamp */
        extts = &ptp->extts[channel];
        extts->ts.tv_sec = sec;
        ...
    }

To avoid an out-of-bounds write and utilize all the supported GPIO inputs, set LAN743X_PTP_N_EXTTS to 8.

Detected using the static analysis tool - Svace.

Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")

---

v2: Increase LAN743X_PTP_N_EXTTS to 8

 drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/lan743x_ptp.h +0 -0
index e8d073bfa2ca..f33dc83c5700 100644
@@ -18,9 +18,9 @@
  */

drivers/net/ethernet/microchip/lan743x_ptp.h line 26

Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_ptp.h +2 -2
 #define LAN743X_PTP_N_EVENT_CHAN	2
 #define LAN743X_PTP_N_PEROUT		LAN743X_PTP_N_EVENT_CHAN
-#define LAN743X_PTP_N_EXTTS		4
-#define LAN743X_PTP_N_PPS		0
 #define PCI11X1X_PTP_IO_MAX_CHANNELS	8
+#define LAN743X_PTP_N_EXTTS		PCI11X1X_PTP_IO_MAX_CHANNELS
+#define LAN743X_PTP_N_PPS		0
 #define PTP_CMD_CTL_TIMEOUT_CNT		50
 
 struct lan743x_adapter;
maintainer
#2 lore raw
In reply to Alexey Kodanev
Quoted 17 lines · Alexey Kodanev

Before calling lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value of PCI11X1X_PTP_IO_MAX_CHANNELS(8). This seems correct and aligns with the PTP interrupt status register (PTP_INT_STS) specifications.

However, lan743x_ptp_io_event_clock_get() writes to ptp->extts[] with only LAN743X_PTP_N_EXTTS(4) elements, using channel as an index:

    lan743x_ptp_io_event_clock_get(..., u8 channel,...)
    {
        ...
        /* Update Local timestamp */
        extts = &ptp->extts[channel];
        extts->ts.tv_sec = sec;
        ...
    }
Quoted 6 lines

To avoid an out-of-bounds write and utilize all the supported GPIO inputs, set LAN743X_PTP_N_EXTTS to 8.

Detected using the static analysis tool - Svace.

Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")

@Rengarajan: I see you suggested this approach on V1, but it would be nice to have explicit ack here (or even better in this case tested-by)

Thanks,

Paolo

maintainer
#3 lore raw
Quoted 21 lines · Paolo Abeni
Quoted 20 lines · Alexey Kodanev

Before calling lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value of PCI11X1X_PTP_IO_MAX_CHANNELS(8). This seems correct and aligns with the PTP interrupt status register (PTP_INT_STS) specifications.

However, lan743x_ptp_io_event_clock_get() writes to ptp->extts[] with only LAN743X_PTP_N_EXTTS(4) elements, using channel as an index:

    lan743x_ptp_io_event_clock_get(..., u8 channel,...)
    {
        ...
        /* Update Local timestamp */
        extts = &ptp->extts[channel];
        extts->ts.tv_sec = sec;
        ...
    }

To avoid an out-of-bounds write and utilize all the supported GPIO inputs, set LAN743X_PTP_N_EXTTS to 8.

Quoted 6 lines
Quoted 3 lines

Detected using the static analysis tool - Svace.

Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")

@Rengarajan: I see you suggested this approach on V1, but it would be nice to have explicit ack here (or even better in this case tested-by)

Rengarajan email address is bouncing. @Bryan: same request as above for you (or any other person @microchip).

Thanks,

Paolo

#4 lore raw
In reply to Paolo Abeni

Hi Paolo,

Quoted 28 lines · Paolo Abeni

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 24 lines · Alexey Kodanev

Before calling lan743x_ptp_io_event_clock_get(), the 'channel' value
is checked against the maximum value of PCI11X1X_PTP_IO_MAX_CHANNELS(8).
This seems correct and aligns with the PTP interrupt status register
(PTP_INT_STS) specifications.

However, lan743x_ptp_io_event_clock_get() writes to ptp->extts[] with
only LAN743X_PTP_N_EXTTS(4) elements, using channel as an index:

    lan743x_ptp_io_event_clock_get(..., u8 channel,...)
    {
        ...
        /* Update Local timestamp */
        extts = &ptp->extts[channel];
        extts->ts.tv_sec = sec;
        ...
    }

To avoid an out-of-bounds write and utilize all the supported GPIO inputs, set LAN743X_PTP_N_EXTTS to 8.

Quoted 8 lines
Quoted 4 lines

Detected using the static analysis tool - Svace.

Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event

Input External Timestamp (extts)")

@Rengarajan: I see you suggested this approach on V1, but it would be nice to have explicit ack here (or even better in this case tested- by)

Yes, I agree with the recent change made by Alexey to set LAN743X_PTP_N_EXTTS to 8. I have tested this on my end using GPIO numbers greater than 4 and did not encounter any issues. I will go ahead and provide my acknowledgment for Alexey's patch.

Thanks,
Rengarajan S

Quoted 5 lines

Thanks,

Paolo

Acked-by on v2 1/1
#5 lore raw
In reply to Alexey Kodanev

Hi Alexey,

Quoted 41 lines · Alexey Kodanev

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Before calling lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value of PCI11X1X_PTP_IO_MAX_CHANNELS(8).
This seems correct and aligns with the PTP interrupt status register (PTP_INT_STS) specifications.

However, lan743x_ptp_io_event_clock_get() writes to ptp->extts[] with only LAN743X_PTP_N_EXTTS(4) elements, using channel as an index:

    lan743x_ptp_io_event_clock_get(..., u8 channel,...)
    {
        ...
        /* Update Local timestamp */
        extts = &ptp->extts[channel];
        extts->ts.tv_sec = sec;
        ...
    }

To avoid an out-of-bounds write and utilize all the supported GPIO inputs, set LAN743X_PTP_N_EXTTS to 8.

Detected using the static analysis tool - Svace.

Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event

Input External Timestamp (extts)")

---

v2: Increase LAN743X_PTP_N_EXTTS to 8

 drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/lan743x_ptp.h +0 -0
index e8d073bfa2ca..f33dc83c5700 100644

drivers/net/ethernet/microchip/lan743x_ptp.h line 24

Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_ptp.h +2 -2
@@ -18,9 +18,9 @@
  */
 #define LAN743X_PTP_N_EVENT_CHAN       2
 #define LAN743X_PTP_N_PEROUT           LAN743X_PTP_N_EVENT_CHAN
-#define LAN743X_PTP_N_EXTTS            4
-#define LAN743X_PTP_N_PPS              0
 #define PCI11X1X_PTP_IO_MAX_CHANNELS   8
+#define LAN743X_PTP_N_EXTTS            PCI11X1X_PTP_IO_MAX_CHANNELS
+#define LAN743X_PTP_N_PPS              0
 #define PTP_CMD_CTL_TIMEOUT_CNT                50

Thanks for the update. Changing the LAN743X_PTP_N_EXTTS from 4 to 8 looks valid here.

Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_ptp.h +0 -1
 struct lan743x_adapter;
--

2.25.1

maintainer
#6 lore raw
Quoted 56 lines · On 6/19/25 12:39 PM, [email protected] wrote:
Quoted 41 lines · Alexey Kodanev

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Before calling lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value of PCI11X1X_PTP_IO_MAX_CHANNELS(8).
This seems correct and aligns with the PTP interrupt status register (PTP_INT_STS) specifications.

However, lan743x_ptp_io_event_clock_get() writes to ptp->extts[] with only LAN743X_PTP_N_EXTTS(4) elements, using channel as an index:

    lan743x_ptp_io_event_clock_get(..., u8 channel,...)
    {
        ...
        /* Update Local timestamp */
        extts = &ptp->extts[channel];
        extts->ts.tv_sec = sec;
        ...
    }

To avoid an out-of-bounds write and utilize all the supported GPIO inputs, set LAN743X_PTP_N_EXTTS to 8.

Detected using the static analysis tool - Svace.

Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event

Input External Timestamp (extts)")

---

v2: Increase LAN743X_PTP_N_EXTTS to 8

 drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/lan743x_ptp.h +0 -0
index e8d073bfa2ca..f33dc83c5700 100644

drivers/net/ethernet/microchip/lan743x_ptp.h line 24

Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_ptp.h +2 -2
@@ -18,9 +18,9 @@
  */
 #define LAN743X_PTP_N_EVENT_CHAN       2
 #define LAN743X_PTP_N_PEROUT           LAN743X_PTP_N_EVENT_CHAN
-#define LAN743X_PTP_N_EXTTS            4
-#define LAN743X_PTP_N_PPS              0
 #define PCI11X1X_PTP_IO_MAX_CHANNELS   8
+#define LAN743X_PTP_N_EXTTS            PCI11X1X_PTP_IO_MAX_CHANNELS
+#define LAN743X_PTP_N_PPS              0
 #define PTP_CMD_CTL_TIMEOUT_CNT                50

Thanks for the update. Changing the LAN743X_PTP_N_EXTTS from 4 to 8 looks valid here.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

struct lan743x_adapter;
--
2.25.1

Thanks!

FTR, I'm applying this patch to the 'net' tree as the issue is present there since a while and the change itself does not fit net-next IMHO.

/P

#7 lore raw
In reply to Alexey Kodanev
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Mon, 16 Jun 2025 11:37:43 +0000 you wrote:

Before calling lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value of PCI11X1X_PTP_IO_MAX_CHANNELS(8). This seems correct and aligns with the PTP interrupt status register (PTP_INT_STS) specifications.

However, lan743x_ptp_io_event_clock_get() writes to ptp->extts[] with only LAN743X_PTP_N_EXTTS(4) elements, using channel as an index:

[...]

Here is the summary with links:
- [net-next,v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()

    https://git.kernel.org/netdev/net/c/e353b0854d3a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html