Skip to content

Commit f688429

Browse files
hfreudehcahca
authored andcommitted
s390/pkey/crypto: Introduce xflags param for pkey in-kernel API
Add a new parameter xflags to the in-kernel API function pkey_key2protkey(). Currently there is only one flag supported: * PKEY_XFLAG_NOMEMALLOC: If this flag is given in the xflags parameter, the pkey implementation is not allowed to allocate memory but instead should fall back to use preallocated memory or simple fail with -ENOMEM. This flag is for protected key derive within a cipher or similar which must not allocate memory which would cause io operations - see also the CRYPTO_ALG_ALLOCATES_MEMORY flag in crypto.h. The one and only user of this in-kernel API - the skcipher implementations PAES in paes_s390.c set this flag upon request to derive a protected key from the given raw key material. Signed-off-by: Harald Freudenberger <[email protected]> Reviewed-by: Holger Dengler <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Carstens <[email protected]>
1 parent e5a7f7e commit f688429

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

arch/s390/crypto/paes_s390.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ static inline int __paes_keyblob2pkey(const u8 *key, unsigned int keylen,
182182
{
183183
int i, rc = -EIO;
184184

185-
/* try three times in case of busy card */
185+
/* try three times in case of busy card or no mem */
186186
for (i = 0; rc && i < 3; i++) {
187-
if (rc == -EBUSY && in_task()) {
187+
if ((rc == -EBUSY || rc == -ENOMEM) && in_task()) {
188188
if (msleep_interruptible(1000))
189189
return -EINTR;
190190
}
191191
rc = pkey_key2protkey(key, keylen, pk->protkey, &pk->len,
192-
&pk->type);
192+
&pk->type, PKEY_XFLAG_NOMEMALLOC);
193193
}
194194

195195
return rc;

arch/s390/include/asm/pkey.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
* @param key pointer to a buffer containing the key blob
2121
* @param keylen size of the key blob in bytes
2222
* @param protkey pointer to buffer receiving the protected key
23+
* @param xflags additional execution flags (see PKEY_XFLAG_* definitions below)
24+
* As of now the only supported flag is PKEY_XFLAG_NOMEMALLOC.
2325
* @return 0 on success, negative errno value on failure
2426
*/
2527
int pkey_key2protkey(const u8 *key, u32 keylen,
26-
u8 *protkey, u32 *protkeylen, u32 *protkeytype);
28+
u8 *protkey, u32 *protkeylen, u32 *protkeytype,
29+
u32 xflags);
2730

2831
/*
2932
* If this flag is given in the xflags parameter, the pkey implementation

drivers/s390/crypto/pkey_api.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ static int key2protkey(const struct pkey_apqn *apqns, size_t nr_apqns,
5353
* In-Kernel function: Transform a key blob (of any type) into a protected key
5454
*/
5555
int pkey_key2protkey(const u8 *key, u32 keylen,
56-
u8 *protkey, u32 *protkeylen, u32 *protkeytype)
56+
u8 *protkey, u32 *protkeylen, u32 *protkeytype, u32 xflags)
5757
{
5858
int rc;
59-
const u32 xflags = 0;
6059

6160
rc = key2protkey(NULL, 0, key, keylen,
6261
protkey, protkeylen, protkeytype, xflags);

0 commit comments

Comments
 (0)