From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 35C6B221727; Mon, 23 Jun 2025 21:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713407; cv=none; b=AapKSbUQULa6GZHbW8zDgk/beqwzOXrlyOCehG5z3lVzjyDBhBhT1/4w21+KhwTD8rx1PAnJsGXu3R3tpX6AUH9qH1QBCEopaIAtyMkOSUFm3UPkbHljtqsSZ2QYZbXc3AfdJBaD80j+d4nweREsfwZRXktZqGmwQIrKcnF5XnI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713407; c=relaxed/simple; bh=L7DE3K+fONCQtOc2ZZigid7OCm+2GNTXimjGUSeB5TU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ojUiyPD35iTiS1odR5t4m3jfU7hdfEG0GszTgmd6vM1DA02o4udsT+LpRSU4VZsPzaCNU23rRIyKLDnTkKWcGDGti1berN11UYsKi7qLQLe1DVWGOYvhxC7D/SVWrL4tEvCs3xrOkmSnxK8unV1tUX6AcrNYehSw7IQtRwtDDrk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CkSXzOot; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CkSXzOot" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C054BC4CEF0; Mon, 23 Jun 2025 21:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750713407; bh=L7DE3K+fONCQtOc2ZZigid7OCm+2GNTXimjGUSeB5TU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CkSXzOot7NuSx56jJatwFTUHL1IDhUvOzqDw0Y07JY8XpdRkzZP8p70mNLzH8qWkd JqKppBUDhHyVIj0SNKJSSr2WyAryuzVRKZl78PZ9wxvGmtoN5wdnmvI6711XE/EKZc D8ERyTyiaNDZNoU/DQLaKDiVDfcxmxWFuyDUVIhU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wentao Liang , Tariq Toukan , Paolo Abeni Subject: [PATCH 5.10 164/355] net/mlx5_core: Add error handling inmlx5_query_nic_vport_qkey_viol_cntr() Date: Mon, 23 Jun 2025 15:06:05 +0200 Message-ID: <20250623130631.631778245@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130626.716971725@linuxfoundation.org> References: <20250623130626.716971725@linuxfoundation.org> User-Agent: quilt/0.68 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wentao Liang commit f0b50730bdd8f2734e548de541e845c0d40dceb6 upstream. The function mlx5_query_nic_vport_qkey_viol_cntr() calls the function mlx5_query_nic_vport_context() but does not check its return value. This could lead to undefined behavior if the query fails. A proper implementation can be found in mlx5_nic_vport_query_local_lb(). Add error handling for mlx5_query_nic_vport_context(). If it fails, free the out buffer via kvfree() and return error code. Fixes: 9efa75254593 ("net/mlx5_core: Introduce access functions to query vport RoCE fields") Cc: stable@vger.kernel.org # v4.5 Signed-off-by: Wentao Liang Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20250521133620.912-1-vulab@iscas.ac.cn Signed-off-by: Paolo Abeni Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/vport.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/vport.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/vport.c @@ -494,19 +494,22 @@ int mlx5_query_nic_vport_qkey_viol_cntr( { u32 *out; int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out); + int err; out = kvzalloc(outlen, GFP_KERNEL); if (!out) return -ENOMEM; - mlx5_query_nic_vport_context(mdev, 0, out); + err = mlx5_query_nic_vport_context(mdev, 0, out); + if (err) + goto out; *qkey_viol_cntr = MLX5_GET(query_nic_vport_context_out, out, nic_vport_context.qkey_violation_counter); - +out: kvfree(out); - return 0; + return err; } EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_qkey_viol_cntr);