From: Dmitry Safonov Date: Wed, 14 Jun 2023 17:46:43 +0000 (+0100) Subject: crypto: cipher - On clone do crypto_mod_get() X-Git-Tag: v6.6.7~2481^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9979c6e55d2b54ed6e0ce69b6f7faa7889549402;p=platform%2Fkernel%2Flinux-starfive.git 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 Signed-off-by: Herbert Xu --- diff --git a/crypto/cipher.c b/crypto/cipher.c index a5a8803..47c77a3 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;