From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5902C3F8EBE; Mon, 17 Aug 2026 15:24:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786980269; cv=none; b=C5IMOQJueUsAT8i0A9EuYuLJg2qrmQcTAl70Rt/e7SOr20Tgrigc5fgzosqbMDmBdrVpsnZ8M3BCuTjvYKq+lMulntIyrt3YmEHN3zUWflzbUK8UZcgJQDmlkOaIJhLCw8z6sWnLbEWDDBDjJL2HqxcuY0SGn8TxP8iA4HTLLpY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786980269; c=relaxed/simple; bh=hJvjeQ4GV2ZR/p+VJzjDNNAyR4gzmFGkD6UhNxb1FXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lI/4Yfyo3JagVgaUTHK740X09FGg307bOgBZgZj2LYu2usVaeN5JBuKXhcp1en6SSxeyCEzFSlVEc4gycUTf2wgCxYSfNIfsowDQ4s0/iAuaOSd8ZFl8WwFsf7W1O76o1Sx2XpW7A8H/wd4SbKJEzCi7u/xAV7YlGJSZi0E+qvI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=h/cxjm7S; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="h/cxjm7S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B41961F00A3A; Mon, 17 Aug 2026 15:24:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786980268; bh=NiN+xpqxpvHCLG08SiWLC1gDKokEndPnfL0Um6QQRIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=h/cxjm7SUFln+LqjdOa0v5rU0EsJZtiVGqHHj50SEHV5HjL8V05je14LXzgTr79n8 btKlghRx4+C4Ho4PK2HJfnBTpLy19plQMsZ3AulxDa8LTYjbDLXx7nT0VwH16SCtt3 NvBsAz4HB5JEPhSnSrv11BWfSGBdJIttvGDdw+IY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Holger Dengler , Harald Freudenberger , Vasily Gorbik , Sasha Levin Subject: [PATCH 6.1 487/609] s390/zcrypt: Fix missing mem scrub at clear key import in cca_clr2cipherkey() Date: Mon, 17 Aug 2026 15:33:03 +0200 Message-ID: <20260817132600.223856617@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132543.039278408@linuxfoundation.org> References: <20260817132543.039278408@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Harald Freudenberger [ Upstream commit 01476391aecef36a3b789ee844357b22fbc90665 ] 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 Signed-off-by: Harald Freudenberger Signed-off-by: Vasily Gorbik Signed-off-by: Holger Dengler Signed-off-by: Sasha Levin --- drivers/s390/crypto/zcrypt_ccamisc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/s390/crypto/zcrypt_ccamisc.c b/drivers/s390/crypto/zcrypt_ccamisc.c index 59323c8ca2856..622d960098ad3 100644 --- a/drivers/s390/crypto/zcrypt_ccamisc.c +++ b/drivers/s390/crypto/zcrypt_ccamisc.c @@ -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); -- 2.53.0