Skip to contentSkip to conversation

s390/crypto: Generate iintermediate chaining value on export

PATCH In review Holger Dengler 5 participants 8 messages Aug 14 – Sep 19

Subsystems (3)
lore
Share & tools
lore

Holger Dengler

author maintainer
#0 lore raw

cover s390/crypto: Generate iintermediate chaining value on export

While exporting the state of the hmac chipher, the intermediate chaining value (CV) has to be calculated. Calling the KIMD instruction on s390 will generate the correct value. The code already sets the correct function code for the instruction, but it calls the wrong instruction (KLMD). The patch just fixes this.

This series applies on top of Linus' master branch.

Holger Dengler (1):
s390/crypto: Generate intermediate CV for API partial block handling

 arch/s390/crypto/hmac_s390.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

base-commit: 2f1baf1fc8929e6c48370be543ad028ac7ad4131

Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 1/1 s390/crypto: Generate intermediate CV for API partial block handling

The API partial block handling requires a intermediate chaining value (CV). The internal function hash_data() sets the function code correctly, so also call cpacf_kimd() instruction for intermediate CV generation, as cpacf_klmd() always generate the final hash value.

Fixes 08811169ac01 ("crypto: s390/hmac - Use API partial block handling")
---
 arch/s390/crypto/hmac_s390.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/s390/crypto/hmac_s390.c +4 -1
index f8cd09f341d4..445fa7bbd958 100644
@@ -150,7 +150,10 @@ static int hash_data(const u8 *in, unsigned int inlen,
 
 #undef PARAM_INIT
 
-	cpacf_klmd(func, &param, in, inlen);
+	if (final)
+		cpacf_klmd(func, &param, in, inlen);
+	else
+		cpacf_kimd(func, &param, in, inlen);
 
 	memcpy(digest, &param, digestsize);
 
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH v1 1/1] s390/crypto: Generate intermediate CV for API partial block handling

Quoted 18 lines · Holger Dengler

The API partial block handling requires a intermediate chaining value (CV). The internal function hash_data() sets the function code correctly, so also call cpacf_kimd() instruction for intermediate CV generation, as cpacf_klmd() always generate the final hash value.

Fixes 08811169ac01 ("crypto: s390/hmac - Use API partial block handling")
---
 arch/s390/crypto/hmac_s390.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/s390/crypto/hmac_s390.c +0 -0
index f8cd09f341d4..445fa7bbd958 100644
@@ -150,7 +150,10 @@ static int hash_data(const u8 *in, unsigned int 
 inlen,

arch/s390/crypto/hmac_s390.c static int hash_data(const u8 *in, unsigned int · line 159

Quoted 10 lines
arch/s390/crypto/hmac_s390.c +4 -1
 
 #undef PARAM_INIT
 
-	cpacf_klmd(func, &param, in, inlen);
+	if (final)
+		cpacf_klmd(func, &param, in, inlen);
+	else
+		cpacf_kimd(func, &param, in, inlen);
 
 	memcpy(digest, &param, digestsize);
#3 lore raw

Re: [PATCH v1 1/1] s390/crypto: Generate intermediate CV for API partial block handling

In reply to Holger Dengler
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Hardware Alignment Requirement Violation due to __packed attribute --

--- Patch [1]: [PATCH v1 1/1] s390/crypto: Generate intermediate CV for API partial block handling --- commit 6ca29d2947b71c2e1420feb8fbee6504922ff37f
Author: Holger Dengler <[email protected]>

s390/crypto: Generate intermediate CV for API partial block handling

This commit updates the internal hash_data() function to conditionally use cpacf_kimd() for intermediate chaining values when API partial block handling is requested, reserving cpacf_klmd() for the final hash value.

arch/s390/crypto/hmac_s390.c static int hash_data(const u8 *in, unsigned int inlen, · line 156

Quoted 13 lines
arch/s390/crypto/hmac_s390.c +4 -1
index f8cd09f341d4b..445fa7bbd9586 100644
@@ -150,7 +150,10 @@ static int hash_data(const u8 *in, unsigned int inlen,
 
 #undef PARAM_INIT
 
-	cpacf_klmd(func, &param, in, inlen);
+	if (final)
+		cpacf_klmd(func, &param, in, inlen);
+	else
+		cpacf_kimd(func, &param, in, inlen);

[Severity: High]
This is a pre-existing issue, but could the alignment of the param block passed to cpacf_kimd() and cpacf_klmd() trigger a hardware specification exception?

The param variable is defined earlier in hash_data() with the __packed attribute:

	union {
		struct sha256_paramblock {
			u32 h[8];
			u64 mbl;
		} sha256;
		struct sha512_paramblock {
			u64 h[8];
			u128 mbl;
		} sha512;
	} __packed param;

The __packed attribute reduces the compiler's alignment requirement for param to 1 byte. The z/Architecture requires doubleword (8-byte) alignment for KIMD and KLMD parameter blocks.

If the compiler places param on a stack address not divisible by 8, won't this cause a kernel panic when passed to these hardware instructions?

Since the struct fields inside the union are naturally packed, can we remove the __packed attribute to ensure the compiler maintains safe alignment?

Quoted 3 lines
arch/s390/crypto/hmac_s390.c +0 -0
 	memcpy(digest, &param, digestsize);
 
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#4 lore raw

Re: [PATCH v1 1/1] s390/crypto: Generate intermediate CV for API partial block handling

Quoted 48 lines · On 8/14/26 16:31, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Hardware Alignment Requirement Violation due to __packed attribute --

--- Patch [1]: [PATCH v1 1/1] s390/crypto: Generate intermediate CV for API partial block handling --- commit 6ca29d2947b71c2e1420feb8fbee6504922ff37f
Author: Holger Dengler <[email protected]>

s390/crypto: Generate intermediate CV for API partial block handling

This commit updates the internal hash_data() function to conditionally use cpacf_kimd() for intermediate chaining values when API partial block handling is requested, reserving cpacf_klmd() for the final hash value.

arch/s390/crypto/hmac_s390.c static int hash_data(const u8 *in, unsigned int inlen, · line 156

Quoted 13 lines
arch/s390/crypto/hmac_s390.c +4 -1
index f8cd09f341d4b..445fa7bbd9586 100644
@@ -150,7 +150,10 @@ static int hash_data(const u8 *in, unsigned int inlen,
 
 #undef PARAM_INIT
 
-	cpacf_klmd(func, &param, in, inlen);
+	if (final)
+		cpacf_klmd(func, &param, in, inlen);
+	else
+		cpacf_kimd(func, &param, in, inlen);

[Severity: High]
This is a pre-existing issue, but could the alignment of the param block passed to cpacf_kimd() and cpacf_klmd() trigger a hardware specification exception?

The param variable is defined earlier in hash_data() with the __packed attribute:

	union {
		struct sha256_paramblock {
			u32 h[8];
			u64 mbl;
		} sha256;
		struct sha512_paramblock {
			u64 h[8];
			u128 mbl;
		} sha512;
	} __packed param;
Quoted 3 lines

The __packed attribute reduces the compiler's alignment requirement for param to 1 byte. The z/Architecture requires doubleword (8-byte) alignment for KIMD and KLMD parameter blocks.

This is not true. The z/Architecture (as described in "z/Architecture, Principles of Operation") does not require any alignment for the address of the parameter block in general register GR1.

Quoted 2 lines

If the compiler places param on a stack address not divisible by 8, won't this cause a kernel panic when passed to these hardware instructions?

There is no specification exception documented, if the parameter block address in GR1 is not 8-byte aligned. A stack address not divisible by 8 will not cause a specification exception and there for also no kernel crash.

Quoted 2 lines

Since the struct fields inside the union are naturally packed, can we remove the __packed attribute to ensure the compiler maintains safe alignment?

The __packed statement may be redundant. But I would prefer to leave it in the code, because it increases the readability.

[...]

Signature · 2 lines
Mit freundlichen Grüßen / Kind regards
Holger Dengler
author maintainer
#5 lore raw
In reply to Holger Dengler

Can someone please pick this series? Either via crypto or s390 maintainers. Thx.

Signature · 2 lines
Mit freundlichen Grüßen / Kind regards
Holger Dengler
maintainer
#6 lore raw
Quoted 2 lines · Holger Dengler

Can someone please pick this series? Either via crypto or s390 maintainers. Thx.

This should go via the crypto tree. Herbert?

maintainer
#7 lore raw
Quoted 5 lines · Heiko Carstens
Quoted 2 lines · Holger Dengler

Can someone please pick this series? Either via crypto or s390 maintainers. Thx.

This should go via the crypto tree. Herbert?

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt