mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
s390/zcrypt: Fix missing mem scrub at clear key import in cca_clr2cipherkey()
[ Upstream commit01476391ae] The helper function _ip_cprb_helper() uses internal buffer memory for building and processing CPRBs. After use this buffer was never scrubbed which could lead to leaving for example clear key material in memory which could be exposed via tricky reuse of this same memory. Extend the _ip_cprb_helper() function with another parameter 'scrub' used to steer scrubbing of this buffer. So now the caller has the opportunity to decide if scrubbing is needed or not. Extend the clear key to secure key token import process in function cca_clr2cipherkey() to tell the helper function from above to scrub the cprb buffer when the clear key value is part of the request data. Add explicit scrubbing on return from function cca_clr2cipherkey() for the random EXOR buffer and the cprb buffer. Overall this cleans the internal used buffer in case of clear key import to prevent sensitive data to get exposed. Fixes:4bc123b18c("s390/zcrypt: Add low level functions for CCA AES cipher keys") Cc: stable@vger.kernel.org Reviewed-by: Holger Dengler <dengler@linux.ibm.com> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Holger Dengler <dengler@linux.ibm.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
590d9aec77
commit
7dd6e556db
@@ -946,7 +946,8 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain,
|
||||
const u8 *clr_key_value,
|
||||
int clr_key_bit_size,
|
||||
u8 *key_token,
|
||||
int *key_token_size)
|
||||
int *key_token_size,
|
||||
bool scrub)
|
||||
{
|
||||
int rc, n;
|
||||
u8 *mem, *ptr;
|
||||
@@ -1087,7 +1088,7 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain,
|
||||
*key_token_size = t->len;
|
||||
|
||||
out:
|
||||
free_cprbmem(mem, PARMBSIZE, 0);
|
||||
free_cprbmem(mem, PARMBSIZE, scrub);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1130,7 +1131,8 @@ int cca_clr2cipherkey(u16 card, u16 dom, u32 keybitsize, u32 keygenflags,
|
||||
* 4/4 COMPLETE the secure cipher key import
|
||||
*/
|
||||
rc = _ip_cprb_helper(card, dom, "AES ", "FIRST ", "MIN3PART",
|
||||
exorbuf, keybitsize, token, &tokensize);
|
||||
exorbuf, keybitsize, token, &tokensize,
|
||||
true);
|
||||
if (rc) {
|
||||
DEBUG_ERR(
|
||||
"%s clear key import 1/4 with CSNBKPI2 failed, rc=%d\n",
|
||||
@@ -1138,7 +1140,8 @@ int cca_clr2cipherkey(u16 card, u16 dom, u32 keybitsize, u32 keygenflags,
|
||||
goto out;
|
||||
}
|
||||
rc = _ip_cprb_helper(card, dom, "AES ", "ADD-PART", NULL,
|
||||
clrkey, keybitsize, token, &tokensize);
|
||||
clrkey, keybitsize, token, &tokensize,
|
||||
true);
|
||||
if (rc) {
|
||||
DEBUG_ERR(
|
||||
"%s clear key import 2/4 with CSNBKPI2 failed, rc=%d\n",
|
||||
@@ -1146,7 +1149,8 @@ int cca_clr2cipherkey(u16 card, u16 dom, u32 keybitsize, u32 keygenflags,
|
||||
goto out;
|
||||
}
|
||||
rc = _ip_cprb_helper(card, dom, "AES ", "ADD-PART", NULL,
|
||||
exorbuf, keybitsize, token, &tokensize);
|
||||
exorbuf, keybitsize, token, &tokensize,
|
||||
true);
|
||||
if (rc) {
|
||||
DEBUG_ERR(
|
||||
"%s clear key import 3/4 with CSNBKPI2 failed, rc=%d\n",
|
||||
@@ -1154,7 +1158,8 @@ int cca_clr2cipherkey(u16 card, u16 dom, u32 keybitsize, u32 keygenflags,
|
||||
goto out;
|
||||
}
|
||||
rc = _ip_cprb_helper(card, dom, "AES ", "COMPLETE", NULL,
|
||||
NULL, keybitsize, token, &tokensize);
|
||||
NULL, keybitsize, token, &tokensize,
|
||||
true);
|
||||
if (rc) {
|
||||
DEBUG_ERR(
|
||||
"%s clear key import 4/4 with CSNBKPI2 failed, rc=%d\n",
|
||||
@@ -1172,7 +1177,8 @@ int cca_clr2cipherkey(u16 card, u16 dom, u32 keybitsize, u32 keygenflags,
|
||||
*keybufsize = tokensize;
|
||||
|
||||
out:
|
||||
kfree(token);
|
||||
memzero_explicit(exorbuf, sizeof(exorbuf));
|
||||
kfree_sensitive(token);
|
||||
return rc;
|
||||
}
|
||||
EXPORT_SYMBOL(cca_clr2cipherkey);
|
||||
|
||||
Reference in New Issue
Block a user