]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/mlx5: Reorder completion before putting command entry in cmd_work_handler
authorNikolay Kuratov <kniv@yandex-team.ru>
Tue, 26 May 2026 16:29:32 +0000 (19:29 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Mon, 1 Jun 2026 11:58:02 +0000 (13:58 +0200)
Assuming callback != NULL && !page_queue, cmd_work_handler takes
command entry with refcnt == 1 from mlx5_cmd_invoke.
If either semaphore timeout or index allocation error happens,
it does final cmd_ent_put(ent). To avoid access to freed memory,
notify slotted completion before cmd_ent_put.

This is theoretical issue found by Svace static analyser.

Cc: stable@vger.kernel.org
Fixes: 485d65e135712 ("net/mlx5: Add a timeout to acquire the command queue semaphore")
Fixes: 0e2909c6bec90 ("net/mlx5: Fix variable not being completed when function returns")
Signed-off-by: Nikolay Kuratov <kniv@yandex-team.ru>
Reviewed-by: Md Haris Iqbal <haris.iqbal@linux.dev>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Acked-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260526162932.501584-1-kniv@yandex-team.ru
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlx5/core/cmd.c

index c89417c1a1f96dbfdf27971d799be40a1d17405d..e2895972cc823669ac71fb352539d32e15f2e43c 100644 (file)
@@ -1002,12 +1002,13 @@ static void cmd_work_handler(struct work_struct *work)
                                ent->callback(-EBUSY, ent->context);
                                mlx5_free_cmd_msg(dev, ent->out);
                                free_msg(dev, ent->in);
+                               complete(&ent->slotted);
                                cmd_ent_put(ent);
                        } else {
                                ent->ret = -EBUSY;
                                complete(&ent->done);
+                               complete(&ent->slotted);
                        }
-                       complete(&ent->slotted);
                        return;
                }
                alloc_ret = cmd_alloc_index(cmd, ent);
@@ -1017,13 +1018,14 @@ static void cmd_work_handler(struct work_struct *work)
                                ent->callback(-EAGAIN, ent->context);
                                mlx5_free_cmd_msg(dev, ent->out);
                                free_msg(dev, ent->in);
+                               complete(&ent->slotted);
                                cmd_ent_put(ent);
                        } else {
                                ent->ret = -EAGAIN;
                                complete(&ent->done);
+                               complete(&ent->slotted);
                        }
                        up(&cmd->vars.sem);
-                       complete(&ent->slotted);
                        return;
                }
        } else {