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.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index 78cb4a584080..fc97a105ebc2 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -61,6 +61,8 @@ static LIST_HEAD(device_list);
61static DEFINE_SPINLOCK(device_spinlock); 61static DEFINE_SPINLOCK(device_spinlock);
62static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG]; 62static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG];
63static struct proto_ops tls_sw_proto_ops; 63static struct proto_ops tls_sw_proto_ops;
64static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
65 struct proto *base);
64 66
65static void update_sk_prot(struct sock *sk, struct tls_context *ctx) 67static void update_sk_prot(struct sock *sk, struct tls_context *ctx)
66{ 68{
@@ -551,6 +553,32 @@ static struct tls_context *create_ctx(struct sock *sk)
551 return ctx; 553 return ctx;
552} 554}
553 555
556static void tls_build_proto(struct sock *sk)
557{
558 int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4;
559
560 /* Build IPv6 TLS whenever the address of tcpv6 _prot changes */
561 if (ip_ver == TLSV6 &&
562 unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv6_prot))) {
563 mutex_lock(&tcpv6_prot_mutex);
564 if (likely(sk->sk_prot != saved_tcpv6_prot)) {
565 build_protos(tls_prots[TLSV6], sk->sk_prot);
566 smp_store_release(&saved_tcpv6_prot, sk->sk_prot);
567 }
568 mutex_unlock(&tcpv6_prot_mutex);
569 }
570
571 if (ip_ver == TLSV4 &&
572 unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv4_prot))) {
573 mutex_lock(&tcpv4_prot_mutex);
574 if (likely(sk->sk_prot != saved_tcpv4_prot)) {
575 build_protos(tls_prots[TLSV4], sk->sk_prot);
576 smp_store_release(&saved_tcpv4_prot, sk->sk_prot);
577 }
578 mutex_unlock(&tcpv4_prot_mutex);
579 }
580}
581
554static int tls_hw_prot(struct sock *sk) 582static int tls_hw_prot(struct sock *sk)
555{ 583{
556 struct tls_context *ctx; 584 struct tls_context *ctx;
@@ -564,12 +592,15 @@ static int tls_hw_prot(struct sock *sk)
564 if (!ctx) 592 if (!ctx)
565 goto out; 593 goto out;
566 594
595 spin_unlock_bh(&device_spinlock);
596 tls_build_proto(sk);
567 ctx->hash = sk->sk_prot->hash; 597 ctx->hash = sk->sk_prot->hash;
568 ctx->unhash = sk->sk_prot->unhash; 598 ctx->unhash = sk->sk_prot->unhash;
569 ctx->sk_proto_close = sk->sk_prot->close; 599 ctx->sk_proto_close = sk->sk_prot->close;
570 ctx->rx_conf = TLS_HW_RECORD; 600 ctx->rx_conf = TLS_HW_RECORD;
571 ctx->tx_conf = TLS_HW_RECORD; 601 ctx->tx_conf = TLS_HW_RECORD;
572 update_sk_prot(sk, ctx); 602 update_sk_prot(sk, ctx);
603 spin_lock_bh(&device_spinlock);
573 rc = 1; 604 rc = 1;
574 break; 605 break;
575 } 606 }
@@ -668,7 +699,6 @@ static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
668 699
669static int tls_init(struct sock *sk) 700static int tls_init(struct sock *sk)
670{ 701{
671 int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4;
672 struct tls_context *ctx; 702 struct tls_context *ctx;
673 int rc = 0; 703 int rc = 0;
674 704
@@ -691,27 +721,7 @@ static int tls_init(struct sock *sk)
691 goto out; 721 goto out;
692 } 722 }
693 723
694 /* Build IPv6 TLS whenever the address of tcpv6 _prot changes */ 724 tls_build_proto(sk);
695 if (ip_ver == TLSV6 &&
696 unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv6_prot))) {
697 mutex_lock(&tcpv6_prot_mutex);
698 if (likely(sk->sk_prot != saved_tcpv6_prot)) {
699 build_protos(tls_prots[TLSV6], sk->sk_prot);
700 smp_store_release(&saved_tcpv6_prot, sk->sk_prot);
701 }
702 mutex_unlock(&tcpv6_prot_mutex);
703 }
704
705 if (ip_ver == TLSV4 &&
706 unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv4_prot))) {
707 mutex_lock(&tcpv4_prot_mutex);
708 if (likely(sk->sk_prot != saved_tcpv4_prot)) {
709 build_protos(tls_prots[TLSV4], sk->sk_prot);
710 smp_store_release(&saved_tcpv4_prot, sk->sk_prot);
711 }
712 mutex_unlock(&tcpv4_prot_mutex);
713 }
714
715 ctx->tx_conf = TLS_BASE; 725 ctx->tx_conf = TLS_BASE;
716 ctx->rx_conf = TLS_BASE; 726 ctx->rx_conf = TLS_BASE;
717 update_sk_prot(sk, ctx); 727 update_sk_prot(sk, ctx);