diff options
author | Sabrina Dubroca <sd@queasysnail.net> | 2018-09-12 11:44:42 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-09-13 15:03:47 -0400 |
commit | 86029d10af18381814881d6cce2dd6872163b59f (patch) | |
tree | ca14c5fa1d55c1b5833e225571ed0aee777715cb /net/tls/tls_main.c | |
parent | 7cba09c6d5bc73ebbd25a353742d9ddb7a713b95 (diff) |
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: 3c4d7559159b ("tls: kernel TLS support")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tls/tls_main.c')
-rw-r--r-- | net/tls/tls_main.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 180b6640e531..737b3865be1b 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c | |||
@@ -241,6 +241,16 @@ static void tls_write_space(struct sock *sk) | |||
241 | ctx->sk_write_space(sk); | 241 | ctx->sk_write_space(sk); |
242 | } | 242 | } |
243 | 243 | ||
244 | static void tls_ctx_free(struct tls_context *ctx) | ||
245 | { | ||
246 | if (!ctx) | ||
247 | return; | ||
248 | |||
249 | memzero_explicit(&ctx->crypto_send, sizeof(ctx->crypto_send)); | ||
250 | memzero_explicit(&ctx->crypto_recv, sizeof(ctx->crypto_recv)); | ||
251 | kfree(ctx); | ||
252 | } | ||
253 | |||
244 | static void tls_sk_proto_close(struct sock *sk, long timeout) | 254 | static void tls_sk_proto_close(struct sock *sk, long timeout) |
245 | { | 255 | { |
246 | struct tls_context *ctx = tls_get_ctx(sk); | 256 | struct tls_context *ctx = tls_get_ctx(sk); |
@@ -294,7 +304,7 @@ static void tls_sk_proto_close(struct sock *sk, long timeout) | |||
294 | #else | 304 | #else |
295 | { | 305 | { |
296 | #endif | 306 | #endif |
297 | kfree(ctx); | 307 | tls_ctx_free(ctx); |
298 | ctx = NULL; | 308 | ctx = NULL; |
299 | } | 309 | } |
300 | 310 | ||
@@ -305,7 +315,7 @@ skip_tx_cleanup: | |||
305 | * for sk->sk_prot->unhash [tls_hw_unhash] | 315 | * for sk->sk_prot->unhash [tls_hw_unhash] |
306 | */ | 316 | */ |
307 | if (free_ctx) | 317 | if (free_ctx) |
308 | kfree(ctx); | 318 | tls_ctx_free(ctx); |
309 | } | 319 | } |
310 | 320 | ||
311 | static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval, | 321 | 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, | |||
330 | } | 340 | } |
331 | 341 | ||
332 | /* get user crypto info */ | 342 | /* get user crypto info */ |
333 | crypto_info = &ctx->crypto_send; | 343 | crypto_info = &ctx->crypto_send.info; |
334 | 344 | ||
335 | if (!TLS_CRYPTO_INFO_READY(crypto_info)) { | 345 | if (!TLS_CRYPTO_INFO_READY(crypto_info)) { |
336 | rc = -EBUSY; | 346 | rc = -EBUSY; |
@@ -417,9 +427,9 @@ static int do_tls_setsockopt_conf(struct sock *sk, char __user *optval, | |||
417 | } | 427 | } |
418 | 428 | ||
419 | if (tx) | 429 | if (tx) |
420 | crypto_info = &ctx->crypto_send; | 430 | crypto_info = &ctx->crypto_send.info; |
421 | else | 431 | else |
422 | crypto_info = &ctx->crypto_recv; | 432 | crypto_info = &ctx->crypto_recv.info; |
423 | 433 | ||
424 | /* Currently we don't support set crypto info more than one time */ | 434 | /* Currently we don't support set crypto info more than one time */ |
425 | if (TLS_CRYPTO_INFO_READY(crypto_info)) { | 435 | if (TLS_CRYPTO_INFO_READY(crypto_info)) { |