Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH 1/2] eth: mlx5: fix double free of flow_table groups on allocation failure
@ 2025-09-04 14:08 Makar Semyonov
  2025-09-04 18:25 ` Markus Elfring
  2025-09-08  7:28 ` Tariq Toukan
  0 siblings, 2 replies; 3+ messages in thread
From: Makar Semyonov @ 2025-09-04 14:08 UTC (permalink / raw)
  To: Saeed Mahameed
  Cc: Makar Semyonov, Leon Romanovsky, Tariq Toukan, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Sabrina Dubroca, netdev, linux-rdma, linux-kernel

In macsec_fs_rx_create_crypto_table_groups(), when memory allocation for 
'in' fails, 'ft->g' is cleared once. However, the function returns 
a non-zero error which causes macsec_fs_rx_destroy to be called. 
Inside it, macsec_fs_destroy_flow_table is invoked, which attempts 
to clear 'ft->g' again, leading to a double free.

This commit fixes the issue by setting 'ft->g' to NULL immediately 
after the first clearance in macsec_fs_rx_create_crypto_table_groups() 
to prevent a double free when macsec_fs_destroy_flow_table attempts to 
free it again.

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

Signed-off-by: Makar Semyonov <m.semenov@tssltd.ru>
---
 drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
index 4a078113e292..5e86c277f33a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
@@ -1066,6 +1066,7 @@ static int macsec_fs_rx_create_crypto_table_groups(struct mlx5_macsec_flow_table
 	in = kvzalloc(inlen, GFP_KERNEL);
 	if (!in) {
 		kfree(ft->g);
+		ft->g = NULL;
 		return -ENOMEM;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] eth: mlx5: fix double free of flow_table groups on allocation failure
  2025-09-04 14:08 [PATCH 1/2] eth: mlx5: fix double free of flow_table groups on allocation failure Makar Semyonov
@ 2025-09-04 18:25 ` Markus Elfring
  2025-09-08  7:28 ` Tariq Toukan
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-09-04 18:25 UTC (permalink / raw)
  To: Makar Semyonov, linux-rdma, netdev
  Cc: LKML, Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Leon Romanovsky, Paolo Abeni, Saeed Mahameed, Sabrina Dubroca,
	Tariq Toukan

…
> This commit fixes the issue by …

* See also:
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc4#n94

* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?

* Would you like to reconsider the numbers in the subject prefix?


Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] eth: mlx5: fix double free of flow_table groups on allocation failure
  2025-09-04 14:08 [PATCH 1/2] eth: mlx5: fix double free of flow_table groups on allocation failure Makar Semyonov
  2025-09-04 18:25 ` Markus Elfring
@ 2025-09-08  7:28 ` Tariq Toukan
  1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2025-09-08  7:28 UTC (permalink / raw)
  To: Makar Semyonov, Saeed Mahameed
  Cc: Leon Romanovsky, Tariq Toukan, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Sabrina Dubroca,
	netdev, linux-rdma, linux-kernel



On 04/09/2025 17:08, Makar Semyonov wrote:
> In macsec_fs_rx_create_crypto_table_groups(), when memory allocation for
> 'in' fails, 'ft->g' is cleared once. However, the function returns
> a non-zero error which causes macsec_fs_rx_destroy to be called.
> Inside it, macsec_fs_destroy_flow_table is invoked, which attempts
> to clear 'ft->g' again, leading to a double free.
> 
> This commit fixes the issue by setting 'ft->g' to NULL immediately
> after the first clearance in macsec_fs_rx_create_crypto_table_groups()
> to prevent a double free when macsec_fs_destroy_flow_table attempts to
> free it again.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Makar Semyonov <m.semenov@tssltd.ru>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
> index 4a078113e292..5e86c277f33a 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
> @@ -1066,6 +1066,7 @@ static int macsec_fs_rx_create_crypto_table_groups(struct mlx5_macsec_flow_table
>   	in = kvzalloc(inlen, GFP_KERNEL);
>   	if (!in) {
>   		kfree(ft->g);
> +		ft->g = NULL;
>   		return -ENOMEM;
>   	}
>   

Code and commit message are fine.
Use "net/mlx5" prefix.
Please address comments from Markus Elfring.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-08  7:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-04 14:08 [PATCH 1/2] eth: mlx5: fix double free of flow_table groups on allocation failure Makar Semyonov
2025-09-04 18:25 ` Markus Elfring
2025-09-08  7:28 ` Tariq Toukan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox