netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
@ 2025-06-16 11:37 Alexey Kodanev
  2025-06-16 22:22 ` Jacob Keller
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Alexey Kodanev @ 2025-06-16 11:37 UTC (permalink / raw)
  To: netdev
  Cc: Rengarajan.S, Bryan Whitehead, UNGLinuxDriver, Raju Lakkaraju,
	Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Richard Cochran, 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)")
Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
---

v2: Increase LAN743X_PTP_N_EXTTS to 8

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

diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.h b/drivers/net/ethernet/microchip/lan743x_ptp.h
index e8d073bfa2ca..f33dc83c5700 100644
--- a/drivers/net/ethernet/microchip/lan743x_ptp.h
+++ b/drivers/net/ethernet/microchip/lan743x_ptp.h
@@ -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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
  2025-06-16 11:37 [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get() Alexey Kodanev
@ 2025-06-16 22:22 ` Jacob Keller
  2025-06-19 10:04 ` Paolo Abeni
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Jacob Keller @ 2025-06-16 22:22 UTC (permalink / raw)
  To: Alexey Kodanev, netdev
  Cc: Rengarajan.S, Bryan Whitehead, UNGLinuxDriver, Raju Lakkaraju,
	Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Richard Cochran



On 6/16/2025 4:37 AM, Alexey Kodanev 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:
> 
>     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)")
> Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
> ---
> 
> v2: Increase LAN743X_PTP_N_EXTTS to 8
> 
>  drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.h b/drivers/net/ethernet/microchip/lan743x_ptp.h
> index e8d073bfa2ca..f33dc83c5700 100644
> --- a/drivers/net/ethernet/microchip/lan743x_ptp.h
> +++ b/drivers/net/ethernet/microchip/lan743x_ptp.h
> @@ -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;

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
  2025-06-16 11:37 [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get() Alexey Kodanev
  2025-06-16 22:22 ` Jacob Keller
@ 2025-06-19 10:04 ` Paolo Abeni
  2025-06-19 10:26   ` Paolo Abeni
  2025-06-19 10:35   ` Rengarajan.S
  2025-06-19 10:39 ` Rengarajan.S
  2025-06-19 13:50 ` patchwork-bot+netdevbpf
  3 siblings, 2 replies; 8+ messages in thread
From: Paolo Abeni @ 2025-06-19 10:04 UTC (permalink / raw)
  To: Alexey Kodanev, Rengarajan.S, netdev
  Cc: Bryan Whitehead, UNGLinuxDriver, Raju Lakkaraju, Andrew Lunn,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Richard Cochran

On 6/16/25 1:37 PM, Alexey Kodanev 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:
> 
>     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)")
> Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>

@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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
  2025-06-19 10:04 ` Paolo Abeni
@ 2025-06-19 10:26   ` Paolo Abeni
  2025-06-19 10:35   ` Rengarajan.S
  1 sibling, 0 replies; 8+ messages in thread
From: Paolo Abeni @ 2025-06-19 10:26 UTC (permalink / raw)
  To: Alexey Kodanev, netdev, Bryan Whitehead
  Cc: UNGLinuxDriver, Raju Lakkaraju, Andrew Lunn, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Richard Cochran, Rengarajan.S

On 6/19/25 12:04 PM, Paolo Abeni wrote:
> On 6/16/25 1:37 PM, Alexey Kodanev 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:
>>
>>     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)")
>> Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
> 
> @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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
  2025-06-19 10:04 ` Paolo Abeni
  2025-06-19 10:26   ` Paolo Abeni
@ 2025-06-19 10:35   ` Rengarajan.S
  1 sibling, 0 replies; 8+ messages in thread
From: Rengarajan.S @ 2025-06-19 10:35 UTC (permalink / raw)
  To: aleksei.kodanev, netdev, pabeni
  Cc: andrew+netdev, Bryan.Whitehead, davem, Raju.Lakkaraju, kuba,
	richardcochran, edumazet, UNGLinuxDriver

Hi Paolo,

On Thu, 2025-06-19 at 12:04 +0200, Paolo Abeni wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> On 6/16/25 1:37 PM, Alexey Kodanev 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:
> > 
> >     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)")
> > Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
> 
> @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

> 
> Thanks,
> 
> Paolo
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
  2025-06-16 11:37 [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get() Alexey Kodanev
  2025-06-16 22:22 ` Jacob Keller
  2025-06-19 10:04 ` Paolo Abeni
@ 2025-06-19 10:39 ` Rengarajan.S
  2025-06-19 13:31   ` Paolo Abeni
  2025-06-19 13:50 ` patchwork-bot+netdevbpf
  3 siblings, 1 reply; 8+ messages in thread
From: Rengarajan.S @ 2025-06-19 10:39 UTC (permalink / raw)
  To: aleksei.kodanev, netdev
  Cc: andrew+netdev, Bryan.Whitehead, davem, Raju.Lakkaraju, pabeni,
	kuba, edumazet, UNGLinuxDriver, richardcochran

Hi Alexey,

On Mon, 2025-06-16 at 11:37 +0000, Alexey Kodanev wrote:
> 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)")
> Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
> ---
> 
> v2: Increase LAN743X_PTP_N_EXTTS to 8
> 
>  drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.h
> b/drivers/net/ethernet/microchip/lan743x_ptp.h
> index e8d073bfa2ca..f33dc83c5700 100644
> --- a/drivers/net/ethernet/microchip/lan743x_ptp.h
> +++ b/drivers/net/ethernet/microchip/lan743x_ptp.h
> @@ -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.

> 
>  struct lan743x_adapter;
> --
> 2.25.1
> 

Acked-by: Rengarajan S <rengarajan.s@microchip.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
  2025-06-19 10:39 ` Rengarajan.S
@ 2025-06-19 13:31   ` Paolo Abeni
  0 siblings, 0 replies; 8+ messages in thread
From: Paolo Abeni @ 2025-06-19 13:31 UTC (permalink / raw)
  To: Rengarajan.S, aleksei.kodanev, netdev
  Cc: andrew+netdev, Bryan.Whitehead, davem, Raju.Lakkaraju, kuba,
	edumazet, UNGLinuxDriver, richardcochran

On 6/19/25 12:39 PM, Rengarajan.S@microchip.com wrote:
> On Mon, 2025-06-16 at 11:37 +0000, Alexey Kodanev wrote:
>> 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)")
>> Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
>> ---
>>
>> v2: Increase LAN743X_PTP_N_EXTTS to 8
>>
>>  drivers/net/ethernet/microchip/lan743x_ptp.h | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.h
>> b/drivers/net/ethernet/microchip/lan743x_ptp.h
>> index e8d073bfa2ca..f33dc83c5700 100644
>> --- a/drivers/net/ethernet/microchip/lan743x_ptp.h
>> +++ b/drivers/net/ethernet/microchip/lan743x_ptp.h
>> @@ -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.
> 
>>
>>  struct lan743x_adapter;
>> --
>> 2.25.1
>>
> 
> Acked-by: Rengarajan S <rengarajan.s@microchip.com>

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get()
  2025-06-16 11:37 [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get() Alexey Kodanev
                   ` (2 preceding siblings ...)
  2025-06-19 10:39 ` Rengarajan.S
@ 2025-06-19 13:50 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-06-19 13:50 UTC (permalink / raw)
  To: Alexey Kodanev
  Cc: netdev, Rengarajan.S, bryan.whitehead, UNGLinuxDriver,
	Raju.Lakkaraju, andrew+netdev, davem, edumazet, kuba, pabeni,
	richardcochran

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-06-19 13:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 11:37 [PATCH net-next v2] net: lan743x: fix potential out-of-bounds write in lan743x_ptp_io_event_clock_get() Alexey Kodanev
2025-06-16 22:22 ` Jacob Keller
2025-06-19 10:04 ` Paolo Abeni
2025-06-19 10:26   ` Paolo Abeni
2025-06-19 10:35   ` Rengarajan.S
2025-06-19 10:39 ` Rengarajan.S
2025-06-19 13:31   ` Paolo Abeni
2025-06-19 13:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).