Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH net] net/mlx5: Fix RoCE steering use-after-free on eswitch mode change
@ 2026-12-02 12:26 Tariq Toukan
  2026-12-02 12:30 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Tariq Toukan @ 2026-12-02 12:26 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn
  Cc: Dragos Tatulea, Gal Pressman, Leon Romanovsky, linux-rdma,
	Maor Gottlieb, Mark Bloch, Mark Bloch, Saeed Mahameed,
	Saeed Mahameed, Tariq Toukan

From: Dragos Tatulea <dtatulea@nvidia.com>

mlx5_rdma_disable_roce() uses roce->ft to tell whether RoCE steering was
set up, but mlx5_rdma_disable_roce_steering() frees the table, group and
rule without clearing the pointers. The pointers in dev->priv.roce
survive a devlink reload.

If the next mlx5_rdma_enable_roce() returns early because the roce cap
is now off, the next mlx5_rdma_disable_roce() passes the !roce->ft check
and frees the stale objects a second time.

Caught on a CX-7 with KASAN when running the following sequence:

  devlink dev eswitch set pci/$PF mode switchdev
  devlink dev eswitch set pci/$PF mode legacy
  devlink dev param set pci/$PF name enable_roce value false cmode driverinit
  devlink dev reload pci/$PF
  devlink dev eswitch set pci/$PF mode switchdev
  devlink dev eswitch set pci/$PF mode legacy

The first legacy transition frees the RoCE steering objects. After the
reload, the roce cap is 0, so the switchdev transition creates nothing.
The second legacy transition then hits:

  BUG: KASAN: slab-use-after-free in mlx5_del_flow_rules+0x634/0x7c0 [mlx5_core]
  Read of size 4 at addr ff11000109bd4200 by task devlink/7695
  Call Trace:
   mlx5_del_flow_rules+0x634/0x7c0 [mlx5_core]
   mlx5_rdma_disable_roce+0x68/0x110 [mlx5_core]
   esw_offloads_disable+0xe4/0x180 [mlx5_core]
   mlx5_eswitch_disable_locked.cold+0x104/0x1dd [mlx5_core]
   mlx5_devlink_eswitch_mode_set+0x418/0xfb0 [mlx5_core]
   devlink_nl_eswitch_set_doit+0x1e5/0x4f0
  ...
  Freed by task 7581:
   kfree+0x16c/0x5c0
   mlx5_rdma_disable_roce+0x68/0x110 [mlx5_core]
   esw_offloads_disable+0xe4/0x180 [mlx5_core]
   mlx5_eswitch_disable_locked.cold+0x104/0x1dd [mlx5_core]
   mlx5_devlink_eswitch_mode_set+0x418/0xfb0 [mlx5_core]

The fix is simple: clear the pointers after freeing the objects so
that mlx5_rdma_disable_roce() can return early.

Fixes: 80f09dfc237f ("net/mlx5: Eswitch, enable RoCE loopback traffic")
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/rdma.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/rdma.c b/drivers/net/ethernet/mellanox/mlx5/core/rdma.c
index e372484960ca..a5f07ac28eb0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/rdma.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/rdma.c
@@ -15,8 +15,11 @@ static void mlx5_rdma_disable_roce_steering(struct mlx5_core_dev *dev)
 	struct mlx5_core_roce *roce = &dev->priv.roce;
 
 	mlx5_del_flow_rules(roce->allow_rule);
+	roce->allow_rule = NULL;
 	mlx5_destroy_flow_group(roce->fg);
+	roce->fg = NULL;
 	mlx5_destroy_flow_table(roce->ft);
+	roce->ft = NULL;
 }
 
 static int mlx5_rdma_enable_roce_steering(struct mlx5_core_dev *dev)
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02 12:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:26 [PATCH net] net/mlx5: Fix RoCE steering use-after-free on eswitch mode change Tariq Toukan
2026-12-02 12:30 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox