linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib/zlib: fix inflating zlib streams on s390
@ 2020-12-15 15:55 Ilya Leoshkevich
  2020-12-15 18:52 ` Christian Borntraeger
  2020-12-16 15:51 ` Zaslonko Mikhail
  0 siblings, 2 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2020-12-15 15:55 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Heiko Carstens, Vasily Gorbik, Mikhail Zaslonko, linux-kernel,
	linux-s390, Ilya Leoshkevich

Decompressing zlib streams on s390 fails with "incorrect data check"
error.

Userspace zlib checks inflate_state.flags in order to byteswap checksums
only for zlib streams, and s390 hardware inflate code, which was ported
from there, tries to match this behavior. At the same time, kernel zlib
does not use inflate_state.flags, so it contains essentially random
values. For many use cases either zlib stream is zeroed out or checksum
is not used, so this problem is masked, but at least SquashFS is still
affected.

Fix by always passing a checksum to and from the hardware as is, which
matches zlib_inflate()'s expectations.

Fixes: 126196100063 ("lib/zlib: add s390 hardware support for kernel zlib_inflate")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 lib/zlib_dfltcc/dfltcc_inflate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/zlib_dfltcc/dfltcc_inflate.c b/lib/zlib_dfltcc/dfltcc_inflate.c
index db107016d29b..fb60b5a6a1cb 100644
--- a/lib/zlib_dfltcc/dfltcc_inflate.c
+++ b/lib/zlib_dfltcc/dfltcc_inflate.c
@@ -125,7 +125,7 @@ dfltcc_inflate_action dfltcc_inflate(
     param->ho = (state->write - state->whave) & ((1 << HB_BITS) - 1);
     if (param->hl)
         param->nt = 0; /* Honor history for the first block */
-    param->cv = state->flags ? REVERSE(state->check) : state->check;
+    param->cv = state->check;
 
     /* Inflate */
     do {
@@ -138,7 +138,7 @@ dfltcc_inflate_action dfltcc_inflate(
     state->bits = param->sbb;
     state->whave = param->hl;
     state->write = (param->ho + param->hl) & ((1 << HB_BITS) - 1);
-    state->check = state->flags ? REVERSE(param->cv) : param->cv;
+    state->check = param->cv;
     if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
         /* Report an error if stream is corrupted */
         state->mode = BAD;
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib/zlib: fix inflating zlib streams on s390
  2020-12-15 15:55 [PATCH] lib/zlib: fix inflating zlib streams on s390 Ilya Leoshkevich
@ 2020-12-15 18:52 ` Christian Borntraeger
  2020-12-16 15:51 ` Zaslonko Mikhail
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Borntraeger @ 2020-12-15 18:52 UTC (permalink / raw)
  To: Ilya Leoshkevich, Andrew Morton
  Cc: Heiko Carstens, Vasily Gorbik, Mikhail Zaslonko, linux-kernel,
	linux-s390

On 15.12.20 16:55, Ilya Leoshkevich wrote:
> Decompressing zlib streams on s390 fails with "incorrect data check"
> error.
> 
> Userspace zlib checks inflate_state.flags in order to byteswap checksums
> only for zlib streams, and s390 hardware inflate code, which was ported
> from there, tries to match this behavior. At the same time, kernel zlib
> does not use inflate_state.flags, so it contains essentially random
> values. For many use cases either zlib stream is zeroed out or checksum
> is not used, so this problem is masked, but at least SquashFS is still
> affected.
> 
> Fix by always passing a checksum to and from the hardware as is, which
> matches zlib_inflate()'s expectations.
> 
> Fixes: 126196100063 ("lib/zlib: add s390 hardware support for kernel zlib_inflate")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

With a zlib compressed squashfs:

Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>

We should add

Cc: <stable@vger.kernel.org> # 5.6

> ---
>  lib/zlib_dfltcc/dfltcc_inflate.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/zlib_dfltcc/dfltcc_inflate.c b/lib/zlib_dfltcc/dfltcc_inflate.c
> index db107016d29b..fb60b5a6a1cb 100644
> --- a/lib/zlib_dfltcc/dfltcc_inflate.c
> +++ b/lib/zlib_dfltcc/dfltcc_inflate.c
> @@ -125,7 +125,7 @@ dfltcc_inflate_action dfltcc_inflate(
>      param->ho = (state->write - state->whave) & ((1 << HB_BITS) - 1);
>      if (param->hl)
>          param->nt = 0; /* Honor history for the first block */
> -    param->cv = state->flags ? REVERSE(state->check) : state->check;
> +    param->cv = state->check;
>  
>      /* Inflate */
>      do {
> @@ -138,7 +138,7 @@ dfltcc_inflate_action dfltcc_inflate(
>      state->bits = param->sbb;
>      state->whave = param->hl;
>      state->write = (param->ho + param->hl) & ((1 << HB_BITS) - 1);
> -    state->check = state->flags ? REVERSE(param->cv) : param->cv;
> +    state->check = param->cv;
>      if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
>          /* Report an error if stream is corrupted */
>          state->mode = BAD;
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib/zlib: fix inflating zlib streams on s390
  2020-12-15 15:55 [PATCH] lib/zlib: fix inflating zlib streams on s390 Ilya Leoshkevich
  2020-12-15 18:52 ` Christian Borntraeger
@ 2020-12-16 15:51 ` Zaslonko Mikhail
  1 sibling, 0 replies; 3+ messages in thread
From: Zaslonko Mikhail @ 2020-12-16 15:51 UTC (permalink / raw)
  To: Ilya Leoshkevich, Andrew Morton
  Cc: Heiko Carstens, Vasily Gorbik, linux-kernel, linux-s390

Acked-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>

Please, also add:
Cc: <stable@vger.kernel.org> # 5.6

On 15.12.2020 16:55, Ilya Leoshkevich wrote:
> Decompressing zlib streams on s390 fails with "incorrect data check"
> error.
> 
> Userspace zlib checks inflate_state.flags in order to byteswap checksums
> only for zlib streams, and s390 hardware inflate code, which was ported
> from there, tries to match this behavior. At the same time, kernel zlib
> does not use inflate_state.flags, so it contains essentially random
> values. For many use cases either zlib stream is zeroed out or checksum
> is not used, so this problem is masked, but at least SquashFS is still
> affected.
> 
> Fix by always passing a checksum to and from the hardware as is, which
> matches zlib_inflate()'s expectations.
> 
> Fixes: 126196100063 ("lib/zlib: add s390 hardware support for kernel zlib_inflate")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  lib/zlib_dfltcc/dfltcc_inflate.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/zlib_dfltcc/dfltcc_inflate.c b/lib/zlib_dfltcc/dfltcc_inflate.c
> index db107016d29b..fb60b5a6a1cb 100644
> --- a/lib/zlib_dfltcc/dfltcc_inflate.c
> +++ b/lib/zlib_dfltcc/dfltcc_inflate.c
> @@ -125,7 +125,7 @@ dfltcc_inflate_action dfltcc_inflate(
>      param->ho = (state->write - state->whave) & ((1 << HB_BITS) - 1);
>      if (param->hl)
>          param->nt = 0; /* Honor history for the first block */
> -    param->cv = state->flags ? REVERSE(state->check) : state->check;
> +    param->cv = state->check;
>  
>      /* Inflate */
>      do {
> @@ -138,7 +138,7 @@ dfltcc_inflate_action dfltcc_inflate(
>      state->bits = param->sbb;
>      state->whave = param->hl;
>      state->write = (param->ho + param->hl) & ((1 << HB_BITS) - 1);
> -    state->check = state->flags ? REVERSE(param->cv) : param->cv;
> +    state->check = param->cv;
>      if (cc == DFLTCC_CC_OP2_CORRUPT && param->oesc != 0) {
>          /* Report an error if stream is corrupted */
>          state->mode = BAD;
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-16 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 15:55 [PATCH] lib/zlib: fix inflating zlib streams on s390 Ilya Leoshkevich
2020-12-15 18:52 ` Christian Borntraeger
2020-12-16 15:51 ` Zaslonko Mikhail

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).