net/tls: Only attach to sockets in ESTABLISHED state
authorIlya Lesokhin <ilyal@mellanox.com>
Tue, 16 Jan 2018 13:31:52 +0000 (15:31 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Jan 2018 13:03:48 +0000 (14:03 +0100)
commita022bbe393fbe3a1f471ee94d846be03f7fe2136
tree3403ea14792d77dd907f0aebfeffd597e18447a1
parent48606bb1eef7c46f154cb4a6c5509729e60a4e91
net/tls: Only attach to sockets in ESTABLISHED state

[ Upstream commit d91c3e17f75f218022140dee18cf515292184a8f ]

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>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/tls/tls_main.c