All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Changyul Lee" <lcy8047@gmail.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH net] net/mlx5: SF, remove probed SF devices when arming vhca events fails
Date: Wed, 18 Nov 2026 03:11:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-220006@kernel.org> (raw)
In-Reply-To: <20261117031141.1720619-1-lcy8047@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/mlx5: race and UAF in mlx5_sf_dev_table_create() arm_err
  cleanup
--

commit a5d70bb82124aa0963c3bb188af6126f523476a3
Author: Changyul Lee <lcy8047@gmail.com>

net/mlx5: SF, remove probed SF devices when arming vhca events fails

This commit calls mlx5_sf_dev_destroy_all() on the arm_err error path in
mlx5_sf_dev_table_create() so that SF auxiliary devices probed by the
active work are removed if arming VHCA events fails.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
> index e75cbf333898d..44f6292ad59ec 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c
[ ... ]
> @@ -360,6 +371,7 @@ void mlx5_sf_dev_table_create(struct mlx5_core_dev *dev)
>  arm_err:
>  	mlx5_sf_dev_destroy_active_works(table);
>  	mlx5_vhca_event_work_queues_flush(dev);
> +	mlx5_sf_dev_destroy_all(table);
>  add_active_err:
>  	kfree(table);
>  	dev->priv.sf_dev_table = NULL;

[Severity: Medium]
Can mlx5_sf_dev_state_change_handler() race with mlx5_sf_dev_destroy_all()
and kfree(table) on the arm_err path?

If mlx5_sf_dev_vhca_arm_all() fails after arming one or more SF functions,
those functions remain armed in firmware while dev->priv.sf_dev_nb is still
registered and dev->priv.sf_dev_table still points to table.  Unlike
mlx5_sf_dev_table_destroy(), which runs after mlx5_sf_dev_notifier_cleanup()
has unregistered the notifier, arm_err runs with the notifier active.

When mlx5_sf_dev_destroy_all() removes an already-probed SF, tearing down
its HCA transitions the function from MLX5_VHCA_STATE_IN_USE back to
MLX5_VHCA_STATE_ACTIVE, which can queue a new VHCA state event after
mlx5_vhca_event_work_queues_flush() has already returned:

CPU0                                  CPU1 (vhca_events wq)
mlx5_sf_dev_table_create()
  mlx5_sf_dev_vhca_arm_all()
    /* arms SF 0, fails on SF 1 */
  mlx5_sf_dev_destroy_active_works()
  mlx5_vhca_event_work_queues_flush()
  mlx5_sf_dev_destroy_all(table)
    xa_erase(&table->devices, 0)
    mlx5_sf_dev_remove_aux()
      /* SF 0 becomes ACTIVE,
         fires VHCA event */
                                      mlx5_sf_dev_state_change_handler()
                                        table = dev->priv.sf_dev_table;
  kfree(table)
                                        xa_load(&table->devices, 0)
                                          <-- use-after-free
  dev->priv.sf_dev_table = NULL;

Even if the handler runs before kfree(table), seeing MLX5_VHCA_STATE_ACTIVE
after xa_erase() causes mlx5_sf_dev_add() to re-add the SF auxiliary device
that mlx5_sf_dev_destroy_all() just removed, and a state change to
ALLOCATED or TEARDOWN_REQUEST can call mlx5_sf_dev_del() concurrently with
mlx5_sf_dev_destroy_all().

Clearing dev->priv.sf_dev_table before mlx5_vhca_event_work_queues_flush()
(with a barrier or WRITE_ONCE/READ_ONCE pair) would ensure no handler runs
against table while mlx5_sf_dev_destroy_all() and kfree(table) execute.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117031141.1720619-1-lcy8047@gmail.com?part=1

      reply	other threads:[~2026-11-18  3:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  3:11 [PATCH net] net/mlx5: SF, remove probed SF devices when arming vhca events fails Changyul Lee
2026-11-18  3:11 ` sashiko-bot [this message]

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=sashiko-outbox-220006@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lcy8047@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.