Skip to content

Commit 5dabfec

Browse files
hfreudehcahca
authored andcommitted
s390/pkey: improve pkey retry behavior
This patch reworks and improves the pkey retry behavior for the pkey_ep11key2pkey() function. In contrast to the pkey_skey2pkey() function which is used to trigger a protected key derivation from an CCA secure data or cipher key the EP11 counterpart function had no proper retry loop implemented. This patch now introduces code which acts similar to the retry already done for CCA keys for this function used for EP11 keys. Signed-off-by: Harald Freudenberger <[email protected]> Reviewed-by: Holger Dengler <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent c338436 commit 5dabfec

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

drivers/s390/crypto/pkey_api.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -293,33 +293,36 @@ static int pkey_ep11key2pkey(const u8 *key, size_t keylen,
293293
u8 *protkey, u32 *protkeylen, u32 *protkeytype)
294294
{
295295
u32 nr_apqns, *apqns = NULL;
296+
int i, j, rc = -ENODEV;
296297
u16 card, dom;
297-
int i, rc;
298298

299299
zcrypt_wait_api_operational();
300300

301-
/* build a list of apqns suitable for this key */
302-
rc = ep11_findcard2(&apqns, &nr_apqns, 0xFFFF, 0xFFFF,
303-
ZCRYPT_CEX7,
304-
ap_is_se_guest() ? EP11_API_V6 : EP11_API_V4,
305-
ep11_kb_wkvp(key, keylen));
306-
if (rc)
307-
goto out;
301+
/* try two times in case of failure */
302+
for (i = 0; i < 2 && rc; i++) {
308303

309-
/* go through the list of apqns and try to derive an pkey */
310-
for (rc = -ENODEV, i = 0; i < nr_apqns; i++) {
311-
card = apqns[i] >> 16;
312-
dom = apqns[i] & 0xFFFF;
313-
rc = ep11_kblob2protkey(card, dom, key, keylen,
314-
protkey, protkeylen, protkeytype);
315-
if (rc == 0)
316-
break;
304+
/* build a list of apqns suitable for this key */
305+
rc = ep11_findcard2(&apqns, &nr_apqns, 0xFFFF, 0xFFFF,
306+
ZCRYPT_CEX7,
307+
ap_is_se_guest() ? EP11_API_V6 : EP11_API_V4,
308+
ep11_kb_wkvp(key, keylen));
309+
if (rc)
310+
continue; /* retry findcard on failure */
311+
312+
/* go through the list of apqns and try to derive an pkey */
313+
for (rc = -ENODEV, j = 0; j < nr_apqns && rc; j++) {
314+
card = apqns[j] >> 16;
315+
dom = apqns[j] & 0xFFFF;
316+
rc = ep11_kblob2protkey(card, dom, key, keylen,
317+
protkey, protkeylen, protkeytype);
318+
}
319+
320+
kfree(apqns);
317321
}
318322

319-
out:
320-
kfree(apqns);
321323
if (rc)
322324
pr_debug("%s failed rc=%d\n", __func__, rc);
325+
323326
return rc;
324327
}
325328

0 commit comments

Comments
 (0)