Skip to contentSkip to conversation

fixup! s390/zcrypt: Rework cca findcard() implementation and callers

PATCH Applied Harald Freudenberger 2 participants 2 messages Apr 25, 2025

Subsystems (2)
lore
Share & tools
lore

Harald Freudenberger

author maintainer
#0 lore raw

PATCH 1/1 fixup! s390/zcrypt: Rework cca findcard() implementation and callers

Ci run of the night showed that a CCA secure key which maches to an old MK on the HSM is not correctly verified. The code builds up an array with a given apqn array with a fixed arraysize and calls findcard2() for the CURRENT MK which fails as expected. So next attempt is made with trying to match the OLD MK with same apqn array and same arraysize variable. But the previous call hat set this arraysize variable to 0 and so the 2nd invocation finds a valid apqn but the arraysize variable tells there is no space in the array. Fixed and tested.

---
 drivers/s390/crypto/pkey_cca.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/s390/crypto/pkey_cca.c +2 -0
index fe67946edc9d..6c7897a93f27 100644
@@ -487,6 +487,7 @@ static int cca_verifykey(const u8 *key, u32 keylen,
 		if (!rc)
 			*flags = PKEY_FLAGS_MATCH_CUR_MKVP;
 		if (rc == -ENODEV) {
+			nr_apqns = ARRAY_SIZE(apqns);
 			rc = cca_findcard2(apqns, &nr_apqns, *card, *dom,
 					   ZCRYPT_CEX3C, AES_MK_SET,
 					   0, t->mkvp, xflags);
@@ -520,6 +521,7 @@ static int cca_verifykey(const u8 *key, u32 keylen,
 		if (!rc)
 			*flags = PKEY_FLAGS_MATCH_CUR_MKVP;
 		if (rc == -ENODEV) {
+			nr_apqns = ARRAY_SIZE(apqns);
 			rc = cca_findcard2(apqns, &nr_apqns, *card, *dom,
 					   ZCRYPT_CEX6, AES_MK_SET,
 					   0, t->mkvp0, xflags);
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Harald Freudenberger

Ci run of the night showed that a CCA secure key which maches to an old MK on the HSM is not correctly verified. The code builds up an array with a given apqn array with a fixed arraysize and calls findcard2() for the CURRENT MK which fails as expected. So next attempt is made with trying to match the OLD MK with same apqn array and same arraysize variable. But the previous call hat set this arraysize variable to 0 and so the 2nd invocation finds a valid apqn but the arraysize variable tells there is no space in the array. Fixed and tested.

Quoted 5 lines
---
 drivers/s390/crypto/pkey_cca.c | 2 ++
 1 file changed, 2 insertions(+)

Merged into your previous patch. Thanks!