diff mbox series

[net,7/8] net/mlx5e: Fix CT entry update leaks of modify header context

Message ID 20240730061638.1831002-8-tariqt@nvidia.com (mailing list archive)
State Accepted
Commit 025f2b85a5e5a46df14ecf162c3c80a957a36d0b
Delegated to: Netdev Maintainers
Headers show
Series mlx5 misc fixes 2024-07-30 | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 42 this patch: 42
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 3 blamed authors not CCed: paulb@nvidia.com ozsh@nvidia.com vladbu@nvidia.com; 4 maintainers not CCed: paulb@nvidia.com ozsh@nvidia.com vladbu@nvidia.com linux-rdma@vger.kernel.org
netdev/build_clang success Errors and warnings before: 43 this patch: 43
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 43 this patch: 43
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-31--12-00 (tests: 707)

Commit Message

Tariq Toukan July 30, 2024, 6:16 a.m. UTC
From: Chris Mi <cmi@nvidia.com>

The cited commit allocates a new modify header to replace the old
one when updating CT entry. But if failed to allocate a new one, eg.
exceed the max number firmware can support, modify header will be
an error pointer that will trigger a panic when deallocating it. And
the old modify header point is copied to old attr. When the old
attr is freed, the old modify header is lost.

Fix it by restoring the old attr to attr when failed to allocate a
new modify header context. So when the CT entry is freed, the right
modify header context will be freed. And the panic of accessing
error pointer is also fixed.

Fixes: 94ceffb48eac ("net/mlx5e: Implement CT entry update")
Signed-off-by: Chris Mi <cmi@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Wojciech Drewek July 30, 2024, 9:49 a.m. UTC | #1
On 30.07.2024 08:16, Tariq Toukan wrote:
> From: Chris Mi <cmi@nvidia.com>
> 
> The cited commit allocates a new modify header to replace the old
> one when updating CT entry. But if failed to allocate a new one, eg.
> exceed the max number firmware can support, modify header will be
> an error pointer that will trigger a panic when deallocating it. And
> the old modify header point is copied to old attr. When the old
> attr is freed, the old modify header is lost.
> 
> Fix it by restoring the old attr to attr when failed to allocate a
> new modify header context. So when the CT entry is freed, the right
> modify header context will be freed. And the panic of accessing
> error pointer is also fixed.
> 
> Fixes: 94ceffb48eac ("net/mlx5e: Implement CT entry update")
> Signed-off-by: Chris Mi <cmi@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
> ---

Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>

>  drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> index 8cf8ba2622f2..71a168746ebe 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
> @@ -932,6 +932,7 @@ mlx5_tc_ct_entry_replace_rule(struct mlx5_tc_ct_priv *ct_priv,
>  	mlx5_tc_ct_entry_destroy_mod_hdr(ct_priv, zone_rule->attr, mh);
>  	mlx5_put_label_mapping(ct_priv, attr->ct_attr.ct_labels_id);
>  err_mod_hdr:
> +	*attr = *old_attr;
>  	kfree(old_attr);
>  err_attr:
>  	kvfree(spec);
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
index 8cf8ba2622f2..71a168746ebe 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c
@@ -932,6 +932,7 @@  mlx5_tc_ct_entry_replace_rule(struct mlx5_tc_ct_priv *ct_priv,
 	mlx5_tc_ct_entry_destroy_mod_hdr(ct_priv, zone_rule->attr, mh);
 	mlx5_put_label_mapping(ct_priv, attr->ct_attr.ct_labels_id);
 err_mod_hdr:
+	*attr = *old_attr;
 	kfree(old_attr);
 err_attr:
 	kvfree(spec);