Skip to content

Commit 0be9f27

Browse files
jallisonciqPlaidCat
authored andcommitted
crypto: aead,cipher - zeroize key buffer after use
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> Back-ported from commit 23e4099 Author: Hailey Mothershead <hailmo@amazon.com> Date: Mon Apr 15 22:19:15 2024 +0000 Signed-off-by: Jeremy Allison <jallison@ciq.com>
1 parent 4c8ad45 commit 0be9f27

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

crypto/aead.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
4545
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
4646
memcpy(alignbuffer, key, keylen);
4747
ret = crypto_aead_alg(tfm)->setkey(tfm, alignbuffer, keylen);
48-
memset(alignbuffer, 0, keylen);
49-
kfree(buffer);
48+
kfree_sensitive(buffer);
5049
return ret;
5150
}
5251

crypto/cipher.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
3838
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
3939
memcpy(alignbuffer, key, keylen);
4040
ret = cia->cia_setkey(tfm, alignbuffer, keylen);
41-
memset(alignbuffer, 0, keylen);
42-
kfree(buffer);
41+
kfree_sensitive(buffer);
4342
return ret;
4443

4544
}

0 commit comments

Comments
 (0)