From: Jianbo Liu mlx5e_ipsec_netevent_event() runs in atomic context on the global netevent chain and snapshots the neighbour MAC into the per-SA work data, which mlx5e_ipsec_handle_netdev_event() then reads from a workqueue. The two are unsynchronized and can tear the address. Protect the shared address with a dedicated spinlock in struct mlx5e_ipsec_netevent_data. x->lock can't be taken here, it may deadlock with the ASO event path. Discovered by Sashiko. Not reproduced, the window is a few instructions wide. Tested on ConnectX-7 (fw 28.48.1000) under KASAN and lockdep with 10k neighbour updates during traffic, no splat. Fixes: 4c24272b4e2b ("net/mlx5e: Listen to ARP events to update IPsec L2 headers in tunnel mode") Signed-off-by: Jianbo Liu Reviewed-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- .../ethernet/mellanox/mlx5/core/en_accel/ipsec.c | 14 ++++++++++++-- .../ethernet/mellanox/mlx5/core/en_accel/ipsec.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c index cc75fcb0aa15..60f7dc3df355 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c @@ -701,15 +701,20 @@ static void mlx5e_ipsec_handle_netdev_event(struct work_struct *_work) struct mlx5e_ipsec_sa_entry *sa_entry = work->sa_entry; struct mlx5e_ipsec_netevent_data *data = work->data; struct mlx5_accel_esp_xfrm_attrs *attrs; + u8 addr[ETH_ALEN] __aligned(2); attrs = &sa_entry->attrs; + spin_lock_bh(&data->lock); + ether_addr_copy(addr, data->addr); + spin_unlock_bh(&data->lock); + switch (attrs->dir) { case XFRM_DEV_OFFLOAD_IN: - ether_addr_copy(attrs->smac, data->addr); + ether_addr_copy(attrs->smac, addr); break; case XFRM_DEV_OFFLOAD_OUT: - ether_addr_copy(attrs->dmac, data->addr); + ether_addr_copy(attrs->dmac, addr); break; default: WARN_ON_ONCE(true); @@ -720,6 +725,7 @@ static void mlx5e_ipsec_handle_netdev_event(struct work_struct *_work) static int mlx5_ipsec_create_work(struct mlx5e_ipsec_sa_entry *sa_entry) { + struct mlx5e_ipsec_netevent_data *ndata; struct xfrm_state *x = sa_entry->x; struct mlx5e_ipsec_work *work; void *data = NULL; @@ -754,6 +760,8 @@ static int mlx5_ipsec_create_work(struct mlx5e_ipsec_sa_entry *sa_entry) if (!data) goto free_work; + ndata = data; + spin_lock_init(&ndata->lock); INIT_WORK(&work->work, mlx5e_ipsec_handle_netdev_event); break; default: @@ -1023,7 +1031,9 @@ static int mlx5e_ipsec_netevent_event(struct notifier_block *nb, data = sa_entry->work->data; + spin_lock_bh(&data->lock); neigh_ha_snapshot(data->addr, n, sa_entry->dev); + spin_unlock_bh(&data->lock); queue_work(ipsec->wq, &sa_entry->work->work); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h index d60c72df0bf1..e70189f81ffb 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h @@ -172,6 +172,8 @@ struct mlx5e_ipsec_work { }; struct mlx5e_ipsec_netevent_data { + /* Protects addr shared by the notifier and workqueue. */ + spinlock_t lock; u8 addr[ETH_ALEN]; }; -- 2.44.0