aboutsummaryrefslogtreecommitdiffstats
path: root/net/tls/tls_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tls/tls_main.c')
-rw-r--r--net/tls/tls_main.c22
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
244static 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
244static void tls_sk_proto_close(struct sock *sk, long timeout) 254static 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
311static int do_tls_getsockopt_tx(struct sock *sk, char __user *optval, 321static 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
501err_crypto_info: 511err_crypto_info:
502 memset(crypto_info, 0, sizeof(*crypto_info)); 512 memzero_explicit(crypto_info, sizeof(union tls_crypto_context));
503out: 513out:
504 return rc; 514 return rc;
505} 515}