aboutsummaryrefslogtreecommitdiffstats
path: root/net/tls/tls_main.c
diff options
context:
space:
mode:
authorAtul Gupta <atul.gupta@chelsio.com>2019-01-17 23:56:21 -0500
committerDavid S. Miller <davem@davemloft.net>2019-01-22 14:30:54 -0500
commit76f7164d02d4c596b396fc2e868276d1db3c5e1e (patch)
treeeb03af48adc94fef9d954569052b45c21ba815c1 /net/tls/tls_main.c
parent63a6b3fee428aeb0288670fc061fa9559b5aca1b (diff)
net/tls: free ctx in sock destruct
free tls context in sock destruct. close may not be the last call to free sock but force releasing the ctx in close will result in GPF when ctx referred again in tcp_done [ 515.330477] general protection fault: 0000 [#1] SMP PTI [ 515.330539] CPU: 5 PID: 0 Comm: swapper/5 Not tainted 4.20.0-rc7+ #10 [ 515.330657] Hardware name: Supermicro X8ST3/X8ST3, BIOS 2.0b 11/07/2013 [ 515.330844] RIP: 0010:tls_hw_unhash+0xbf/0xd0 [ [ 515.332220] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 515.332340] CR2: 00007fab32c55000 CR3: 000000009261e000 CR4: 00000000000006e0 [ 515.332519] Call Trace: [ 515.332632] <IRQ> [ 515.332793] tcp_set_state+0x5a/0x190 [ 515.332907] ? tcp_update_metrics+0xe3/0x350 [ 515.333023] tcp_done+0x31/0xd0 [ 515.333130] tcp_rcv_state_process+0xc27/0x111a [ 515.333242] ? __lock_is_held+0x4f/0x90 [ 515.333350] ? tcp_v4_do_rcv+0xaf/0x1e0 [ 515.333456] tcp_v4_do_rcv+0xaf/0x1e0 Signed-off-by: Atul Gupta <atul.gupta@chelsio.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tls/tls_main.c')
-rw-r--r--net/tls/tls_main.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index fc97a105ebc2..d36d095cbcf0 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -266,8 +266,10 @@ static void tls_sk_proto_close(struct sock *sk, long timeout)
266 lock_sock(sk); 266 lock_sock(sk);
267 sk_proto_close = ctx->sk_proto_close; 267 sk_proto_close = ctx->sk_proto_close;
268 268
269 if ((ctx->tx_conf == TLS_HW_RECORD && ctx->rx_conf == TLS_HW_RECORD) || 269 if (ctx->tx_conf == TLS_HW_RECORD && ctx->rx_conf == TLS_HW_RECORD)
270 (ctx->tx_conf == TLS_BASE && ctx->rx_conf == TLS_BASE)) { 270 goto skip_tx_cleanup;
271
272 if (ctx->tx_conf == TLS_BASE && ctx->rx_conf == TLS_BASE) {
271 free_ctx = true; 273 free_ctx = true;
272 goto skip_tx_cleanup; 274 goto skip_tx_cleanup;
273 } 275 }
@@ -579,6 +581,17 @@ static void tls_build_proto(struct sock *sk)
579 } 581 }
580} 582}
581 583
584static void tls_hw_sk_destruct(struct sock *sk)
585{
586 struct tls_context *ctx = tls_get_ctx(sk);
587 struct inet_connection_sock *icsk = inet_csk(sk);
588
589 ctx->sk_destruct(sk);
590 /* Free ctx */
591 kfree(ctx);
592 icsk->icsk_ulp_data = NULL;
593}
594
582static int tls_hw_prot(struct sock *sk) 595static int tls_hw_prot(struct sock *sk)
583{ 596{
584 struct tls_context *ctx; 597 struct tls_context *ctx;
@@ -597,6 +610,8 @@ static int tls_hw_prot(struct sock *sk)
597 ctx->hash = sk->sk_prot->hash; 610 ctx->hash = sk->sk_prot->hash;
598 ctx->unhash = sk->sk_prot->unhash; 611 ctx->unhash = sk->sk_prot->unhash;
599 ctx->sk_proto_close = sk->sk_prot->close; 612 ctx->sk_proto_close = sk->sk_prot->close;
613 ctx->sk_destruct = sk->sk_destruct;
614 sk->sk_destruct = tls_hw_sk_destruct;
600 ctx->rx_conf = TLS_HW_RECORD; 615 ctx->rx_conf = TLS_HW_RECORD;
601 ctx->tx_conf = TLS_HW_RECORD; 616 ctx->tx_conf = TLS_HW_RECORD;
602 update_sk_prot(sk, ctx); 617 update_sk_prot(sk, ctx);