Skip to content

Commit c774973

Browse files
nxa22042davem330
authored andcommitted
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: a42055e ("net/tls: Add support for async encryption") Signed-off-by: Vakul Garg <vakul.garg@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b85135b commit c774973

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/tls/tls_sw.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static void free_sg(struct sock *sk, struct scatterlist *sg,
310310
*sg_size = 0;
311311
}
312312

313-
static void tls_free_both_sg(struct sock *sk)
313+
static void tls_free_open_rec(struct sock *sk)
314314
{
315315
struct tls_context *tls_ctx = tls_get_ctx(sk);
316316
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)
327327
free_sg(sk, rec->sg_plaintext_data,
328328
&rec->sg_plaintext_num_elem,
329329
&rec->sg_plaintext_size);
330+
331+
kfree(rec);
330332
}
331333

332334
int tls_tx_records(struct sock *sk, int flags)
@@ -1591,7 +1593,7 @@ void tls_sw_free_resources_tx(struct sock *sk)
15911593
}
15921594

15931595
crypto_free_aead(ctx->aead_send);
1594-
tls_free_both_sg(sk);
1596+
tls_free_open_rec(sk);
15951597

15961598
kfree(ctx);
15971599
}

0 commit comments

Comments
 (0)