Skip to content

Commit dd64572

Browse files
gal-pressmanSaeed Mahameed
authored andcommitted
net/mlx5e: kTLS, Fix missing error unwind on unsupported cipher type
Do proper error unwinding when adding an unsupported TX/RX cipher type. Move the switch case prior to key creation so there's less to unwind, and change the goto label name to describe the action performed instead of what failed. Fixes: 4960c41 ("net/mlx5e: Support 256 bit keys with kTLS device offload") Signed-off-by: Gal Pressman <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent c9668f0 commit dd64572

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,6 @@ int mlx5e_ktls_add_rx(struct net_device *netdev, struct sock *sk,
621621
if (unlikely(!priv_rx))
622622
return -ENOMEM;
623623

624-
dek = mlx5_ktls_create_key(priv->tls->dek_pool, crypto_info);
625-
if (IS_ERR(dek)) {
626-
err = PTR_ERR(dek);
627-
goto err_create_key;
628-
}
629-
priv_rx->dek = dek;
630-
631-
INIT_LIST_HEAD(&priv_rx->list);
632-
spin_lock_init(&priv_rx->lock);
633624
switch (crypto_info->cipher_type) {
634625
case TLS_CIPHER_AES_GCM_128:
635626
priv_rx->crypto_info.crypto_info_128 =
@@ -642,9 +633,20 @@ int mlx5e_ktls_add_rx(struct net_device *netdev, struct sock *sk,
642633
default:
643634
WARN_ONCE(1, "Unsupported cipher type %u\n",
644635
crypto_info->cipher_type);
645-
return -EOPNOTSUPP;
636+
err = -EOPNOTSUPP;
637+
goto err_cipher_type;
646638
}
647639

640+
dek = mlx5_ktls_create_key(priv->tls->dek_pool, crypto_info);
641+
if (IS_ERR(dek)) {
642+
err = PTR_ERR(dek);
643+
goto err_cipher_type;
644+
}
645+
priv_rx->dek = dek;
646+
647+
INIT_LIST_HEAD(&priv_rx->list);
648+
spin_lock_init(&priv_rx->lock);
649+
648650
rxq = mlx5e_ktls_sk_get_rxq(sk);
649651
priv_rx->rxq = rxq;
650652
priv_rx->sk = sk;
@@ -677,7 +679,7 @@ int mlx5e_ktls_add_rx(struct net_device *netdev, struct sock *sk,
677679
mlx5e_tir_destroy(&priv_rx->tir);
678680
err_create_tir:
679681
mlx5_ktls_destroy_key(priv->tls->dek_pool, priv_rx->dek);
680-
err_create_key:
682+
err_cipher_type:
681683
kfree(priv_rx);
682684
return err;
683685
}

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,6 @@ int mlx5e_ktls_add_tx(struct net_device *netdev, struct sock *sk,
469469
if (IS_ERR(priv_tx))
470470
return PTR_ERR(priv_tx);
471471

472-
dek = mlx5_ktls_create_key(priv->tls->dek_pool, crypto_info);
473-
if (IS_ERR(dek)) {
474-
err = PTR_ERR(dek);
475-
goto err_create_key;
476-
}
477-
priv_tx->dek = dek;
478-
479-
priv_tx->expected_seq = start_offload_tcp_sn;
480472
switch (crypto_info->cipher_type) {
481473
case TLS_CIPHER_AES_GCM_128:
482474
priv_tx->crypto_info.crypto_info_128 =
@@ -489,8 +481,18 @@ int mlx5e_ktls_add_tx(struct net_device *netdev, struct sock *sk,
489481
default:
490482
WARN_ONCE(1, "Unsupported cipher type %u\n",
491483
crypto_info->cipher_type);
492-
return -EOPNOTSUPP;
484+
err = -EOPNOTSUPP;
485+
goto err_pool_push;
493486
}
487+
488+
dek = mlx5_ktls_create_key(priv->tls->dek_pool, crypto_info);
489+
if (IS_ERR(dek)) {
490+
err = PTR_ERR(dek);
491+
goto err_pool_push;
492+
}
493+
494+
priv_tx->dek = dek;
495+
priv_tx->expected_seq = start_offload_tcp_sn;
494496
priv_tx->tx_ctx = tls_offload_ctx_tx(tls_ctx);
495497

496498
mlx5e_set_ktls_tx_priv_ctx(tls_ctx, priv_tx);
@@ -500,7 +502,7 @@ int mlx5e_ktls_add_tx(struct net_device *netdev, struct sock *sk,
500502

501503
return 0;
502504

503-
err_create_key:
505+
err_pool_push:
504506
pool_push(pool, priv_tx);
505507
return err;
506508
}

0 commit comments

Comments
 (0)