diff mbox series

[net-next,12/12] mlxsw: Validate local port from CQE in PCI code

Message ID 0bd312ed629e85a044725080b9f33403bb51ae41.1738665783.git.petrm@nvidia.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series mlxsw: Preparations for XDP support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 4 this patch: 4
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-04--15-00 (tests: 886)

Commit Message

Petr Machata Feb. 4, 2025, 11:05 a.m. UTC
From: Amit Cohen <amcohen@nvidia.com>

Currently, there is a check in core code to validate that the received
local port does not exceed number of ports in the switch. Next patch will
have to validate it also in PCI, before accessing the pci_ports array.
There is no reason to check it twice, so move this check to PCI code.

Note that 'mlxsw_pci->max_ports' and 'mlxsw_core->max_ports' store the same
value, which is read from firmware.

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/core.c | 3 +--
 drivers/net/ethernet/mellanox/mlxsw/pci.c  | 3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
index 628530e01b19..962283bbfe18 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
@@ -2959,8 +2959,7 @@  void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
 	const struct mlxsw_rx_listener *rxl;
 	bool found = false;
 
-	if ((rx_info->trap_id >= MLXSW_TRAP_ID_MAX) ||
-	    (rx_info->local_port >= mlxsw_core->max_ports))
+	if (rx_info->trap_id >= MLXSW_TRAP_ID_MAX)
 		goto drop;
 
 	rcu_read_lock();
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index b560c21fd3ef..778493b21318 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -845,6 +845,9 @@  static void mlxsw_pci_cqe_rdq_handle(struct mlxsw_pci *mlxsw_pci,
 		rx_info.local_port = mlxsw_pci_cqe_system_port_get(cqe);
 	}
 
+	if (rx_info.local_port >= mlxsw_pci->max_ports)
+		goto out;
+
 	err = mlxsw_pci_rx_pkt_info_init(q->pci, elem_info, byte_count,
 					 &rx_pkt_info);
 	if (err)