Re: [PATCH] crypto: scomp - Bound the single-page source scratch buffer
From: Herbert Xu
Date: Fri Dec 04 2026 - 00:43:47 EST
Fang Xieyan <fangxy@xxxxxxxxxxxx> wrote:
>
> diff --git a/crypto/scompress.c b/crypto/scompress.c
> index de54227203ce..02438d8f1751 100644
> --- a/crypto/scompress.c
> +++ b/crypto/scompress.c
> @@ -232,8 +232,16 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
> struct crypto_acomp_stream *stream = crypto_acomp_lock_stream_bh(&crypto_scomp_alg(scomp)->streams);
>
> if (!src_isvirt && !src) {
> - struct scomp_scratch *scratch = scomp_lock_scratch();
> - const u8 *src = scratch->src;
> + struct scomp_scratch *scratch;
> + const u8 *src;
> +
> + if (slen > PAGE_SIZE) {
> + ret = -EINVAL;
> + goto out;
> + }
> +
> + scratch = scomp_lock_scratch();
> + src = scratch->src;
>
> memcpy_from_sglist(scratch->src, req->src, 0, slen);
Good catch!
But the contract is that all callers should have slen <= PAGE_SIZE.
So please express that at the top of the function:
if (!req->src || !slen)
return -EINVAL;
if (slen > PAGE_SIZE)
return -ENOSYS;
BTW, did you identify any callers with either virt or SG sources
greater than PAGE_SIZE when performing decompression?
Thanks,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt