From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73A3C4534B3; Tue, 16 Jun 2026 16:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781625941; cv=none; b=YCmBjEj/Bu1yNlfSsN1WLcOjqTYF3IaOS91mfkTi3fqjXghzlhXdnrtIhywIz2vi3H4pAprZ+n4NZfEgzpiuVnrfCmPpiefCvTlO54gUGZNI61DMWSgQB0K28x1yb5dv9LjWXesW5pDCdSSJ0g+jSOxkPH6RQBeHNNcZllf4Eak= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781625941; c=relaxed/simple; bh=D5pMtaTJ3RVodamPcDYLxkXDyAz5RMO9YEEdjatGTuE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h4/Ex+QTQBrVFyRA0tXxRNsT76rQbjsmYIBh5Bqjw/mcEaKGz/DaITw1njWqfCLW57snavl2fTeHPpIRv455KwlPWYTJRsEOppq08ECuGbn+fi1b3rA711dud0KlOsvzVI82xdBj8SYnhrNKSshFLcjfPpBtWGL5qDKhnwl2ctw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=r6b1ZIna; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="r6b1ZIna" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 713DD1F000E9; Tue, 16 Jun 2026 16:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781625940; bh=odl4DoxuNFXX/cAH8BnWRYTdHdw4VNCQufxlPA2IEvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=r6b1ZInaN+ZM39ieBZdueli9NGg2hFFZJkLO9tluMLuNYglVo+bDRnlsTvVL0QN1o 6TFHDbaUs2al2z5kRJrWUAs9RPX9Ah+t6jA/IOz/GDW/7dylW+nIgLiNdq5Qe1kRdS lu4njW/SycyBCes3iW5itKdvioXNUR21wRPQtnk8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nikolay Kuratov , Md Haris Iqbal , Moshe Shemesh , Tariq Toukan , Paolo Abeni Subject: [PATCH 6.18 236/325] net/mlx5: Reorder completion before putting command entry in cmd_work_handler Date: Tue, 16 Jun 2026 20:30:32 +0530 Message-ID: <20260616145110.187894537@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145057.827196531@linuxfoundation.org> References: <20260616145057.827196531@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nikolay Kuratov commit 02896a7fa4cd3ec61d60ba30136841e4f04bdeac upstream. 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 Reviewed-by: Md Haris Iqbal Reviewed-by: Moshe Shemesh Acked-by: Tariq Toukan Link: https://patch.msgid.link/20260526162932.501584-1-kniv@yandex-team.ru Signed-off-by: Paolo Abeni Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -1000,12 +1000,13 @@ static void cmd_work_handler(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); @@ -1015,13 +1016,14 @@ static void cmd_work_handler(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 {