diff mbox series

net/mlx5e: Fix return of a kfree'd object instead of NULL

Message ID 20220224221525.147744-1-colin.i.king@gmail.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series net/mlx5e: Fix return of a kfree'd object instead of NULL | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Colin Ian King Feb. 24, 2022, 10:15 p.m. UTC
Currently in the case where parse_attr fails to be allocated the memory
pointed to by attr2 is kfree'd but the non-null pointer attr2 is returned
and a potential use of a kfree'd object can occur.  Fix this by returning
NULL to indicate a memory allocation error.

Addresses issue found by clang-scan:
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:3401:3: warning: Use of
memory after it is freed [unix.Malloc]

Fixes: 8300f225268b ("net/mlx5e: Create new flow attr for multi table actions")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Roi Dayan Feb. 25, 2022, 12:14 p.m. UTC | #1
On 2022-02-25 12:15 AM, Colin Ian King wrote:
> Currently in the case where parse_attr fails to be allocated the memory
> pointed to by attr2 is kfree'd but the non-null pointer attr2 is returned
> and a potential use of a kfree'd object can occur.  Fix this by returning
> NULL to indicate a memory allocation error.
> 
> Addresses issue found by clang-scan:
> drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:3401:3: warning: Use of
> memory after it is freed [unix.Malloc]
> 
> Fixes: 8300f225268b ("net/mlx5e: Create new flow attr for multi table actions")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> index 76a015dfc5fc..c0776a4a3845 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> @@ -3398,7 +3398,7 @@ mlx5e_clone_flow_attr_for_post_act(struct mlx5_flow_attr *attr,
>   	if (!attr2 || !parse_attr) {
>   		kvfree(parse_attr);
>   		kfree(attr2);
> -		return attr2;
> +		return NULL;
>   	}
>   
>   	memcpy(attr2, attr, attr_sz);


thanks!

Reviewed-by: Roi Dayan <roid@nvidia.com>
Saeed Mahameed March 1, 2022, 7:11 a.m. UTC | #2
On 24 Feb 22:15, Colin Ian King wrote:
>Currently in the case where parse_attr fails to be allocated the memory
>pointed to by attr2 is kfree'd but the non-null pointer attr2 is returned
>and a potential use of a kfree'd object can occur.  Fix this by returning
>NULL to indicate a memory allocation error.
>
>Addresses issue found by clang-scan:
>drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:3401:3: warning: Use of
>memory after it is freed [unix.Malloc]
>
>Fixes: 8300f225268b ("net/mlx5e: Create new flow attr for multi table actions")
>Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Applied to net-next-mlx5
Thanks.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 76a015dfc5fc..c0776a4a3845 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -3398,7 +3398,7 @@  mlx5e_clone_flow_attr_for_post_act(struct mlx5_flow_attr *attr,
 	if (!attr2 || !parse_attr) {
 		kvfree(parse_attr);
 		kfree(attr2);
-		return attr2;
+		return NULL;
 	}
 
 	memcpy(attr2, attr, attr_sz);