diff options
author | 2025-05-04 21:33:18 +0800 | |
---|---|---|
committer | 2025-05-05 18:20:46 +0800 | |
commit | fd66f2ab09b8305006764887cc47eeeb1ca5704b (patch) | |
tree | 561176bbdbf148fe4eaa751e4b4812fcac9d7009 | |
parent | crypto: shash - Mark shash algorithms as REQ_VIRT (diff) | |
download | wireguard-linux-fd66f2ab09b8305006764887cc47eeeb1ca5704b.tar.xz wireguard-linux-fd66f2ab09b8305006764887cc47eeeb1ca5704b.zip |
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>
-rw-r--r-- | crypto/ahash.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/crypto/ahash.c b/crypto/ahash.c index 57c131a13067..736e9fb5d0a4 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -760,23 +760,28 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm) tfm->exit = crypto_ahash_exit_tfm; - if (!alg->init_tfm) { - if (!tfm->__crt_alg->cra_init) - return 0; - + if (alg->init_tfm) + err = alg->init_tfm(hash); + else if (tfm->__crt_alg->cra_init) err = tfm->__crt_alg->cra_init(tfm); - if (err) - goto out_free_sync_hash; - + else return 0; - } - err = alg->init_tfm(hash); if (err) goto out_free_sync_hash; + if (!ahash_is_async(hash) && crypto_ahash_reqsize(hash) > + MAX_SYNC_HASH_REQSIZE) + goto out_exit_tfm; + 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: crypto_free_ahash(fb); 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) 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; |