summaryrefslogtreecommitdiffstats
path: root/crypto/cipher.c
diff options
context:
space:
mode:
authorDmitry Safonov <dima@arista.com>2023-06-14 19:46:43 +0200
committerHerbert Xu <herbert@gondor.apana.org.au>2023-06-23 10:15:36 +0200
commit9979c6e55d2b54ed6e0ce69b6f7faa7889549402 (patch)
treedc1b6ca9dccd0bfde7199e372af0e34dca083616 /crypto/cipher.c
parentcrypto: api - Add __crypto_alloc_tfmgfp (diff)
downloadlinux-9979c6e55d2b54ed6e0ce69b6f7faa7889549402.tar.xz
linux-9979c6e55d2b54ed6e0ce69b6f7faa7889549402.zip
crypto: cipher - On clone do crypto_mod_get()
The refcounter of underlying algorithm should be incremented, otherwise it'll be destroyed with the cloned cipher, wrecking the original cipher. Signed-off-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/cipher.c')
-rw-r--r--crypto/cipher.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/crypto/cipher.c b/crypto/cipher.c
index a5a88038f0d6..47c77a3e5978 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -101,10 +101,15 @@ struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher)
if (alg->cra_init)
return ERR_PTR(-ENOSYS);
+ if (unlikely(!crypto_mod_get(alg)))
+ return ERR_PTR(-ESTALE);
+
ntfm = __crypto_alloc_tfmgfp(alg, CRYPTO_ALG_TYPE_CIPHER,
CRYPTO_ALG_TYPE_MASK, GFP_ATOMIC);
- if (IS_ERR(ntfm))
+ if (IS_ERR(ntfm)) {
+ crypto_mod_put(alg);
return ERR_CAST(ntfm);
+ }
ntfm->crt_flags = tfm->crt_flags;