mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shay Drory <shayd@nvidia.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <tariqt@nvidia.com>, <andrew+netdev@lunn.ch>,
	<davem@davemloft.net>, <edumazet@kernel.org>, <kuba@kernel.org>,
	<netdev@vger.kernel.org>, <pabeni@redhat.com>,
	<cjubran@nvidia.com>, <cratiu@nvidia.com>, <gal@nvidia.com>,
	<leon@kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-rdma@vger.kernel.org>, <mbloch@nvidia.com>,
	<moshe@nvidia.com>, <ohartoov@nvidia.com>, <phaddad@nvidia.com>,
	<saeedm@nvidia.com>, <udar@nvidia.com>
Subject: Re: [PATCH net-next V2 08/10] net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation
Date: Thu, 19 Nov 2026 10:20:18 +0200	[thread overview]
Message-ID: <20261119082018.1587771-1-shayd@nvidia.com> (raw)
In-Reply-To: <179499791769.3136.2377396411292995534@kernel.org>

On Wed, 18 Nov 2026 10:31:57 +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 1
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] Possible heap out-of-bounds read/write in
>   mlx5_mpesw_metadata_cleanup()…
> - [Low] The commit message ends with "Thus, removes the hard dependency
>   on MLX5_MAX_PORTS", which overstates what the patch does.
>
> --
>
> net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation
>
> This converts lag_mpesw.pf_metadata and the mdev array in
> mlx5_lag_query_cong_counters() from fixed MLX5_MAX_PORTS sized arrays to
> dynamically allocated buffers. pf_metadata is sized by ldev->max_fns when
> MPESW is enabled. The cong counters array is sized by ldev->ports.
>
> > Thus, removes the hard dependency on MLX5_MAX_PORTS.
>
> [Severity: Low]
> Is this statement accurate? This patch converts only two arrays.
>
> This patch leaves the devs[MLX5_MAX_PORTS] scratch array in
> mlx5_lag_rescan_devices_locked_filter() in place. The later series patch
> "drop MLX5_MAX_PORTS scratch array from device rescan" removes it.
>
> Some arrays tied to the LAG member index space are still there at the end
> of the series. That index space is no longer capped at MLX5_MAX_PORTS,
> because "decouple iteration end-of-walk from MLX5_MAX_PORTS" moved
> xa_alloc() to XA_LIMIT(0, U8_MAX - 1):
>
> drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h:struct lag_tracker {
>     ...
>     struct netdev_lag_lower_state_info  netdev_state[MLX5_MAX_PORTS];
>     ...
> }
>
> drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.h:struct mlx5_lag_port_sel {
>     ...
>     struct mlx5_flow_handle *rules[MLX5_MAX_PORTS * MLX5_LAG_MAX_HASH_BUCKETS];
>     ...
> }
>
> Could the commit message say that these remain? Or should they be
> converted or bounded as well?

The sentence refers to the two arrays this patch converts.
tracker.netdev_state[] and the port_sel rules[] keep their
MLX5_MAX_PORTS size on purpose.

> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
> > index 49602f8306155..8a867a04916a8 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
> > @@ -15,6 +15,9 @@ static void mlx5_mpesw_metadata_cleanup(struct mlx5_lag *ldev)
> >  	u32 pf_metadata;
> >  	int i;
> >
> > +	if (!ldev->lag_mpesw.pf_metadata)
> > +		return;
> > +
> >  	mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
> >  		dev = mlx5_lag_fn(ldev, i)->dev;
> >  		esw = dev->priv.eswitch;
> > @@ -27,6 +30,9 @@ static void mlx5_mpesw_metadata_cleanup(struct mlx5_lag *ldev)
> >  		mlx5_esw_match_metadata_free(esw, pf_metadata);
> >  		ldev->lag_mpesw.pf_metadata[i] = 0;
> >  	}
> > +
> > +	kfree(ldev->lag_mpesw.pf_metadata);
> > +	ldev->lag_mpesw.pf_metadata = NULL;
> >  }
> >
> >  static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
> > @@ -36,6 +42,12 @@ static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
> >  	u32 pf_metadata;
> >  	int i, err;
> >
> > +	ldev->lag_mpesw.pf_metadata =
> > +		kcalloc(ldev->max_fns, sizeof(*ldev->lag_mpesw.pf_metadata),
> > +			GFP_KERNEL);
> > +	if (!ldev->lag_mpesw.pf_metadata)
> > +		return -ENOMEM;
> > +
>
> [Severity: High]
> Can ldev->max_fns grow after this allocation while MPESW is still active?
>

It shouldn't. This is a pre-existing bug: MPESW shouldn't be enabled
while an SD secondary hasn't probed yet. A separate fix that rejects
MPESW in this case is in the pipe.

> The allocated length is not stored anywhere. Yet
> mlx5_mpesw_metadata_cleanup() walks the members with mlx5_lag_for_each(),
> which checks against the current max_fns:
>
> #define mlx5_lag_for_each(i, start_index, ldev, filter) \
> 	for (int tmp = start_index; \
> 	     tmp = mlx5_get_next_lag_func(ldev, tmp, filter), \
> 	     i = tmp, tmp < (ldev)->max_fns; tmp++)
>
> mlx5_ldev_add_mdev() grows max_fns without looking at the LAG mode:
>
> drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_ldev_add_mdev() {
>     ...
> 	/* max_fns is the iteration ceiling; grow it, never shrink. */
> 	if (idx >= ldev->max_fns)
> 		ldev->max_fns = idx + 1;
>     ...
> }
>
> sd_lag_init() calls it for each SD secondary, also without checking
> ldev->mode:
>
> drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c:sd_lag_init() {
>     ...
> 	mlx5_sd_for_each_secondary(i, primary, pos) {
> 		err = mlx5_ldev_add_mdev(ldev, pos, sd->group_id);
>     ...
> }
>
> Here is one possible sequence on an SD card:
>
>   devlink esw_multiport=true
>     mlx5_lag_enable_mpesw()
>       mlx5_mpesw_metadata_set()
>         kcalloc(max_fns = 2)
>
>   secondary PF probes later
>     mlx5e_probe() -> mlx5_sd_init() -> sd_lag_init()
>       mlx5_ldev_add_mdev()     /* idx 2, max_fns = 3 */
>
>   devlink esw_multiport=false, or unload
>     mlx5_lag_disable_mpesw()
>       mlx5_mpesw_metadata_cleanup()
>         reads and writes pf_metadata[2]
>
> SD secondaries have fn->dev set, so the MLX5_LAG_FILTER_ALL walk visits
> them. Three things then go wrong for any index past the allocated count:
>
> - cleanup reads pf_metadata[i] past the end of the slab object.
> - if that stale value is non-zero, it calls
>   mlx5_esw_acl_ingress_vport_metadata_update() on that eswitch, and
>   mlx5_esw_match_metadata_free() with an ida id that was never allocated.
> - it writes 0 to pf_metadata[i] past the end of the buffer.
>
> With the old embedded u32 pf_metadata[MLX5_MAX_PORTS], a member added
> later at an index below MLX5_MAX_PORTS read a zero slot and was skipped.
>
> The last patch in the series ("do not add a device to an already-active
> virt LAG") says SD secondaries join before MPESW can be enabled. Is that
> enforced anywhere?
>
> - mlx5_devlink_esw_multiport_set()->mlx5_lag_mpesw_enable() does not
>   check SD readiness.
> - mlx5_phys_mpesw_validate()->mlx5_lag_check_prereq() only checks
>   mlx5_lag_num_devs(ldev) == ldev->ports. That counts port members, not
>   SD secondaries.
>
> Would it be safer to record the allocated length and bound the cleanup
> loop by it? Another option is to refuse max_fns growth and SD joins
> while MPESW is active.
> [ ... ]
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com

  reply	other threads:[~2026-11-19  8:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 01/10] net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping Tariq Toukan
2026-11-18 10:31   ` netdev-bot+sashiko
2026-11-19  7:40     ` Shay Drory
2026-11-16 10:30 ` [PATCH net-next V2 02/10] net/mlx5: LAG, select the MPESW master from the live member snapshot Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 03/10] net/mlx5: LAG, skip phys LAG prerequisites for a virt LAG Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 04/10] net/mlx5: LAG, treat virt LAG as a software managed LAG Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 05/10] net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS Tariq Toukan
2026-11-18 10:31   ` netdev-bot+sashiko
2026-11-19  8:10     ` Shay Drory
2026-11-16 10:30 ` [PATCH net-next V2 06/10] net/mlx5: LAG, rename PF naming to fn Tariq Toukan
2026-11-18 10:31   ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 07/10] net/mlx5: LAG, resolve affinity indices only in queue-affinity mode Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 08/10] net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation Tariq Toukan
2026-11-18 10:31   ` netdev-bot+sashiko
2026-11-19  8:20     ` Shay Drory [this message]
2026-11-16 10:30 ` [PATCH net-next V2 09/10] net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan Tariq Toukan
2026-11-18 10:31   ` netdev-bot+sashiko
2026-11-19  8:40     ` Shay Drory
2026-11-16 10:30 ` [PATCH net-next V2 10/10] net/mlx5: LAG, do not add a device to an already-active virt LAG Tariq Toukan
2026-11-18 10:32   ` netdev-bot+sashiko

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=20261119082018.1587771-1-shayd@nvidia.com \
    --to=shayd@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=cjubran@nvidia.com \
    --cc=cratiu@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gal@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=moshe@nvidia.com \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ohartoov@nvidia.com \
    --cc=pabeni@redhat.com \
    --cc=phaddad@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=udar@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

all inboxes | Powered by JetHome®