diff mbox series

[SRU,F,1/1] crypto: aead, cipher - zeroize key buffer after use

Message ID 20240916222027.134582-2-bethany.jamison@canonical.com
State New
Headers show
Series CVE-2024-42229 | expand

Commit Message

Bethany Jamison Sept. 16, 2024, 10:20 p.m. UTC
From: Hailey Mothershead <hailmo@amazon.com>

[ Upstream commit 23e4099bdc3c8381992f9eb975c79196d6755210 ]

I.G 9.7.B for FIPS 140-3 specifies that variables temporarily holding
cryptographic information should be zeroized once they are no longer
needed. Accomplish this by using kfree_sensitive for buffers that
previously held the private key.

Signed-off-by: Hailey Mothershead <hailmo@amazon.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(backported from commit 9db8c299a521813630fcb4154298cb60c37f3133 linux-5.10.y)
[bjamison: ignored context conflict from neighboring line that shouldn't
affect fix - missing commit e8cfed5 (crypto: cipher - remove crt_u.cipher
(struct cipher_tfm)), and used kzfree instead of kfree_sensitive - renamed in
commit 453431a (mm, treewide: rename kzfree() to kfree_sensitive())]
CVE-2024-42229
Signed-off-by: Bethany Jamison <bethany.jamison@canonical.com>
---
 crypto/aead.c   | 3 +--
 crypto/cipher.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/crypto/aead.c b/crypto/aead.c
index ce035589cf577..8f60b48a835bd 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -40,8 +40,7 @@  static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
 	alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
 	memcpy(alignbuffer, key, keylen);
 	ret = crypto_aead_alg(tfm)->setkey(tfm, alignbuffer, keylen);
-	memset(alignbuffer, 0, keylen);
-	kfree(buffer);
+	kzfree(buffer);
 	return ret;
 }
 
diff --git a/crypto/cipher.c b/crypto/cipher.c
index 108427026e7c7..18bf9c425ae28 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -33,8 +33,7 @@  static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
 	alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
 	memcpy(alignbuffer, key, keylen);
 	ret = cia->cia_setkey(tfm, alignbuffer, keylen);
-	memset(alignbuffer, 0, keylen);
-	kfree(buffer);
+	kzfree(buffer);
 	return ret;
 
 }