tls: Fix TLS ulp context leak, when TLS_TX setsockopt is not used.
authorIlya Lesokhin <ilyal@mellanox.com>
Mon, 13 Nov 2017 08:22:46 +0000 (10:22 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Dec 2018 18:41:10 +0000 (19:41 +0100)
commit797b8bb47fb27ee49a3b59ad110e5264585415aa
tree7e43376df244a7e4a3563262713d0cbc5a26216d
parent25f03991a5210f31491e1e2fccec7cf0d080772e
tls: Fix TLS ulp context leak, when TLS_TX setsockopt is not used.

commit ff45d820a2df163957ad8ab459b6eb6976144c18 upstream.

Previously the TLS ulp context would leak if we attached a TLS ulp
to a socket but did not use the TLS_TX setsockopt,
or did use it but it failed.
This patch solves the issue by overriding prot[TLS_BASE_TX].close
and fixing tls_sk_proto_close to work properly
when its called with ctx->tx_conf == TLS_BASE_TX.
This patch also removes ctx->free_resources as we can use ctx->tx_conf
to obtain the relevant information.

Fixes: 3c4d7559159b ('tls: kernel TLS support')
Signed-off-by: Ilya Lesokhin <ilyal@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 4.14: Keep using tls_ctx_free() as introduced by
 the earlier backport of "tls: zero the crypto information from
 tls_context before freeing"]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/tls.h
net/tls/tls_main.c
net/tls/tls_sw.c