tls: zero the crypto information from tls_context before freeing
This contains key material in crypto_send_aes_gcm_128 and
crypto_recv_aes_gcm_128.
Introduce union tls_crypto_context, and replace the two identical
unions directly embedded in struct tls_context with it. We can then
use this union to clean up the memory in the new tls_ctx_free()
function.
Fixes: 3c4d755915
("tls: kernel TLS support")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
7cba09c6d5
commit
86029d10af
@@ -241,6 +241,16 @@ static void tls_write_space(struct sock *sk)
|
||||
ctx->sk_write_space(sk);
|
||||
}
|
||||
|
||||
static void tls_ctx_free(struct tls_context *ctx)
|
||||
{
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
memzero_explicit(&ctx->crypto_send, sizeof(ctx->crypto_send));
|
||||
memzero_explicit(&ctx->crypto_recv, sizeof(ctx->crypto_recv));
|
||||
kfree(ctx);
|
||||
}
|
||||
|
||||
static void tls_sk_proto_close(struct sock *sk, long timeout)
|
||||
{
|
||||
struct tls_context *ctx = tls_get_ctx(sk);
|
||||
@@ -294,7 +304,7 @@ static void tls_sk_proto_close(struct sock *sk, long timeout)
|
||||
#else
|
||||
{
|
||||
#endif
|
||||
kfree(ctx);
|
||||
tls_ctx_free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
|
||||
@@ -305,7 +315,7 @@ skip_tx_cleanup:
|
||||
* for sk->sk_prot->unhash [tls_hw_unhash]
|
||||
*/
|
||||
if (free_ctx)
|
||||
kfree(ctx);
|
||||
tls_ctx_free(ctx);
|
||||
}
|
||||
|
||||
static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval,
|
||||
@@ -330,7 +340,7 @@ static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval,
|
||||
}
|
||||
|
||||
/* get user crypto info */
|
||||
crypto_info = &ctx->crypto_send;
|
||||
crypto_info = &ctx->crypto_send.info;
|
||||
|
||||
if (!TLS_CRYPTO_INFO_READY(crypto_info)) {
|
||||
rc = -EBUSY;
|
||||
@@ -417,9 +427,9 @@ static int do_tls_setsockopt_conf(struct sock *sk, char __user *optval,
|
||||
}
|
||||
|
||||
if (tx)
|
||||
crypto_info = &ctx->crypto_send;
|
||||
crypto_info = &ctx->crypto_send.info;
|
||||
else
|
||||
crypto_info = &ctx->crypto_recv;
|
||||
crypto_info = &ctx->crypto_recv.info;
|
||||
|
||||
/* Currently we don't support set crypto info more than one time */
|
||||
if (TLS_CRYPTO_INFO_READY(crypto_info)) {
|
||||
|
Reference in New Issue
Block a user