diff options
author | Danielle Ratson <danieller@nvidia.com> | 2021-05-17 20:03:57 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-05-18 01:15:46 +0300 |
commit | 837ec05cfea08284c575e8e834777b107da5ff9d (patch) | |
tree | dd4cf1ed79684b1aa8a76f43e9dcca92a56dc08e /drivers/net/ethernet/mellanox/mlxsw/minimal.c | |
parent | ece5df874d3a80fcade92ca3b3877bd78dbb6116 (diff) | |
download | linux-837ec05cfea08284c575e8e834777b107da5ff9d.tar.xz |
mlxsw: Verify the accessed index doesn't exceed the array length
There are few cases in which an array index queried from a fw register,
is accessed without any validation that it doesn't exceed the array
length.
Add a proper length validation, so accessing memory past the end of an
array will be forbidden.
Signed-off-by: Danielle Ratson <danieller@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/mellanox/mlxsw/minimal.c')
-rw-r--r-- | drivers/net/ethernet/mellanox/mlxsw/minimal.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/net/ethernet/mellanox/mlxsw/minimal.c b/drivers/net/ethernet/mellanox/mlxsw/minimal.c index b34c44723f8b..68102726c6a7 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/minimal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/minimal.c @@ -234,6 +234,7 @@ static void mlxsw_m_port_remove(struct mlxsw_m *mlxsw_m, u8 local_port) static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u8 local_port, u8 *last_module) { + unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core); u8 module, width; int err; @@ -249,6 +250,9 @@ static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u8 local_port, if (module == *last_module) return 0; *last_module = module; + + if (WARN_ON_ONCE(module >= max_ports)) + return -EINVAL; mlxsw_m->module_to_port[module] = ++mlxsw_m->max_ports; return 0; |