Skip to contentSkip to conversation

tls: Fixed a memory leak during socket close

PATCH Applied Vakul Garg 2 participants 2 messages Sep 25, 2018 – Sep 26, 2018

Subsystems (3)
lore
Share & tools
lore

Vakul Garg

author
#0 lore raw

PATCH 1/1 tls: Fixed a memory leak during socket close

During socket close, if there is a open record with tx context, it needs to be be freed apart from freeing up plaintext and encrypted scatter lists. This patch frees up the open record if present in tx context.

Also tls_free_both_sg() has been renamed to tls_free_open_rec() to indicate that the free record in tx context is being freed inside the function.

Fixes a42055e8d2c3 ("net/tls: Add support for async encryption")
---
 net/tls/tls_sw.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/tls/tls_sw.c +4 -2
index bf03f32aa983..6f2dc1873556 100644
@@ -310,7 +310,7 @@ static void free_sg(struct sock *sk, struct scatterlist *sg,
 	*sg_size = 0;
 }
 
-static void tls_free_both_sg(struct sock *sk)
+static void tls_free_open_rec(struct sock *sk)
 {
 	struct tls_context *tls_ctx = tls_get_ctx(sk);
 	struct tls_sw_context_tx *ctx = tls_sw_ctx_tx(tls_ctx);
@@ -327,6 +327,8 @@ static void tls_free_both_sg(struct sock *sk)
 	free_sg(sk, rec->sg_plaintext_data,
 		&rec->sg_plaintext_num_elem,
 		&rec->sg_plaintext_size);
+
+	kfree(rec);
 }
 
 int tls_tx_records(struct sock *sk, int flags)
@@ -1580,7 +1582,7 @@ void tls_sw_free_resources_tx(struct sock *sk)
 	}
 
 	crypto_free_aead(ctx->aead_send);
-	tls_free_both_sg(sk);
+	tls_free_open_rec(sk);
 
 	kfree(ctx);
 }
Signature · 1 line
2.13.6
maintainer Applied
#1 lore raw

From: Vakul Garg <[email protected]>
Date: Tue, 25 Sep 2018 20:21:51 +0530

Quoted 10 lines

During socket close, if there is a open record with tx context, it needs to be be freed apart from freeing up plaintext and encrypted scatter lists. This patch frees up the open record if present in tx context.

Also tls_free_both_sg() has been renamed to tls_free_open_rec() to indicate that the free record in tx context is being freed inside the function.

Fixes a42055e8d2c3 ("net/tls: Add support for async encryption")

Applied.