* [PATCH] net/mlx5e: Fix return of a kfree'd object instead of NULL
@ 2022-02-24 22:15 Colin Ian King
2022-02-25 12:14 ` Roi Dayan
2022-03-01 7:11 ` Saeed Mahameed
0 siblings, 2 replies; 3+ messages in thread
From: Colin Ian King @ 2022-02-24 22:15 UTC (permalink / raw)
To: Saeed Mahameed, Leon Romanovsky, David S . Miller,
Jakub Kicinski, Nathan Chancellor, Nick Desaulniers, Roi Dayan,
netdev, linux-rdma
Cc: kernel-janitors, linux-kernel, llvm
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);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net/mlx5e: Fix return of a kfree'd object instead of NULL
2022-02-24 22:15 [PATCH] net/mlx5e: Fix return of a kfree'd object instead of NULL Colin Ian King
@ 2022-02-25 12:14 ` Roi Dayan
2022-03-01 7:11 ` Saeed Mahameed
1 sibling, 0 replies; 3+ messages in thread
From: Roi Dayan @ 2022-02-25 12:14 UTC (permalink / raw)
To: Colin Ian King, Saeed Mahameed, Leon Romanovsky,
David S . Miller, Jakub Kicinski, Nathan Chancellor,
Nick Desaulniers, netdev, linux-rdma
Cc: kernel-janitors, linux-kernel, llvm
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net/mlx5e: Fix return of a kfree'd object instead of NULL
2022-02-24 22:15 [PATCH] net/mlx5e: Fix return of a kfree'd object instead of NULL Colin Ian King
2022-02-25 12:14 ` Roi Dayan
@ 2022-03-01 7:11 ` Saeed Mahameed
1 sibling, 0 replies; 3+ messages in thread
From: Saeed Mahameed @ 2022-03-01 7:11 UTC (permalink / raw)
To: Colin Ian King
Cc: Saeed Mahameed, Leon Romanovsky, David S . Miller,
Jakub Kicinski, Nathan Chancellor, Nick Desaulniers, Roi Dayan,
netdev, linux-rdma, kernel-janitors, linux-kernel, llvm
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-01 7:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24 22:15 [PATCH] net/mlx5e: Fix return of a kfree'd object instead of NULL Colin Ian King
2022-02-25 12:14 ` Roi Dayan
2022-03-01 7:11 ` Saeed Mahameed
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.