tls: Fix context leak on tls_device_down
Subsystems (3)
PATCH 1/1 tls: Fix context leak on tls_device_down
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.
--- net/tls/tls_device.c | 3 +++ 1 file changed, 3 insertions(+)
net/tls/tls_device.c +3 -0
@@ -1347,7 +1347,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);
Signature · 1 line
2.25.1
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 6 lines · On Thu, 12 May 2022 12:18:30 +0300 you wrote:
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, butctx->netdevbecame NULL, and the offload was torn down without a proper fallback, so a bug was present, but a different kind of bug.
Quoted 7 lines
Due to misunderstanding of the issue, the original patch dropped the
refcount_dec_and_testline for the context to avoid the alleged premature deallocation. That line has to be restored, because it matches therefcount_inc_not_zerofrom the same function, otherwise the contexts that survivedtls_device_downare leaked.[...]
Here is the summary with links:
- [net] tls: Fix context leak on tls_device_down
https://git.kernel.org/netdev/net/c/3740651bf7e2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html