Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tariq Toukan" <tariqt@nvidia.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH net-next 08/13] net/mlx5e: TC, track peer flows in a vhca_id xarray
Date: Thu, 24 Sep 2026 10:41:45 +0000	[thread overview]
Message-ID: <20260924104146.1E5FE1F008A3@smtp.kernel.org> (raw)
In-Reply-To: <20260923103830.1183-9-tariqt@nvidia.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net/mlx5e: NULL pointer dereference in TC flow error cleanup
- [High] net/mlx5e: UAF of dup_peer_flows due to race with unpair
--

commit 92fc8821722bceca321f4825f3199f7c0d234a70
Author: Shay Drory <shayd@nvidia.com>

net/mlx5e: TC, track peer flows in a vhca_id xarray

The commit replaces a fixed-size esw->offloads.peer_flows[] array with an
xarray keyed by vhca_id to lift the MLX5_MAX_PORTS cap. A dup_peer_flows
list_head is created when eswitches pair over devcom and freed when they
unpair.

> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> @@ -4634,8 +4635,11 @@ static int mlx5e_tc_add_fdb_peer_flow(struct flow_cls_offload *f,
>  	peer_flow->peer_orig = flow;
>  	list_add_tail(&peer_flow->peer_flows, &flow->peer_flows);
>  	flow_flag_set(flow, DUP);
> +	dup_peer_flows = xa_load(&esw->offloads.peer_flows, peer_vhca_id);
> +	if (!dup_peer_flows)
> +		return -ENODEV;

[Severity: High]
Can this early return lead to a NULL pointer dereference during error
unwinding? 

If xa_load() returns NULL, we return -ENODEV, leaving peer_flow->peer
completely uninitialized.

When the caller unwinds and calls mlx5e_tc_del_fdb_peer_flow(peer_flow),
it executes list_del(&peer_flow->peer) which will access NULL->next and
NULL->prev, causing a kernel panic.

>  	mutex_lock(&esw->offloads.peer_mutex);
> -	list_add_tail(&peer_flow->peer, &esw->offloads.peer_flows[i]);
> +	list_add_tail(&peer_flow->peer, dup_peer_flows);
>  	mutex_unlock(&esw->offloads.peer_mutex);
>  
>  out:

[ ... ]

> @@ -5530,20 +5534,14 @@ int mlx5e_tc_num_filters(struct mlx5e_priv *priv, unsigned long flags)
>  
>  void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw)
>  {
[ ... ]
> +	xa_for_each(&esw->offloads.peer_flows, index, dup_peer_flows)
>  		list_for_each_entry_safe(peer_flow, tmp_peer_flow,
> -					 &esw->offloads.peer_flows[i], peer)
> +					 dup_peer_flows, peer)
>  			mlx5e_tc_del_fdb_peer_flow(peer_flow);

[Severity: Low]
This isn't a bug introduced by this patch, but does flushing the entire xarray
here wipe flows for all active peers when only a single peer unpairs?

When a devcom unpair event happens for a single peer, iterating over the
entire esw->offloads.peer_flows xarray unconditionally drops TC flows
duplicated to all active peers, rather than just the one disconnecting.
This behavior existed prior to the patch, but the patch carries it forward
without resolving the multi-peer limitation it claimed to lift.

> -	}
>  }

[ ... ]

> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
> @@ -3383,10 +3383,15 @@ static void mlx5_esw_offloads_rep_event_unpair(struct mlx5_eswitch *esw,
>  static void mlx5_esw_offloads_unpair(struct mlx5_eswitch *esw,
>  				     struct mlx5_eswitch *peer_esw)
>  {
> +	struct list_head *dup_peer_flows;
> +
>  #if IS_ENABLED(CONFIG_MLX5_CLS_ACT)
>  	mlx5e_tc_clean_fdb_peer_flows(esw);
>  #endif
>  	mlx5_esw_offloads_rep_event_unpair(esw, peer_esw);
> +	dup_peer_flows = xa_erase(&esw->offloads.peer_flows,
> +				  MLX5_CAP_GEN(peer_esw->dev, vhca_id));
> +	kfree(dup_peer_flows);

[Severity: High]
Does this kfree() race with concurrent TC flow additions, leading to a
use-after-free?

In mlx5e_tc_add_fdb_peer_flow(), dup_peer_flows is retrieved locklessly
via xa_load(), and then usage is delayed behind acquiring peer_mutex:

mlx5e_tc_add_fdb_peer_flow() {
    dup_peer_flows = xa_load(&esw->offloads.peer_flows, peer_vhca_id);
    ...
    mutex_lock(&esw->offloads.peer_mutex);
    list_add_tail(&peer_flow->peer, dup_peer_flows);
}

Meanwhile, this unpair path does not hold peer_mutex before removing the
entry via xa_erase() and freeing it. If unpair runs concurrently with a
filter addition, can the addition thread wake up and call list_add_tail()
on the already freed dup_peer_flows list head?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260923103830.1183-1-tariqt@nvidia.com?part=8

  reply	other threads:[~2026-09-24 10:41 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 10:38 [PATCH net-next 00/13] net/mlx5: Preparations for nested E-switch Tariq Toukan
2026-09-23 10:38 ` [PATCH net-next 01/13] net/mlx5e: Assign a random MAC to any netdev with a zero MAC address Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-24 17:45   ` netdev-bot+sashiko
2026-09-23 10:38 ` [PATCH net-next 02/13] net/mlx5: E-switch, do not leave an unpaired devcom registered Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-24 17:45   ` netdev-bot+sashiko
2026-09-23 10:38 ` [PATCH net-next 03/13] net/mlx5: LAG, allocate v2p_map dynamically Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-24 17:45   ` netdev-bot+sashiko
2026-09-28 14:56     ` Shay Drori
2026-09-23 10:38 ` [PATCH net-next 04/13] net/mlx5: LAG, allocate port-indexed scratch buffers dynamically Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-24 17:45   ` netdev-bot+sashiko
2026-09-28 14:57     ` Shay Drori
2026-09-23 10:38 ` [PATCH net-next 05/13] net/mlx5: LAG, drop per-port scratch array in drop-rule setup Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-23 10:38 ` [PATCH net-next 06/13] net/mlx5: LAG, size debugfs buffers by port count Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-24 17:45   ` netdev-bot+sashiko
2026-09-23 10:38 ` [PATCH net-next 07/13] net/mlx5e: TC, anchor peer-flow reverse index on the duplicated flow Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-24 17:45   ` netdev-bot+sashiko
2026-09-23 10:38 ` [PATCH net-next 08/13] net/mlx5e: TC, track peer flows in a vhca_id xarray Tariq Toukan
2026-09-24 10:41   ` sashiko-bot [this message]
2026-09-24 17:46   ` netdev-bot+sashiko
2026-09-23 10:38 ` [PATCH net-next 09/13] net/mlx5: E-switch, derive manager vport from device capability Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-24 17:46   ` netdev-bot+sashiko
2026-09-28 15:13     ` Shay Drori
2026-09-23 10:38 ` [PATCH net-next 10/13] net/mlx5: LAG, don't print port mapping to debugfs in MPESW mode Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-23 10:38 ` [PATCH net-next 11/13] net/mlx5: LAG, drop stale esw_shared_ingress_acl gate from shared FDB Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-23 10:38 ` [PATCH net-next 12/13] net/mlx5: E-switch, correct stale VF/PF wording in esw-allowed comments Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-23 10:38 ` [PATCH net-next 13/13] net/mlx5: E-switch, disable host functions for a non PF e-switch manager Tariq Toukan
2026-09-24 10:41   ` sashiko-bot
2026-09-29  0:20 ` [PATCH net-next 00/13] net/mlx5: Preparations for nested E-switch patchwork-bot+netdevbpf

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=20260924104146.1E5FE1F008A3@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tariqt@nvidia.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