Skip to content

Commit

Permalink
tls: Fix context leak on tls_device_down
Browse files Browse the repository at this point in the history
[ Upstream commit 3740651 ]

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 <maximmi@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://lore.kernel.org/r/20220512091830.678684-1-maximmi@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
nvmmax authored and gregkh committed May 18, 2022
1 parent 161c4ed commit fccf4bf
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions net/tls/tls_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,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);
Expand Down

0 comments on commit fccf4bf

Please sign in to comment.