Skip to contentSkip to conversation

net/mlx5e: Fix a use after free on error in mlx5_tc_ct_shared_counter_get()

PATCH Applied Dan Carpenter 4 participants 4 messages Sep 28, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5e: Fix a use after free on error in mlx5_tc_ct_shared_counter_get()

This code frees "shared_counter" and then dereferences on the next line to get the error code.

Fixes 1edae2335adf ("net/mlx5e: CT: Use the same counter for both directions")
---
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +3 -1
index b5f8ed30047b..cea2070af9af 100644
@@ -739,6 +739,7 @@ mlx5_tc_ct_shared_counter_get(struct mlx5_tc_ct_priv *ct_priv,
 	struct mlx5_core_dev *dev = ct_priv->dev;
 	struct mlx5_ct_entry *rev_entry;
 	__be16 tmp_port;
+	int ret;
 
 	/* get the reversed tuple */
 	tmp_port = rev_tuple.port.src;
@@ -778,8 +779,9 @@ mlx5_tc_ct_shared_counter_get(struct mlx5_tc_ct_priv *ct_priv,
 	shared_counter->counter = mlx5_fc_create(dev, true);
 	if (IS_ERR(shared_counter->counter)) {
 		ct_dbg("Failed to create counter for ct entry");
+		ret = PTR_ERR(shared_counter->counter);
 		kfree(shared_counter);
-		return ERR_PTR(PTR_ERR(shared_counter->counter));
+		return ERR_PTR(ret);
 	}
 
 	refcount_set(&shared_counter->refcount, 1);
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dan Carpenter

This code frees "shared_counter" and then dereferences on the next line to get the error code.

Fixes 1edae2335adf ("net/mlx5e: CT: Use the same counter for both directions")
---
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Thanks,

#3 lore raw
Quoted 7 lines · David Miller

From: Dan Carpenter <[email protected]>
Date: Mon, 28 Sep 2020 12:05:56 +0300

Quoted 1 line

This code frees "shared_counter" and then dereferences on the next

line

Quoted 2 lines

to get the error code.

Quoted 7 lines
Quoted 1 line
Fixes 1edae2335adf ("net/mlx5e: CT: Use the same counter for both

directions")

Quoted 1 line

Saeed, I assume you will pick this up.

Thank you.

Applied to net-next-mlx5.

Thanks