lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250522141357.295240-1-aleksei.kodanev@bell-sw.com>
Date: Thu, 22 May 2025 14:13:57 +0000
From: Alexey Kodanev <aleksei.kodanev@...l-sw.com>
To: netdev@...r.kernel.org
Cc: Bryan Whitehead <bryan.whitehead@...rochip.com>,
	UNGLinuxDriver@...rochip.com,
	Raju Lakkaraju <Raju.Lakkaraju@...rochip.com>,
	Andrew Lunn <andrew+netdev@...n.ch>,
	"David S . Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	Richard Cochran <richardcochran@...il.com>,
	Alexey Kodanev <aleksei.kodanev@...l-sw.com>
Subject: [PATCH net-next] net: lan743x: fix 'channel' index check before writing ptp->extts[]

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;
        ...
    }

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_get(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_get(adapter,
 								       false,
 								       channel,
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ