diff options
author | David S. Miller <davem@davemloft.net> | 2018-09-13 15:03:47 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-09-13 15:03:47 -0400 |
commit | 79140335ac12e71d9270dabe030274a297d8a2cf (patch) | |
tree | 909dc26b18e1ee20e6fcac8936b4bcaa1bfa9eeb /net/tls/tls_main.c | |
parent | f0e0d04413fcce9bc76388839099aee93cd0d33b (diff) | |
parent | c844eb46b7d43c2cf760169df5ae1d5b033af338 (diff) |
Merge branch 'tls-don-t-leave-keys-in-kernel-memory'
Sabrina Dubroca says:
====================
tls: don't leave keys in kernel memory
There are a few places where the RX/TX key for a TLS socket is copied
to kernel memory. This series clears those memory areas when they're no
longer needed.
v2: add union tls_crypto_context, following Vakul Garg's comment
swap patch 2 and 3, using new union in patch 3
====================
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 | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 180b6640e531..523622dc74f8 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)) { |
@@ -499,7 +509,7 @@ static int do_tls_setsockopt_conf(struct sock *sk, char __user *optval, | |||
499 | goto out; | 509 | goto out; |
500 | 510 | ||
501 | err_crypto_info: | 511 | err_crypto_info: |
502 | memset(crypto_info, 0, sizeof(*crypto_info)); | 512 | memzero_explicit(crypto_info, sizeof(union tls_crypto_context)); |
503 | out: | 513 | out: |
504 | return rc; | 514 | return rc; |
505 | } | 515 | } |