netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeed@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Eric Dumazet <edumazet@google.com>
Cc: Saeed Mahameed <saeedm@nvidia.com>,
	netdev@vger.kernel.org, Tariq Toukan <tariqt@nvidia.com>,
	Zhipeng Lu <alexious@zju.edu.cn>, Simon Horman <horms@kernel.org>
Subject: [net 13/14] net/mlx5e: fix a double-free in arfs_create_groups
Date: Wed, 24 Jan 2024 00:18:54 -0800	[thread overview]
Message-ID: <20240124081855.115410-14-saeed@kernel.org> (raw)
In-Reply-To: <20240124081855.115410-1-saeed@kernel.org>

From: Zhipeng Lu <alexious@zju.edu.cn>

When `in` allocated by kvzalloc fails, arfs_create_groups will free
ft->g and return an error. However, arfs_create_table, the only caller of
arfs_create_groups, will hold this error and call to
mlx5e_destroy_flow_table, in which the ft->g will be freed again.

Fixes: 1cabe6b0965e ("net/mlx5e: Create aRFS flow tables")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_arfs.c | 26 +++++++++++--------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c
index bb7f86c993e5..e66f486faafe 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c
@@ -254,11 +254,13 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft,
 
 	ft->g = kcalloc(MLX5E_ARFS_NUM_GROUPS,
 			sizeof(*ft->g), GFP_KERNEL);
-	in = kvzalloc(inlen, GFP_KERNEL);
-	if  (!in || !ft->g) {
-		kfree(ft->g);
-		kvfree(in);
+	if (!ft->g)
 		return -ENOMEM;
+
+	in = kvzalloc(inlen, GFP_KERNEL);
+	if (!in) {
+		err = -ENOMEM;
+		goto err_free_g;
 	}
 
 	mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
@@ -278,7 +280,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft,
 		break;
 	default:
 		err = -EINVAL;
-		goto out;
+		goto err_free_in;
 	}
 
 	switch (type) {
@@ -300,7 +302,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft,
 		break;
 	default:
 		err = -EINVAL;
-		goto out;
+		goto err_free_in;
 	}
 
 	MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
@@ -309,7 +311,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft,
 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
 	if (IS_ERR(ft->g[ft->num_groups]))
-		goto err;
+		goto err_clean_group;
 	ft->num_groups++;
 
 	memset(in, 0, inlen);
@@ -318,18 +320,20 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft,
 	MLX5_SET_CFG(in, end_flow_index, ix - 1);
 	ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
 	if (IS_ERR(ft->g[ft->num_groups]))
-		goto err;
+		goto err_clean_group;
 	ft->num_groups++;
 
 	kvfree(in);
 	return 0;
 
-err:
+err_clean_group:
 	err = PTR_ERR(ft->g[ft->num_groups]);
 	ft->g[ft->num_groups] = NULL;
-out:
+err_free_in:
 	kvfree(in);
-
+err_free_g:
+	kfree(ft->g);
+	ft->g = NULL;
 	return err;
 }
 
-- 
2.43.0


  parent reply	other threads:[~2024-01-24  8:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24  8:18 [pull request][net 00/14] mlx5 fixes 2024-01-24 Saeed Mahameed
2024-01-24  8:18 ` [net 01/14] net/mlx5e: Use the correct lag ports number when creating TISes Saeed Mahameed
2024-01-25 11:00   ` patchwork-bot+netdevbpf
2024-01-24  8:18 ` [net 02/14] net/mlx5: Fix query of sd_group field Saeed Mahameed
2024-01-24  8:18 ` [net 03/14] net/mlx5e: Fix operation precedence bug in port timestamping napi_poll context Saeed Mahameed
2024-01-24  8:18 ` [net 04/14] net/mlx5e: Fix inconsistent hairpin RQT sizes Saeed Mahameed
2024-01-24  8:18 ` [net 05/14] net/mlx5e: Fix peer flow lists handling Saeed Mahameed
2024-01-24  8:18 ` [net 06/14] net/mlx5: Fix a WARN upon a callback command failure Saeed Mahameed
2024-01-24  8:18 ` [net 07/14] net/mlx5: Bridge, fix multicast packets sent to uplink Saeed Mahameed
2024-01-24  8:18 ` [net 08/14] net/mlx5: DR, Use the right GVMI number for drop action Saeed Mahameed
2024-01-24  8:18 ` [net 09/14] net/mlx5: DR, Can't go to uplink vport on RX rule Saeed Mahameed
2024-01-24  8:18 ` [net 10/14] net/mlx5: Use mlx5 device constant for selecting CQ period mode for ASO Saeed Mahameed
2024-01-24  8:18 ` [net 11/14] net/mlx5e: Allow software parsing when IPsec crypto is enabled Saeed Mahameed
2024-01-24  8:18 ` [net 12/14] net/mlx5e: Ignore IPsec replay window values on sender side Saeed Mahameed
2024-01-24  8:18 ` Saeed Mahameed [this message]
2024-01-24  8:18 ` [net 14/14] net/mlx5e: fix a potential double-free in fs_any_create_groups Saeed Mahameed

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=20240124081855.115410-14-saeed@kernel.org \
    --to=saeed@kernel.org \
    --cc=alexious@zju.edu.cn \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --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;
as well as URLs for NNTP newsgroup(s).