Message ID | 20220512091830.678684-1-maximmi@nvidia.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 3740651bf7e200109dd42d5b2fb22226b26f960a |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] tls: Fix context leak on tls_device_down | expand |
Hello: This patch was applied to netdev/net.git (master) by Jakub Kicinski <kuba@kernel.org>: 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, 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. > > [...] 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!
diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index af875ad4a822..3919fe2c58c5 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -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);