Skip to content

Commit 3740651

Browse files
nvmmaxkuba-moo
authored andcommitted
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. Fixes: c55dcdd ("net/tls: Fix use-after-free after the TLS device goes down and up") Signed-off-by: Maxim Mikityanskiy <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1fa89ff commit 3740651

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/tls/tls_device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,10 @@ static int tls_device_down(struct net_device *netdev)
13471347

13481348
/* Device contexts for RX and TX will be freed in on sk_destruct
13491349
* by tls_device_free_ctx. rx_conf and tx_conf stay in TLS_HW.
1350+
* Now release the ref taken above.
13501351
*/
1352+
if (refcount_dec_and_test(&ctx->refcount))
1353+
tls_device_free_ctx(ctx);
13511354
}
13521355

13531356
up_write(&device_offload_lock);

0 commit comments

Comments
 (0)