Skip to content

Commit 025cc2f

Browse files
Maxim Mikityanskiykuba-moo
authored andcommitted
net/tls: Protect from calling tls_dev_del for TLS RX twice
tls_device_offload_cleanup_rx doesn't clear tls_ctx->netdev after calling tls_dev_del if TLX TX offload is also enabled. Clearing tls_ctx->netdev gets postponed until tls_device_gc_task. It leaves a time frame when tls_device_down may get called and call tls_dev_del for RX one extra time, confusing the driver, which may lead to a crash. This patch corrects this racy behavior by adding a flag to prevent tls_device_down from calling tls_dev_del the second time. Fixes: e8f6979 ("net/tls: Add generic NIC offload infrastructure") Signed-off-by: Maxim Mikityanskiy <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a060133 commit 025cc2f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/net/tls.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ enum tls_context_flags {
199199
* to be atomic.
200200
*/
201201
TLS_TX_SYNC_SCHED = 1,
202+
/* tls_dev_del was called for the RX side, device state was released,
203+
* but tls_ctx->netdev might still be kept, because TX-side driver
204+
* resources might not be released yet. Used to prevent the second
205+
* tls_dev_del call in tls_device_down if it happens simultaneously.
206+
*/
207+
TLS_RX_DEV_CLOSED = 2,
202208
};
203209

204210
struct cipher_context {

net/tls/tls_device.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,8 @@ void tls_device_offload_cleanup_rx(struct sock *sk)
12621262
if (tls_ctx->tx_conf != TLS_HW) {
12631263
dev_put(netdev);
12641264
tls_ctx->netdev = NULL;
1265+
} else {
1266+
set_bit(TLS_RX_DEV_CLOSED, &tls_ctx->flags);
12651267
}
12661268
out:
12671269
up_read(&device_offload_lock);
@@ -1291,7 +1293,8 @@ static int tls_device_down(struct net_device *netdev)
12911293
if (ctx->tx_conf == TLS_HW)
12921294
netdev->tlsdev_ops->tls_dev_del(netdev, ctx,
12931295
TLS_OFFLOAD_CTX_DIR_TX);
1294-
if (ctx->rx_conf == TLS_HW)
1296+
if (ctx->rx_conf == TLS_HW &&
1297+
!test_bit(TLS_RX_DEV_CLOSED, &ctx->flags))
12951298
netdev->tlsdev_ops->tls_dev_del(netdev, ctx,
12961299
TLS_OFFLOAD_CTX_DIR_RX);
12971300
WRITE_ONCE(ctx->netdev, NULL);

0 commit comments

Comments
 (0)