diff mbox series

[v2,net,1/1] net/tls: Only attach to sockets in ESTABLISHED state

Message ID 20180116133152.24397-1-ilyal@mellanox.com
State Accepted, archived
Delegated to: David Miller
Headers show
Series [v2,net,1/1] net/tls: Only attach to sockets in ESTABLISHED state | expand

Commit Message

Ilya Lesokhin Jan. 16, 2018, 1:31 p.m. UTC
Calling accept on a TCP socket with a TLS ulp attached results
in two sockets that share the same ulp context.
The ulp context is freed while a socket is destroyed, so
after one of the sockets is released, the second second will
trigger a use after free when it tries to access the ulp context
attached to it.
We restrict the TLS ulp to sockets in ESTABLISHED state
to prevent the scenario above.

Fixes: 3c4d7559159b ("tls: kernel TLS support")
Reported-by: syzbot+904e7cd6c5c741609228@syzkaller.appspotmail.com
Signed-off-by: Ilya Lesokhin <ilyal@mellanox.com>
---
v2: Fix typos

 net/tls/tls_main.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

David Miller Jan. 17, 2018, 9:06 p.m. UTC | #1
From: Ilya Lesokhin <ilyal@mellanox.com>
Date: Tue, 16 Jan 2018 15:31:52 +0200

> Calling accept on a TCP socket with a TLS ulp attached results
> in two sockets that share the same ulp context.
> The ulp context is freed while a socket is destroyed, so
> after one of the sockets is released, the second second will
> trigger a use after free when it tries to access the ulp context
> attached to it.
> We restrict the TLS ulp to sockets in ESTABLISHED state
> to prevent the scenario above.
> 
> Fixes: 3c4d7559159b ("tls: kernel TLS support")
> Reported-by: syzbot+904e7cd6c5c741609228@syzkaller.appspotmail.com
> Signed-off-by: Ilya Lesokhin <ilyal@mellanox.com>
> ---
> v2: Fix typos

Applied and queued up for -stable, thanks.
diff mbox series

Patch

diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index e07ee3ae0023..7b7a70e22d90 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -454,6 +454,15 @@  static int tls_init(struct sock *sk)
 	struct tls_context *ctx;
 	int rc = 0;
 
+	/* The TLS ulp is currently supported only for TCP sockets
+	 * in ESTABLISHED state.
+	 * Supporting sockets in LISTEN state will require us
+	 * to modify the accept implementation to clone rather then
+	 * share the ulp context.
+	 */
+	if (sk->sk_state != TCP_ESTABLISHED)
+		return -ENOTSUPP;
+
 	/* allocate tls context */
 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
 	if (!ctx) {