Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Tariq Toukan <tariqt@nvidia.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>
Cc: Dragos Tatulea <dtatulea@nvidia.com>,
	Gal Pressman <gal@nvidia.com>,
	"Leon Romanovsky" <leon@kernel.org>, <linux-rdma@vger.kernel.org>,
	Maor Gottlieb <maorg@mellanox.com>,
	Mark Bloch <markb@mellanox.com>, Mark Bloch <mbloch@nvidia.com>,
	Saeed Mahameed <saeedm@mellanox.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>
Subject: [PATCH net] net/mlx5: Fix RoCE steering use-after-free on eswitch mode change
Date: Wed, 2 Dec 2026 14:26:56 +0200	[thread overview]
Message-ID: <20261202122656.3434304-1-tariqt@nvidia.com> (raw)

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


             reply	other threads:[~2026-12-02 12:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:26 Tariq Toukan [this message]
2026-12-02 12:30 ` [PATCH net] net/mlx5: Fix RoCE steering use-after-free on eswitch mode change sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202122656.3434304-1-tariqt@nvidia.com \
    --to=tariqt@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --cc=edumazet@kernel.org \
    --cc=gal@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=maorg@mellanox.com \
    --cc=markb@mellanox.com \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@mellanox.com \
    --cc=saeedm@nvidia.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox