mirror of https://github.com/torvalds/linux.git
crypto: ahash - Enforce MAX_SYNC_HASH_REQSIZE for sync ahash
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>
This commit is contained in:
parent
f4e365d5ca
commit
fd66f2ab09
|
|
@ -760,23 +760,28 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
|
||||||
|
|
||||||
tfm->exit = crypto_ahash_exit_tfm;
|
tfm->exit = crypto_ahash_exit_tfm;
|
||||||
|
|
||||||
if (!alg->init_tfm) {
|
if (alg->init_tfm)
|
||||||
if (!tfm->__crt_alg->cra_init)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err = tfm->__crt_alg->cra_init(tfm);
|
|
||||||
if (err)
|
|
||||||
goto out_free_sync_hash;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = alg->init_tfm(hash);
|
err = alg->init_tfm(hash);
|
||||||
|
else if (tfm->__crt_alg->cra_init)
|
||||||
|
err = tfm->__crt_alg->cra_init(tfm);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
goto out_free_sync_hash;
|
goto out_free_sync_hash;
|
||||||
|
|
||||||
|
if (!ahash_is_async(hash) && crypto_ahash_reqsize(hash) >
|
||||||
|
MAX_SYNC_HASH_REQSIZE)
|
||||||
|
goto out_exit_tfm;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out_exit_tfm:
|
||||||
|
if (alg->exit_tfm)
|
||||||
|
alg->exit_tfm(hash);
|
||||||
|
else if (tfm->__crt_alg->cra_exit)
|
||||||
|
tfm->__crt_alg->cra_exit(tfm);
|
||||||
|
err = -EINVAL;
|
||||||
out_free_sync_hash:
|
out_free_sync_hash:
|
||||||
crypto_free_ahash(fb);
|
crypto_free_ahash(fb);
|
||||||
return err;
|
return err;
|
||||||
|
|
@ -954,6 +959,10 @@ static int ahash_prepare_alg(struct ahash_alg *alg)
|
||||||
if (base->cra_reqsize && base->cra_reqsize < alg->halg.statesize)
|
if (base->cra_reqsize && base->cra_reqsize < alg->halg.statesize)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (!(base->cra_flags & CRYPTO_ALG_ASYNC) &&
|
||||||
|
base->cra_reqsize > MAX_SYNC_HASH_REQSIZE)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
err = hash_prepare_alg(&alg->halg);
|
err = hash_prepare_alg(&alg->halg);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue