Netdev List
 help / color / mirror / Atom feed
From: Moshe Shemesh <moshe@nvidia.com>
To: Wentao Liang <vulab@iscas.ac.cn>, <agoldberger@nvidia.com>
Cc: <andrew+netdev@lunn.ch>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <leon@kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-rdma@vger.kernel.org>,
	<mbloch@nvidia.com>, <netdev@vger.kernel.org>,
	<pabeni@redhat.com>, <saeedm@nvidia.com>, <tariqt@nvidia.com>,
	<stable@vger.kernel.org>
Subject: Re: [PATCH] net/mlx5: Fix ent use-after-free in cmd_work_handler()
Date: Thu, 17 Sep 2026 17:03:51 +0300	[thread overview]
Message-ID: <c23774ed-f6f3-4f11-921b-59aa9a06e1fe@nvidia.com> (raw)
In-Reply-To: <20260917112900.2148932-1-vulab@iscas.ac.cn>



On 9/17/2026 2:29 PM, Wentao Liang wrote:
> 
> In the two command slot acquisition error paths, cmd_ent_put() can drop
> the last reference and free the command entry, and complete(&ent->slotted)
> is then called on that freed entry.  Signal the slotted completion before
> dropping the reference so that the waiter in wait_func() is woken while
> the entry is still allocated and the entry is not touched after it has
> been freed.


This is already fixed upstream by
commit 02896a7fa4cd ("net/mlx5: Reorder completion before putting 
command entry in cmd_work_handler").

Thanks, Moshe.

> 
> Fixes: 485d65e13571 ("net/mlx5: Add a timeout to acquire the command queue semaphore")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> index c89417c1a1f9..2dac131c5f86 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> @@ -998,6 +998,7 @@ static void cmd_work_handler(struct work_struct *work)
>                  if (down_timeout(&cmd->vars.sem, timeout)) {
>                          mlx5_core_warn(dev, "%s(0x%x) timed out while waiting for a slot.\n",
>                                         mlx5_command_str(ent->op), ent->op);
> +                       complete(&ent->slotted);
>                          if (ent->callback) {
>                                  ent->callback(-EBUSY, ent->context);
>                                  mlx5_free_cmd_msg(dev, ent->out);
> @@ -1007,12 +1008,12 @@ static void cmd_work_handler(struct work_struct *work)
>                                  ent->ret = -EBUSY;
>                                  complete(&ent->done);
>                          }
> -                       complete(&ent->slotted);
>                          return;
>                  }
>                  alloc_ret = cmd_alloc_index(cmd, ent);
>                  if (alloc_ret < 0) {
>                          mlx5_core_err_rl(dev, "failed to allocate command entry\n");
> +                       complete(&ent->slotted);
>                          if (ent->callback) {
>                                  ent->callback(-EAGAIN, ent->context);
>                                  mlx5_free_cmd_msg(dev, ent->out);
> @@ -1023,7 +1024,6 @@ static void cmd_work_handler(struct work_struct *work)
>                                  complete(&ent->done);
>                          }
>                          up(&cmd->vars.sem);
> -                       complete(&ent->slotted);
>                          return;
>                  }
>          } else {
> --
> 2.34.1
> 


      reply	other threads:[~2026-09-17 14:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 11:29 [PATCH] net/mlx5: Fix ent use-after-free in cmd_work_handler() Wentao Liang
2026-09-17 14:03 ` Moshe Shemesh [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=c23774ed-f6f3-4f11-921b-59aa9a06e1fe@nvidia.com \
    --to=moshe@nvidia.com \
    --cc=agoldberger@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.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=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=stable@vger.kernel.org \
    --cc=tariqt@nvidia.com \
    --cc=vulab@iscas.ac.cn \
    /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