[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ae5090d780d6214311f030818f47b48a9b04fe4a.camel@microchip.com>
Date: Fri, 23 May 2025 17:21:13 +0000
From: <Rengarajan.S@...rochip.com>
To: <aleksei.kodanev@...l-sw.com>, <netdev@...r.kernel.org>
CC: <andrew+netdev@...n.ch>, <Bryan.Whitehead@...rochip.com>,
<davem@...emloft.net>, <Raju.Lakkaraju@...rochip.com>, <pabeni@...hat.com>,
<kuba@...nel.org>, <edumazet@...gle.com>, <UNGLinuxDriver@...rochip.com>,
<richardcochran@...il.com>
Subject: Re: [PATCH net-next] net: lan743x: fix 'channel' index check before
writing ptp->extts[]
Hi Alexey,
On Thu, 2025-05-22 at 14:13 +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 at first 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;
> ...
> }
>
As per the PTP_INT_STS definition, there are 8 sets of capture
registers that can be configured as GPIO inputs. However, using
LAN743X_PTP_N_EXTTS (4) restricts processing to only 4 GPIOs. Would it
be more appropriate to update LAN743X_PTP_N_EXTTS to 8? This would
ensure that extts = &ptp->extts[channel]; remains valid for all 8
potential channel indices.
> To avoid a potential out-of-bounds write, let's use the maximum
> value actually defined for the timestamp array to ensure valid
> access to ptp->extts[channel] within its actual bounds.
>
> 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@...l-sw.com>
> ---
>
> Note that PCI11X1X_PTP_IO_MAX_CHANNELS will be unused after this
> patch.
> Could it perhaps be used to define LAN743X_PTP_N_EXTTS to support
> size 8?
>
> drivers/net/ethernet/microchip/lan743x_ptp.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c
> b/drivers/net/ethernet/microchip/lan743x_ptp.c
> index 0be44dcb3393..1ef7978e768b 100644
> --- a/drivers/net/ethernet/microchip/lan743x_ptp.c
> +++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
> @@ -1121,7 +1121,7 @@ static long lan743x_ptpci_do_aux_work(struct
> ptp_clock_info *ptpci)
> PTP_INT_IO_FE
> _MASK_) >>
> PTP_INT_IO_FE
> _SHIFT_);
> if (channel >= 0 &&
> - channel <
> PCI11X1X_PTP_IO_MAX_CHANNELS) {
> + channel < LAN743X_PTP_N_EXTTS) {
> lan743x_ptp_io_event_clock_ge
> t(adapter,
>
> true,
>
> channel,
> @@ -1154,7 +1154,7 @@ static long lan743x_ptpci_do_aux_work(struct
> ptp_clock_info *ptpci)
> PTP_INT_IO_RE_
> MASK_) >>
> PTP_INT_IO_RE_
> SHIFT_);
> if (channel >= 0 &&
> - channel <
> PCI11X1X_PTP_IO_MAX_CHANNELS) {
> + channel < LAN743X_PTP_N_EXTTS) {
> lan743x_ptp_io_event_clock_ge
> t(adapter,
>
> false,
>
> channel,
> --
> 2.25.1
>
Powered by blists - more mailing lists