Skip to contentSkip to conversation

lib/zlib: fix inflating zlib streams on s390

PATCH Applied Ilya Leoshkevich 3 participants 3 messages Dec 15, 2020 – Dec 16, 2020 s390

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/zlib: fix inflating zlib streams on s390

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")
---
 lib/zlib_dfltcc/dfltcc_inflate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/zlib_dfltcc/dfltcc_inflate.c +2 -2
index db107016d29b..fb60b5a6a1cb 100644
@@ -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;
Signature · 1 line
2.25.4
Tested-by Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · 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.

Quoted 5 lines

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")

With a zlib compressed squashfs:

We should add

Quoted 27 lines
---
 lib/zlib_dfltcc/dfltcc_inflate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/zlib_dfltcc/dfltcc_inflate.c +2 -2
index db107016d29b..fb60b5a6a1cb 100644
@@ -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;
Acked-by on v1 1/1
#2 lore raw
In reply to Ilya Leoshkevich

Please, also add:
Cc: <[email protected]> # 5.6

Quoted 43 lines · 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")
---
 lib/zlib_dfltcc/dfltcc_inflate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/zlib_dfltcc/dfltcc_inflate.c +2 -2
index db107016d29b..fb60b5a6a1cb 100644
@@ -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;