net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
Subsystems (3)
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.
---
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
@@ -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 50struct lan743x_adapter ;
Signature · 1 line
2.25.1
Quoted 36 lines · Alexey Kodanev
Before calling
lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value ofPCI11X1X_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 onlyLAN743X_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_EXTTSto 8.Detected using the static analysis tool - Svace.
Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")Signed-off-by Alexey Kodanev <[email protected]>---
v2: Increase
LAN743X_PTP_N_EXTTSto 8drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/microchip/lan743x_ptp.h +0
-0@@ -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 50struct lan743x_adapter ;
Paolo Abeni
maintainerQuoted 17 lines · Alexey Kodanev
Before calling
lan743x_ptp_io_event_clock_get(), the 'channel' value is checked against the maximum value ofPCI11X1X_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 onlyLAN743X_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_EXTTSto 8.Detected using the static analysis tool - Svace.
Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO Event Input External Timestamp (extts)")Signed-off-by Alexey Kodanev <[email protected]>
@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
Paolo Abeni
maintainerQuoted 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 ofPCI11X1X_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 onlyLAN743X_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_EXTTSto 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)")Signed-off-by Alexey Kodanev <[email protected]>@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
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 ofPCI11X1X_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
onlyLAN743X_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_EXTTSto 8.
Quoted 8 lines
Quoted 4 lines
Detected using the static analysis tool - Svace.
Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO EventInput External Timestamp (extts)")
Signed-off-by Alexey Kodanev <[email protected]>@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
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 ofPCI11X1X_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 onlyLAN743X_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_EXTTSto 8.Detected using the static analysis tool - Svace.
Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO EventInput External Timestamp (extts)")
Signed-off-by Alexey Kodanev <[email protected]>---
v2: Increase
LAN743X_PTP_N_EXTTSto 8drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/microchip/lan743x_ptp.h +0
-0
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
-1struct lan743x_adapter ; --2.25.1
Paolo Abeni
maintainerQuoted 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 ofPCI11X1X_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 onlyLAN743X_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_EXTTSto 8.Detected using the static analysis tool - Svace.
Fixes 60942c397af6 ("net: lan743x: Add support for PTP-IO EventInput External Timestamp (extts)")
Signed-off-by Alexey Kodanev <[email protected]>---
v2: Increase
LAN743X_PTP_N_EXTTSto 8drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/microchip/lan743x_ptp.h +0
-0drivers/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 50Thanks for the update. Changing the
LAN743X_PTP_N_EXTTSfrom 4 to 8 looks valid here.Quoted 1 line
Quoted 6 lines
Quoted 4 lines
struct
lan743x_adapter;
--
2.25.1Acked-by Rengarajan S <[email protected]>
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
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 ofPCI11X1X_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 onlyLAN743X_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