summaryrefslogtreecommitdiff
path: root/net/tls
diff options
context:
space:
mode:
authorMaxim Mikityanskiy <maximmi@nvidia.com>2022-05-12 12:18:30 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-05-18 11:23:45 +0300
commitfccf4bf3f25dff4aa47d80926298f3707b8d1072 (patch)
treef3029a7720b0e517783aedefa641afbe419bb5fa /net/tls
parent161c4edeca45a1b24a589693efbc639ecf850c20 (diff)
downloadlinux-fccf4bf3f25dff4aa47d80926298f3707b8d1072.tar.xz
tls: Fix context leak on tls_device_down
[ Upstream commit 3740651bf7e200109dd42d5b2fb22226b26f960a ] The commit cited below claims to fix a use-after-free condition after tls_device_down. Apparently, the description wasn't fully accurate. The context stayed alive, but ctx->netdev became NULL, and the offload was torn down without a proper fallback, so a bug was present, but a different kind of bug. Due to misunderstanding of the issue, the original patch dropped the refcount_dec_and_test line for the context to avoid the alleged premature deallocation. That line has to be restored, because it matches the refcount_inc_not_zero from the same function, otherwise the contexts that survived tls_device_down are leaked. This patch fixes the described issue by restoring refcount_dec_and_test. After this change, there is no leak anymore, and the fallback to software kTLS still works. Fixes: c55dcdd435aa ("net/tls: Fix use-after-free after the TLS device goes down and up") Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com> Reviewed-by: Tariq Toukan <tariqt@nvidia.com> Link: https://lore.kernel.org/r/20220512091830.678684-1-maximmi@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net/tls')
-rw-r--r--net/tls/tls_device.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index 1f56225a10e3..3c82286e5bcc 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -1345,7 +1345,10 @@ static int tls_device_down(struct net_device *netdev)
/* Device contexts for RX and TX will be freed in on sk_destruct
* by tls_device_free_ctx. rx_conf and tx_conf stay in TLS_HW.
+ * Now release the ref taken above.
*/
+ if (refcount_dec_and_test(&ctx->refcount))
+ tls_device_free_ctx(ctx);
}
up_write(&device_offload_lock);