Netdev List
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: 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, moshe@nvidia.com,
	netdev@vger.kernel.org, pabeni@redhat.com, saeedm@nvidia.com,
	tariqt@nvidia.com, Wentao Liang <vulab@iscas.ac.cn>,
	stable@vger.kernel.org
Subject: [PATCH] net/mlx5: Fix ent use-after-free in cmd_work_handler()
Date: Thu, 17 Sep 2026 11:29:00 +0000	[thread overview]
Message-ID: <20260917112900.2148932-1-vulab@iscas.ac.cn> (raw)

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.

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 11:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 11:29 Wentao Liang [this message]
2026-09-17 14:03 ` [PATCH] net/mlx5: Fix ent use-after-free in cmd_work_handler() Moshe Shemesh

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=20260917112900.2148932-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --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=moshe@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=stable@vger.kernel.org \
    --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