All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init()
@ 2022-11-10  9:03 Yu Liao
  2022-11-10  9:14 ` Gal Pressman
  2022-11-12  5:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Yu Liao @ 2022-11-10  9:03 UTC (permalink / raw)
  To: borisp, john.fastabend, kuba, gal, pabeni, edumazet, davem
  Cc: liaoyu15, liwei391, netdev

'aead_req' and 'aead_send' is allocated but not freed in default switch
case. This commit fixes the potential memory leak by freeing them under
the situation.

Fixes: ea7a9d88ba21 ("net/tls: Use cipher sizes structs")
Signed-off-by: Yu Liao <liaoyu15@huawei.com>
---
v1->v2: Also fix memory leak in tls_sw_fallback_init().

 net/tls/tls_device_fallback.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c
index cdb391a8754b..7fbb1d0b69b3 100644
--- a/net/tls/tls_device_fallback.c
+++ b/net/tls/tls_device_fallback.c
@@ -346,7 +346,7 @@ static struct sk_buff *tls_enc_skb(struct tls_context *tls_ctx,
 		salt = tls_ctx->crypto_send.aes_gcm_256.salt;
 		break;
 	default:
-		return NULL;
+		goto free_req;
 	}
 	cipher_sz = &tls_cipher_size_desc[tls_ctx->crypto_send.info.cipher_type];
 	buf_len = cipher_sz->salt + cipher_sz->iv + TLS_AAD_SPACE_SIZE +
@@ -492,7 +492,8 @@ int tls_sw_fallback_init(struct sock *sk,
 		key = ((struct tls12_crypto_info_aes_gcm_256 *)crypto_info)->key;
 		break;
 	default:
-		return -EINVAL;
+		rc = -EINVAL;
+		goto free_aead;
 	}
 	cipher_sz = &tls_cipher_size_desc[crypto_info->cipher_type];
 
-- 
2.25.1


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

* Re: [PATCH v2] net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init()
  2022-11-10  9:03 [PATCH v2] net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init() Yu Liao
@ 2022-11-10  9:14 ` Gal Pressman
  2022-11-12  5:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Gal Pressman @ 2022-11-10  9:14 UTC (permalink / raw)
  To: Yu Liao, borisp, john.fastabend, kuba, pabeni, edumazet, davem
  Cc: liwei391, netdev

On 10/11/2022 11:03, Yu Liao wrote:
> 'aead_req' and 'aead_send' is allocated but not freed in default switch
> case. This commit fixes the potential memory leak by freeing them under
> the situation.
>
> Fixes: ea7a9d88ba21 ("net/tls: Use cipher sizes structs")
> Signed-off-by: Yu Liao <liaoyu15@huawei.com>
> ---
> v1->v2: Also fix memory leak in tls_sw_fallback_init().
>
>  net/tls/tls_device_fallback.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c
> index cdb391a8754b..7fbb1d0b69b3 100644
> --- a/net/tls/tls_device_fallback.c
> +++ b/net/tls/tls_device_fallback.c
> @@ -346,7 +346,7 @@ static struct sk_buff *tls_enc_skb(struct tls_context *tls_ctx,
>  		salt = tls_ctx->crypto_send.aes_gcm_256.salt;
>  		break;
>  	default:
> -		return NULL;
> +		goto free_req;
>  	}
>  	cipher_sz = &tls_cipher_size_desc[tls_ctx->crypto_send.info.cipher_type];
>  	buf_len = cipher_sz->salt + cipher_sz->iv + TLS_AAD_SPACE_SIZE +
> @@ -492,7 +492,8 @@ int tls_sw_fallback_init(struct sock *sk,
>  		key = ((struct tls12_crypto_info_aes_gcm_256 *)crypto_info)->key;
>  		break;
>  	default:
> -		return -EINVAL;
> +		rc = -EINVAL;
> +		goto free_aead;
>  	}
>  	cipher_sz = &tls_cipher_size_desc[crypto_info->cipher_type];
>  

Thanks!
Reviewed-by: Gal Pressman <gal@nvidia.com>

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

* Re: [PATCH v2] net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init()
  2022-11-10  9:03 [PATCH v2] net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init() Yu Liao
  2022-11-10  9:14 ` Gal Pressman
@ 2022-11-12  5:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-12  5:10 UTC (permalink / raw)
  To: Yu Liao
  Cc: borisp, john.fastabend, kuba, gal, pabeni, edumazet, davem,
	liwei391, netdev

Hello:

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

On Thu, 10 Nov 2022 17:03:29 +0800 you wrote:
> 'aead_req' and 'aead_send' is allocated but not freed in default switch
> case. This commit fixes the potential memory leak by freeing them under
> the situation.
> 
> Fixes: ea7a9d88ba21 ("net/tls: Use cipher sizes structs")
> Signed-off-by: Yu Liao <liaoyu15@huawei.com>
> 
> [...]

Here is the summary with links:
  - [v2] net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init()
    https://git.kernel.org/netdev/net/c/0834ced65a6a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-11-12  5:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10  9:03 [PATCH v2] net/tls: Fix memory leak in tls_enc_skb() and tls_sw_fallback_init() Yu Liao
2022-11-10  9:14 ` Gal Pressman
2022-11-12  5:10 ` patchwork-bot+netdevbpf

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.