netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] tls: Fix context leak on tls_device_down
@ 2022-05-12  9:18 Maxim Mikityanskiy
  2022-05-12 18:40 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Maxim Mikityanskiy @ 2022-05-12  9:18 UTC (permalink / raw)
  To: Jakub Kicinski, David S. Miller, Daniel Borkmann, John Fastabend
  Cc: Paolo Abeni, Boris Pismenny, Tariq Toukan, Eric Dumazet, netdev,
	Maxim Mikityanskiy

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>
---
 net/tls/tls_device.c | 3 +++
 1 file changed, 3 insertions(+)

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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] tls: Fix context leak on tls_device_down
  2022-05-12  9:18 [PATCH net] tls: Fix context leak on tls_device_down Maxim Mikityanskiy
@ 2022-05-12 18:40 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-05-12 18:40 UTC (permalink / raw)
  To: Maxim Mikityanskiy
  Cc: kuba, davem, daniel, john.fastabend, pabeni, borisp, tariqt,
	edumazet, netdev

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-12 18:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12  9:18 [PATCH net] tls: Fix context leak on tls_device_down Maxim Mikityanskiy
2022-05-12 18:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).