* [PATCH] crypto: deflate - fix decompression window size
@ 2026-03-24 18:08 Giovanni Cabiddu
2026-03-26 8:44 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Giovanni Cabiddu @ 2026-03-24 18:08 UTC (permalink / raw)
To: herbert; +Cc: linux-crypto, qat-linux, Giovanni Cabiddu, Laurent M Coquerel
deflate_decompress() initializes the inflate stream with windowBits set
to -DEFLATE_DEF_WINBITS (11 bits, 2KB window). Valid raw DEFLATE streams
allow window sizes up to MAX_WBITS (15 bits, 32KB). Using a smaller
window than the one used during compression causes decompression to fail
for externally generated data. This might occur if data is compressed
with a compressor that is not deflate-generic (i.e. this
implementation).
Use -MAX_WBITS when calling zlib_inflateInit2() to accept all valid raw
DEFLATE streams. The inflate workspace allocated in deflate_alloc_stream()
is already sized using zlib_inflate_workspacesize(), which accounts for
the maximum window size, so no allocation change is needed.
Fixes: 08cabc7d3c86 ("crypto: deflate - Convert to acomp")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Laurent M Coquerel <laurent.m.coquerel@intel.com>
---
crypto/deflate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crypto/deflate.c b/crypto/deflate.c
index 46fc7def8d4c..d347e506e6c3 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -203,7 +203,7 @@ static int deflate_decompress(struct acomp_req *req)
s = crypto_acomp_lock_stream_bh(&deflate_streams);
ds = s->ctx;
- err = zlib_inflateInit2(&ds->stream, -DEFLATE_DEF_WINBITS);
+ err = zlib_inflateInit2(&ds->stream, -MAX_WBITS);
if (err != Z_OK) {
err = -EINVAL;
goto out;
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] crypto: deflate - fix decompression window size
2026-03-24 18:08 [PATCH] crypto: deflate - fix decompression window size Giovanni Cabiddu
@ 2026-03-26 8:44 ` Herbert Xu
2026-03-26 9:36 ` Giovanni Cabiddu
0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2026-03-26 8:44 UTC (permalink / raw)
To: Giovanni Cabiddu; +Cc: linux-crypto, qat-linux, Laurent M Coquerel
On Tue, Mar 24, 2026 at 06:08:58PM +0000, Giovanni Cabiddu wrote:
> deflate_decompress() initializes the inflate stream with windowBits set
> to -DEFLATE_DEF_WINBITS (11 bits, 2KB window). Valid raw DEFLATE streams
> allow window sizes up to MAX_WBITS (15 bits, 32KB). Using a smaller
> window than the one used during compression causes decompression to fail
> for externally generated data. This might occur if data is compressed
> with a compressor that is not deflate-generic (i.e. this
> implementation).
>
> Use -MAX_WBITS when calling zlib_inflateInit2() to accept all valid raw
> DEFLATE streams. The inflate workspace allocated in deflate_alloc_stream()
> is already sized using zlib_inflate_workspacesize(), which accounts for
> the maximum window size, so no allocation change is needed.
>
> Fixes: 08cabc7d3c86 ("crypto: deflate - Convert to acomp")
That commit doesn't touch this at all. I think you meant
commit 62a465c25e99b9a98259a6b7f5bb759f5296d501
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date: Wed Aug 30 17:56:25 2023 +0800
crypto: deflate - Remove zlib-deflate
But this simply restored the status quo prior to
commit a368f43d6e3a001e684e9191a27df384fbff12f5
Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Date: Fri Apr 21 21:54:30 2017 +0100
crypto: scomp - add support for deflate rfc1950 (zlib)
So the commit message needs to be rewritten to clearly state
why this is needed for the "deflate" algorithm.
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] crypto: deflate - fix decompression window size
2026-03-26 8:44 ` Herbert Xu
@ 2026-03-26 9:36 ` Giovanni Cabiddu
0 siblings, 0 replies; 3+ messages in thread
From: Giovanni Cabiddu @ 2026-03-26 9:36 UTC (permalink / raw)
To: Herbert Xu; +Cc: linux-crypto, qat-linux, Laurent M Coquerel
On Thu, Mar 26, 2026 at 05:44:03PM +0900, Herbert Xu wrote:
> On Tue, Mar 24, 2026 at 06:08:58PM +0000, Giovanni Cabiddu wrote:
> > deflate_decompress() initializes the inflate stream with windowBits set
> > to -DEFLATE_DEF_WINBITS (11 bits, 2KB window). Valid raw DEFLATE streams
> > allow window sizes up to MAX_WBITS (15 bits, 32KB). Using a smaller
> > window than the one used during compression causes decompression to fail
> > for externally generated data. This might occur if data is compressed
> > with a compressor that is not deflate-generic (i.e. this
> > implementation).
> >
> > Use -MAX_WBITS when calling zlib_inflateInit2() to accept all valid raw
> > DEFLATE streams. The inflate workspace allocated in deflate_alloc_stream()
> > is already sized using zlib_inflate_workspacesize(), which accounts for
> > the maximum window size, so no allocation change is needed.
> >
> > Fixes: 08cabc7d3c86 ("crypto: deflate - Convert to acomp")
>
> That commit doesn't touch this at all. I think you meant
>
> commit 62a465c25e99b9a98259a6b7f5bb759f5296d501
> Author: Herbert Xu <herbert@gondor.apana.org.au>
> Date: Wed Aug 30 17:56:25 2023 +0800
>
> crypto: deflate - Remove zlib-deflate
>
> But this simply restored the status quo prior to
>
> commit a368f43d6e3a001e684e9191a27df384fbff12f5
> Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
> Date: Fri Apr 21 21:54:30 2017 +0100
>
> crypto: scomp - add support for deflate rfc1950 (zlib)
>
> So the commit message needs to be rewritten to clearly state
> why this is needed for the "deflate" algorithm.
My bad. Sorry about that.
I think the Fixes tag should report either the commit that introduced
deflate-scomp
commit f6ded09de8bdaa405ab90b1b6c4166e69a23664d
Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Date: Fri Oct 21 13:19:53 2016 +0100
crypto: acomp - add support for deflate via scomp
OR the one that introduced deflate...
commit 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (tag: v2.6.12-rc2)
Author: Linus Torvalds <torvalds@ppc970.osdl.org>
Date: Sat Apr 16 15:20:36 2005 -0700
Linux-2.6.12-rc2
What do you think?
The motivation for this change is that data compressed with a history
window larger than 2 KB (for example, by QAT or IAA) might not be
decompressed by deflate-generic, which currently initializes the inflate
stream with a 2 KB window.
I'll rework the commit message to make this explicit and resubmit.
Regards,
--
Giovanni
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-26 9:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-24 18:08 [PATCH] crypto: deflate - fix decompression window size Giovanni Cabiddu
2026-03-26 8:44 ` Herbert Xu
2026-03-26 9:36 ` Giovanni Cabiddu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox