Skip to content

Commit

Permalink
crypto: cipher - On clone do crypto_mod_get()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Dmitry Safonov authored and Herbert Xu committed Jun 23, 2023
1 parent fa3b356 commit 9979c6e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crypto/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9979c6e

Please sign in to comment.