@@ -768,6 +768,14 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
if (err)
goto out_free_sync_hash;
+ if (!ahash_is_async(hash) && crypto_ahash_reqsize(hash) >
+ MAX_SYNC_HASH_REQSIZE) {
+ if (tfm->__crt_alg->cra_exit)
+ tfm->__crt_alg->cra_exit(tfm);
+ err = -EINVAL;
+ goto out_free_sync_hash;
+ }
+
return 0;
}
@@ -775,6 +783,14 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
if (err)
goto out_free_sync_hash;
+ if (!ahash_is_async(hash) && crypto_ahash_reqsize(hash) >
+ MAX_SYNC_HASH_REQSIZE) {
+ if (alg->exit_tfm)
+ alg->exit_tfm(hash);
+ err = -EINVAL;
+ goto out_free_sync_hash;
+ }
+
return 0;
out_free_sync_hash:
@@ -954,6 +970,10 @@ static int ahash_prepare_alg(struct ahash_alg *alg)
if (base->cra_reqsize && base->cra_reqsize < alg->halg.statesize)
return -EINVAL;
+ if (!(base->cra_flags & CRYPTO_ALG_ASYNC) &&
+ base->cra_reqsize > MAX_SYNC_HASH_REQSIZE)
+ return -EINVAL;
+
err = hash_prepare_alg(&alg->halg);
if (err)
return err;
As sync ahash algorithms (currently there are none) are used without a fallback, ensure that they obey the MAX_SYNC_HASH_REQSIZE rule just like shash algorithms. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> --- crypto/ahash.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)