Re: [PATCH v2] crypto: zstd - fix segmented acomp streaming paths
From: Herbert Xu
Date: Sun May 03 2026 - 23:40:34 EST
On Fri, Mar 20, 2026 at 03:51:24PM -0600, Wesley Atwell wrote:
> The zstd acomp implementation does not correctly handle segmented
> source and destination walks.
>
> The compression path advances the destination walk by the full
> segment length rather than the bytes actually produced, and it only
> calls zstd_end_stream() once even though the streaming API requires it
> to be called until it returns 0. With segmented destinations this can
> leave buffered output behind and misaccount the walk progress.
>
> The decompression path has the same destination accounting issue, and
> it stops when the source walk is exhausted even if
> zstd_decompress_stream() has not yet reported that the frame is fully
> decoded and flushed. That can report success too early for segmented
> requests and incomplete frames.
>
> Fix both streaming paths by advancing destination segments by actual
> output bytes, refilling destination segments as needed, draining
> zstd_end_stream() until completion, and continuing to flush buffered
> decompression output after the source walk is exhausted. Return
> -EINVAL if decompression cannot finish once the input has been fully
> consumed.
>
> Fixes: f5ad93ffb541 ("crypto: zstd - convert to acomp")
> Assisted-by: Codex:GPT-5
> Signed-off-by: Wesley Atwell <atwellwea@xxxxxxxxx>
> ---
> Changes in v2:
> - always finalize acomp walk mappings in the direct one-shot paths
> - add mapped src/dst cleanup on streaming error exits
> - reacquire a destination segment in decompression before resuming after a
> full output-chunk completion
>
> Local validation:
> - built bzImage with CONFIG_CRYPTO_SELFTESTS=y and
> CONFIG_CRYPTO_SELFTESTS_FULL=y
> - exercised segmented zstd acomp requests using temporary local testmgr
> scaffolding
> - booted under virtme and verified zstd-generic selftest passed in
> /proc/crypto
Thanks for the patch. But please redo this as a series of incremental
patches, each of which fixing a specific problem so that it is
more amenable to review.
Cheers,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt