net/mlx5: Fix slab-out-of-bounds in mlx5_query_nic_vport_mac_list
Subsystems (5)
Tariq Toukan
maintainerPATCH 1/1 net/mlx5: Fix slab-out-of-bounds in mlx5_query_nic_vport_mac_list
From: Dragos Tatulea <[email protected]>
mlx5_query_nic_vport_mac_list() sizes its firmware command buffer using the PF's log_max_current_uc/mc_list capabilities. When querying a VF vport with a larger configured max (via devlink), the firmware response can overflow this buffer:
BUG: KASAN: slab-out-of-bounds in mlx5_query_nic_vport_mac_list+0x453/0x4c0 [mlx5_core] Read of size 4 at addr ff1100013ffc8a12 by task kworker/u96:2/385 CPU: 12 UID: 0 PID: 385 Comm: kworker/u96:2 Not tainted 7.0.0-rc6+ #1 PREEMPT Hardware name: QEMU Standard PC (Q35 + ICH9, 2009) Workqueue: mlx5_esw_wq esw_vport_change_handler [mlx5_core] Call Trace: <TASK> dump_stack_lvl+0x69/0xa0 print_report+0x176/0x4e4 kasan_report+0xc8/0x100 mlx5_query_nic_vport_mac_list+0x453/0x4c0 [mlx5_core] esw_update_vport_addr_list+0x2e3/0xda0 [mlx5_core] esw_vport_change_handle_locked+0xa1f/0x1060 [mlx5_core] esw_vport_change_handler+0x6a/0x90 [mlx5_core] process_one_work+0x87f/0x15e0 worker_thread+0x62b/0x1020 kthread+0x375/0x490 ret_from_fork+0x4dc/0x810 ret_from_fork_asm+0x11/0x20 </TASK>
Fix by querying the vport's own HCA caps to size the buffer correctly. Refactor the function to allocate and return the MAC list internally, removing the caller's dependency on knowing the correct max.
--- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +--- .../net/ethernet/mellanox/mlx5/core/vport.c | 72 ++++++++++++++----- include/linux/mlx5/vport.h | 4 +- 3 files changed, 59 insertions(+), 30 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +3 -10
@@ -533,23 +533,16 @@ static void esw_update_vport_addr_list(struct mlx5_eswitch *esw, struct mlx5_vport *vport, int list_type) { bool is_uc = list_type == MLX5_NVPRT_LIST_TYPE_UC; -u8 (*mac_list)[ETH_ALEN ]; +u8 (*mac_list)[ETH_ALEN ] =NULL ;struct l2addr_node *node;struct vport_addr *addr;struct hlist_head *hash;struct hlist_node *tmp; -int size; +int size =0 ;int err;int hi;int i; - size = is_uc ?MLX5_MAX_UC_PER_VPORT (esw->dev) : -MLX5_MAX_MC_PER_VPORT (esw->dev); - - mac_list =kcalloc (size,ETH_ALEN ,GFP_KERNEL ); -if (!mac_list) -return ; - hash = is_uc ? vport->uc_list : vport->mc_list;for_each_l2hash_node (node, tmp, hash, hi) {
@@ -561,7 +554,7 @@ static void esw_update_vport_addr_list(struct mlx5_eswitch *esw, goto out; err =mlx5_query_nic_vport_mac_list (esw->dev, vport->vport, list_type, - mac_list, &size); + &mac_list, &size);if (err) goto out; esw_debug(esw->dev, "vport[%d] context update %s list size (%d)\n",
drivers/net/ethernet/mellanox/mlx5/core/vport.c +54 -18
105 lines not on this page · raw message
include/linux/mlx5/vport.h +2 -2
@@ -102,8 +102,8 @@ int mlx5_query_hca_vport_node_guid(struct mlx5_core_dev *dev,int mlx5_query_nic_vport_mac_list (struct mlx5_core_dev *dev,u16 vport,enum mlx5_list_type list_type, -u8 addr_list[][ETH_ALEN ], -int *list_size); +u8 (**mac_list)[ETH_ALEN ], +int *mac_list_size); int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev, enum mlx5_list_type list_type, u8 addr_list[][ETH_ALEN],
base-commit: c05fa14db43ebef3bd862ca9d073981c0358b3f0
Signature · 1 line
2.44.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Thu, 4 Jun 2026 16:58:49 +0300 you wrote:
From: Dragos Tatulea <[email protected]>
mlx5_query_nic_vport_mac_list()sizes its firmware command buffer using the PF's log_max_current_uc/mc_list capabilities. When querying a VF vport with a larger configured max (via devlink), the firmware response can overflow this buffer:[...]
Here is the summary with links:
- [net] net/mlx5: Fix slab-out-of-bounds in mlx5_query_nic_vport_mac_list
https://git.kernel.org/netdev/net/c/894e036a24a2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html