]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390/zcrypt: Fix missing mem scrub at clear key import in cca_clr2cipherkey()
authorHarald Freudenberger <freude@linux.ibm.com>
Wed, 29 Jul 2026 14:01:34 +0000 (16:01 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Fri, 31 Jul 2026 11:31:20 +0000 (13:31 +0200)
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: 4bc123b18ce6 ("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>
drivers/s390/crypto/zcrypt_ccamisc.c

index f797786107b928b33a7ab737c1356819a6204df6..86d2ee78c9f48cada96ccb5d19179a4fa354e618 100644 (file)
@@ -1015,7 +1015,8 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain,
                           int clr_key_bit_size,
                           u8 *key_token,
                           int *key_token_size,
-                          u32 xflags)
+                          u32 xflags,
+                          bool scrub)
 {
        int rc, n;
        u8 *mem, *ptr;
@@ -1155,7 +1156,7 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain,
        *key_token_size = t->len;
 
 out:
-       free_cprbmem(mem, PARMBSIZE, false, xflags);
+       free_cprbmem(mem, PARMBSIZE, scrub, xflags);
        return rc;
 }
 
@@ -1206,28 +1207,32 @@ 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, xflags);
+                            exorbuf, keybitsize, token, &tokensize,
+                            xflags, true);
        if (rc) {
                ZCRYPT_DBF_ERR("%s clear key import 1/4 with CSNBKPI2 failed, rc=%d\n",
                               __func__, rc);
                goto out;
        }
        rc = _ip_cprb_helper(card, dom, "AES     ", "ADD-PART", NULL,
-                            clrkey, keybitsize, token, &tokensize, xflags);
+                            clrkey, keybitsize, token, &tokensize,
+                            xflags, true);
        if (rc) {
                ZCRYPT_DBF_ERR("%s clear key import 2/4 with CSNBKPI2 failed, rc=%d\n",
                               __func__, rc);
                goto out;
        }
        rc = _ip_cprb_helper(card, dom, "AES     ", "ADD-PART", NULL,
-                            exorbuf, keybitsize, token, &tokensize, xflags);
+                            exorbuf, keybitsize, token, &tokensize,
+                            xflags, true);
        if (rc) {
                ZCRYPT_DBF_ERR("%s clear key import 3/4 with CSNBKPI2 failed, rc=%d\n",
                               __func__, rc);
                goto out;
        }
        rc = _ip_cprb_helper(card, dom, "AES     ", "COMPLETE", NULL,
-                            NULL, keybitsize, token, &tokensize, xflags);
+                            NULL, keybitsize, token, &tokensize,
+                            xflags, true);
        if (rc) {
                ZCRYPT_DBF_ERR("%s clear key import 4/4 with CSNBKPI2 failed, rc=%d\n",
                               __func__, rc);
@@ -1244,6 +1249,8 @@ int cca_clr2cipherkey(u16 card, u16 dom, u32 keybitsize, u32 keygenflags,
        *keybufsize = tokensize;
 
 out:
+       memzero_explicit(exorbuf, sizeof(exorbuf));
+       memzero_explicit(mem, CPRB_MEMPOOL_ITEM_SIZE);
        mempool_free(mem, cprb_mempool);
        return rc;
 }