Skip to content

Commit c636019

Browse files
Eric Biggersopsiff
authored andcommitted
crypto: s390/sha - Fix uninitialized variable in SHA-1 and SHA-2
commit 68279380266a5fa70e664de754503338e2ec3f43 upstream. Commit 88c02b3 ("s390/sha3: Support sha3 performance enhancements") added the field s390_sha_ctx::first_message_part and made it be used by s390_sha_update() (now s390_sha_update_blocks()). At the time, s390_sha_update() was used by all the s390 SHA-1, SHA-2, and SHA-3 algorithms. However, only the initialization functions for SHA-3 were updated, leaving SHA-1 and SHA-2 using first_message_part uninitialized. This could cause e.g. the function code CPACF_KIMD_SHA_512 | CPACF_KIMD_NIP to be used instead of just CPACF_KIMD_SHA_512. This apparently was harmless, as the SHA-1 and SHA-2 function codes ignore CPACF_KIMD_NIP; it is recognized only by the SHA-3 function codes (https://lore.kernel.org/r/[email protected]/). Therefore, this bug was found only when first_message_part was later converted to a boolean and UBSAN detected its uninitialized use. Regardless, let's fix this by just initializing to zero. Note: in 6.16, we need to patch SHA-1, SHA-384, and SHA-512. In 6.15 and earlier, we'll also need to patch SHA-224 and SHA-256, as they hadn't yet been librarified (which incidentally fixed this bug). Fixes: 88c02b3 ("s390/sha3: Support sha3 performance enhancements") Cc: [email protected] Reported-by: Ingo Franzki <[email protected]> Closes: https://lore.kernel.org/r/[email protected] Acked-by: Heiko Carstens <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 56ea7746045a1c90b424cc6578b4eead30621878)
1 parent b4f2933 commit c636019

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

arch/s390/crypto/sha1_s390.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static int s390_sha1_init(struct shash_desc *desc)
3838
sctx->state[4] = SHA1_H4;
3939
sctx->count = 0;
4040
sctx->func = CPACF_KIMD_SHA_1;
41+
sctx->first_message_part = 0;
4142

4243
return 0;
4344
}
@@ -62,6 +63,7 @@ static int s390_sha1_import(struct shash_desc *desc, const void *in)
6263
memcpy(sctx->state, ictx->state, sizeof(ictx->state));
6364
memcpy(sctx->buf, ictx->buffer, sizeof(ictx->buffer));
6465
sctx->func = CPACF_KIMD_SHA_1;
66+
sctx->first_message_part = 0;
6567
return 0;
6668
}
6769

arch/s390/crypto/sha256_s390.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static int s390_sha256_init(struct shash_desc *desc)
3131
sctx->state[7] = SHA256_H7;
3232
sctx->count = 0;
3333
sctx->func = CPACF_KIMD_SHA_256;
34+
sctx->first_message_part = 0;
3435

3536
return 0;
3637
}
@@ -55,6 +56,7 @@ static int sha256_import(struct shash_desc *desc, const void *in)
5556
memcpy(sctx->state, ictx->state, sizeof(ictx->state));
5657
memcpy(sctx->buf, ictx->buf, sizeof(ictx->buf));
5758
sctx->func = CPACF_KIMD_SHA_256;
59+
sctx->first_message_part = 0;
5860
return 0;
5961
}
6062

@@ -90,6 +92,7 @@ static int s390_sha224_init(struct shash_desc *desc)
9092
sctx->state[7] = SHA224_H7;
9193
sctx->count = 0;
9294
sctx->func = CPACF_KIMD_SHA_256;
95+
sctx->first_message_part = 0;
9396

9497
return 0;
9598
}

arch/s390/crypto/sha512_s390.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static int sha512_init(struct shash_desc *desc)
3232
*(__u64 *)&ctx->state[14] = SHA512_H7;
3333
ctx->count = 0;
3434
ctx->func = CPACF_KIMD_SHA_512;
35+
ctx->first_message_part = 0;
3536

3637
return 0;
3738
}
@@ -60,6 +61,7 @@ static int sha512_import(struct shash_desc *desc, const void *in)
6061
memcpy(sctx->state, ictx->state, sizeof(ictx->state));
6162
memcpy(sctx->buf, ictx->buf, sizeof(ictx->buf));
6263
sctx->func = CPACF_KIMD_SHA_512;
64+
sctx->first_message_part = 0;
6365
return 0;
6466
}
6567

@@ -97,6 +99,7 @@ static int sha384_init(struct shash_desc *desc)
9799
*(__u64 *)&ctx->state[14] = SHA384_H7;
98100
ctx->count = 0;
99101
ctx->func = CPACF_KIMD_SHA_512;
102+
ctx->first_message_part = 0;
100103

101104
return 0;
102105
}

0 commit comments

Comments
 (0)