diff mbox series

[net] net/mlx5: Fix tainted pointer delete is case of flow rules creation fail

Message ID 20240604100552.25201-1-amishin@t-argos.ru (mailing list archive)
State Accepted
Commit 229bedbf62b13af5aba6525ad10b62ad38d9ccb5
Delegated to: Netdev Maintainers
Headers show
Series [net] net/mlx5: Fix tainted pointer delete is case of flow rules creation fail | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
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: 900 this patch: 900
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 13 of 13 maintainers
netdev/build_clang success Errors and warnings before: 904 this patch: 904
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: 904 this patch: 904
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 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-06-04--18-00 (tests: 1045)

Commit Message

Aleksandr Mishin June 4, 2024, 10:05 a.m. UTC
In case of flow rule creation fail in mlx5_lag_create_port_sel_table(),
instead of previously created rules, the tainted pointer is deleted
deveral times.
Fix this bug by using correct flow rules pointers.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 352899f384d4 ("net/mlx5: Lag, use buckets in hash mode")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
---
 drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Jacob Keller June 4, 2024, 9:58 p.m. UTC | #1
On 6/4/2024 3:05 AM, Aleksandr Mishin wrote:
> In case of flow rule creation fail in mlx5_lag_create_port_sel_table(),
> instead of previously created rules, the tainted pointer is deleted
> deveral times.
> Fix this bug by using correct flow rules pointers.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 352899f384d4 ("net/mlx5: Lag, use buckets in hash mode")
> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
> index c16b462ddedf..ab2717012b79 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
> @@ -88,9 +88,13 @@ static int mlx5_lag_create_port_sel_table(struct mlx5_lag *ldev,
>  								      &dest, 1);
>  			if (IS_ERR(lag_definer->rules[idx])) {
>  				err = PTR_ERR(lag_definer->rules[idx]);
> -				while (i--)
> -					while (j--)
> +				do {
> +					while (j--) {
> +						idx = i * ldev->buckets + j;
>  						mlx5_del_flow_rules(lag_definer->rules[idx]);
> +					}
> +					j = ldev->buckets;
> +				} while (i--);

So, before the code was:

while (i--)
    while (j--)
        mlx5_del_flow_rules(lag_definer->rules[idx]);

That just calls mlx5_del_flow_rules a bunch of times but keeps using the
wrong index, which is obviously wrong.

The new fix is to calculate the index properly (hence the switch to a do
{ } while (0) loop, so that we properly delete all of the older rules
rather than calling mlx5_del_flow_rules multiple times on the wrong index.

Makes sense.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

>  				goto destroy_fg;
>  			}
>  		}
Tariq Toukan June 5, 2024, 5:14 a.m. UTC | #2
On 04/06/2024 13:05, Aleksandr Mishin wrote:
> In case of flow rule creation fail in mlx5_lag_create_port_sel_table(),
> instead of previously created rules, the tainted pointer is deleted
> deveral times.
> Fix this bug by using correct flow rules pointers.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 352899f384d4 ("net/mlx5: Lag, use buckets in hash mode")
> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
> index c16b462ddedf..ab2717012b79 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
> @@ -88,9 +88,13 @@ static int mlx5_lag_create_port_sel_table(struct mlx5_lag *ldev,
>   								      &dest, 1);
>   			if (IS_ERR(lag_definer->rules[idx])) {
>   				err = PTR_ERR(lag_definer->rules[idx]);
> -				while (i--)
> -					while (j--)
> +				do {
> +					while (j--) {
> +						idx = i * ldev->buckets + j;
>   						mlx5_del_flow_rules(lag_definer->rules[idx]);
> +					}
> +					j = ldev->buckets;
> +				} while (i--);
>   				goto destroy_fg;
>   			}
>   		}

Reviewed-by: Tariq Toukan <tariqt@nvidia.com> 
 
 


Thanks.
patchwork-bot+netdevbpf@kernel.org June 5, 2024, 9:30 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 4 Jun 2024 13:05:52 +0300 you wrote:
> In case of flow rule creation fail in mlx5_lag_create_port_sel_table(),
> instead of previously created rules, the tainted pointer is deleted
> deveral times.
> Fix this bug by using correct flow rules pointers.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> [...]

Here is the summary with links:
  - [net] net/mlx5: Fix tainted pointer delete is case of flow rules creation fail
    https://git.kernel.org/netdev/net/c/229bedbf62b1

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
index c16b462ddedf..ab2717012b79 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
@@ -88,9 +88,13 @@  static int mlx5_lag_create_port_sel_table(struct mlx5_lag *ldev,
 								      &dest, 1);
 			if (IS_ERR(lag_definer->rules[idx])) {
 				err = PTR_ERR(lag_definer->rules[idx]);
-				while (i--)
-					while (j--)
+				do {
+					while (j--) {
+						idx = i * ldev->buckets + j;
 						mlx5_del_flow_rules(lag_definer->rules[idx]);
+					}
+					j = ldev->buckets;
+				} while (i--);
 				goto destroy_fg;
 			}
 		}