Skip to content

Commit 9979c6e

Browse files
0x7f454c46herbertx
authored andcommitted
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>
1 parent fa3b356 commit 9979c6e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crypto/cipher.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,15 @@ struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher)
101101
if (alg->cra_init)
102102
return ERR_PTR(-ENOSYS);
103103

104+
if (unlikely(!crypto_mod_get(alg)))
105+
return ERR_PTR(-ESTALE);
106+
104107
ntfm = __crypto_alloc_tfmgfp(alg, CRYPTO_ALG_TYPE_CIPHER,
105108
CRYPTO_ALG_TYPE_MASK, GFP_ATOMIC);
106-
if (IS_ERR(ntfm))
109+
if (IS_ERR(ntfm)) {
110+
crypto_mod_put(alg);
107111
return ERR_CAST(ntfm);
112+
}
108113

109114
ntfm->crt_flags = tfm->crt_flags;
110115

0 commit comments

Comments
 (0)