diff options
author | Sabrina Dubroca <sd@queasysnail.net> | 2023-08-25 23:35:16 +0200 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2023-08-28 02:17:42 +0200 |
commit | d2322cf5ed59f084ac86d9339f7c3acccd177bfd (patch) | |
tree | 605ac75069f478a66aea9b766a1aadd6b0f41694 /net/tls | |
parent | tls: expand use of tls_cipher_desc in tls_set_device_offload (diff) | |
download | linux-d2322cf5ed59f084ac86d9339f7c3acccd177bfd.tar.xz linux-d2322cf5ed59f084ac86d9339f7c3acccd177bfd.zip |
tls: allocate the fallback aead after checking that the cipher is valid
No need to allocate the aead if we're going to fail afterwards.
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Link: https://lore.kernel.org/r/335e32511ed55a0b30f3f81a78fa8f323b3bdf8f.1692977948.git.sd@queasysnail.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/tls')
-rw-r--r-- | net/tls/tls_device_fallback.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c index cb224fb2a394..4de9061f38f5 100644 --- a/net/tls/tls_device_fallback.c +++ b/net/tls/tls_device_fallback.c @@ -475,15 +475,6 @@ int tls_sw_fallback_init(struct sock *sk, const u8 *key; int rc; - offload_ctx->aead_send = - crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC); - if (IS_ERR(offload_ctx->aead_send)) { - rc = PTR_ERR(offload_ctx->aead_send); - pr_err_ratelimited("crypto_alloc_aead failed rc=%d\n", rc); - offload_ctx->aead_send = NULL; - goto err_out; - } - switch (crypto_info->cipher_type) { case TLS_CIPHER_AES_GCM_128: key = ((struct tls12_crypto_info_aes_gcm_128 *)crypto_info)->key; @@ -493,10 +484,19 @@ int tls_sw_fallback_init(struct sock *sk, break; default: rc = -EINVAL; - goto free_aead; + goto err_out; } cipher_desc = get_cipher_desc(crypto_info->cipher_type); + offload_ctx->aead_send = + crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC); + if (IS_ERR(offload_ctx->aead_send)) { + rc = PTR_ERR(offload_ctx->aead_send); + pr_err_ratelimited("crypto_alloc_aead failed rc=%d\n", rc); + offload_ctx->aead_send = NULL; + goto err_out; + } + rc = crypto_aead_setkey(offload_ctx->aead_send, key, cipher_desc->key); if (rc) goto free_aead; |