[PATCH] crypto: acomp - Enforce MAX_SYNC_COMP_REQSIZE in init_tfm
From: Herbert Xu
Date: Tue Oct 13 2026 - 05:50:16 EST
On Fri, Oct 09, 2026 at 09:30:31AM -0700, Usama Arif wrote:
>
> diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h
> index 5d5358dfab734..12c1ce1f6243b 100644
> --- a/include/crypto/acompress.h
> +++ b/include/crypto/acompress.h
> @@ -203,6 +203,19 @@ static inline bool acomp_is_async(struct crypto_acomp *tfm)
> CRYPTO_ALG_ASYNC;
> }
>
> +/**
> + * acomp_can_use_stack_req() - check whether a transform can use stack requests
> + * @tfm: ACOMPRESS transform
> + *
> + * Return: true if @tfm completes synchronously and its request context fits
> + * in the storage reserved by ACOMP_REQUEST_ON_STACK(), false otherwise.
> + */
> +static inline bool acomp_can_use_stack_req(struct crypto_acomp *tfm)
> +{
> + return !acomp_is_async(tfm) &&
> + crypto_acomp_reqsize(tfm) <= MAX_SYNC_COMP_REQSIZE;
I think we should enforce MAX_SYNC_COMP_REQSIZE in the Crypto API
and then you can simply test against acomp_is_async(tfm).
Feel free to include this patch in your series:
---8<---
Enforce the limit MAX_SYNC_COMP_REQSIZE when an acomp tfm is
initialised. All existing algorithms obey this limit.
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
diff --git a/crypto/acompress.c b/crypto/acompress.c
index 4de1a2ad577f..c8b4b8589769 100644
--- a/crypto/acompress.c
+++ b/crypto/acompress.c
@@ -92,10 +92,6 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
if (IS_ERR(fb))
return PTR_ERR(fb);
- err = -EINVAL;
- if (crypto_acomp_reqsize(fb) > MAX_SYNC_COMP_REQSIZE)
- goto out_free_fb;
-
tfm->fb = crypto_acomp_tfm(fb);
}
@@ -105,15 +101,19 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
acomp->base.exit = crypto_acomp_exit_tfm;
- if (!alg->init)
- return 0;
-
- err = alg->init(acomp);
- if (err)
+ if (alg->init && ((err = alg->init(acomp))))
goto out_free_fb;
+ err = -EINVAL;
+ if (!acomp_is_async(acomp) &&
+ crypto_acomp_reqsize(acomp) > MAX_SYNC_COMP_REQSIZE)
+ goto out_exit_tfm;
+
return 0;
+out_exit_tfm:
+ if (alg->exit)
+ alg->exit(acomp);
out_free_fb:
crypto_free_acomp(fb);
return err;
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt