Skip to contentSkip to conversation

crypto: inside-secure - Zeroize temporary arrays on stack with sensitive data

PATCH Superseded Thomas Huth 2 participants 2 messages Aug 14 – Aug 19

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: inside-secure - Zeroize temporary arrays on stack with sensitive data

This issue has been found by the Sashiko bot while reviewing another
patch: key_tmp[] in safexcel_xcbcmac_setkey() and consts[] / _const[] in safexcel_cmac_setkey() contain crypto key material that should not get exposed to the outside once the function is done. Scrub the arrays with memzero_explicit() to avoid that the data could leak via the stack.

---
 drivers/crypto/inside-secure/safexcel_hash.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/crypto/inside-secure/safexcel_hash.c +4 -0
index 3402e570d045c..1ae6fbec31298 100644
@@ -1993,6 +1993,7 @@ static int safexcel_xcbcmac_setkey(struct crypto_ahash *tfm, const u8 *key,
 	ret = aes_prepareenckey(ctx->aes,
 				(u8 *)key_tmp + 2 * AES_BLOCK_SIZE,
 				AES_MIN_KEY_SIZE);
+	memzero_explicit(key_tmp, sizeof(key_tmp));
 	if (ret)
 		return ret;
 
@@ -2104,6 +2105,9 @@ static int safexcel_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
 	}
 	ctx->cbcmac = false;
 
+
+	memzero_explicit(consts, sizeof(consts));
+	memzero_explicit(_const, sizeof(_const));
 	return 0;
 }
 
Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Thomas Huth

This issue has been found by the Sashiko bot while reviewing another
patch: key_tmp[] in safexcel_xcbcmac_setkey() and consts[] / _const[] in safexcel_cmac_setkey() contain crypto key material that should not get exposed to the outside once the function is done. Scrub the arrays with memzero_explicit() to avoid that the data could leak via the stack.

This could have both a Reported-by (Sashiko) and a Fixes tag.

With that,

Thanks!

Quoted 29 lines
---
 drivers/crypto/inside-secure/safexcel_hash.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/crypto/inside-secure/safexcel_hash.c +4 -0
index 3402e570d045c..1ae6fbec31298 100644
@@ -1993,6 +1993,7 @@ static int safexcel_xcbcmac_setkey(struct crypto_ahash *tfm, const u8 *key,
 	ret = aes_prepareenckey(ctx->aes,
 				(u8 *)key_tmp + 2 * AES_BLOCK_SIZE,
 				AES_MIN_KEY_SIZE);
+	memzero_explicit(key_tmp, sizeof(key_tmp));
 	if (ret)
 		return ret;
 
@@ -2104,6 +2105,9 @@ static int safexcel_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
 	}
 	ctx->cbcmac = false;
 
+
+	memzero_explicit(consts, sizeof(consts));
+	memzero_explicit(_const, sizeof(_const));
 	return 0;
 }
 
Signature · 1 line
2.55.0