Skip to content

Commit f633672

Browse files
nvmmaxdavem330
authored andcommitted
net/tls: Remove the context from the list in tls_device_down
tls_device_down takes a reference on all contexts it's going to move to the degraded state (software fallback). If sk_destruct runs afterwards, it can reduce the reference counter back to 1 and return early without destroying the context. Then tls_device_down will release the reference it took and call tls_device_free_ctx. However, the context will still stay in tls_device_down_list forever. The list will contain an item, memory for which is released, making a memory corruption possible. Fix the above bug by properly removing the context from all lists before any call to tls_device_free_ctx. Fixes: 3740651 ("tls: Fix context leak on tls_device_down") Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com> Reviewed-by: Tariq Toukan <tariqt@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4d8f24e commit f633672

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

net/tls/tls_device.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,8 +1376,13 @@ static int tls_device_down(struct net_device *netdev)
13761376
* by tls_device_free_ctx. rx_conf and tx_conf stay in TLS_HW.
13771377
* Now release the ref taken above.
13781378
*/
1379-
if (refcount_dec_and_test(&ctx->refcount))
1379+
if (refcount_dec_and_test(&ctx->refcount)) {
1380+
/* sk_destruct ran after tls_device_down took a ref, and
1381+
* it returned early. Complete the destruction here.
1382+
*/
1383+
list_del(&ctx->list);
13801384
tls_device_free_ctx(ctx);
1385+
}
13811386
}
13821387

13831388
up_write(&device_offload_lock);

0 commit comments

Comments
 (0)