Skip to content

Commit 0eb3b02

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> Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 14e675e commit 0eb3b02

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
@@ -35,8 +35,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
3535
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
3636
memcpy(alignbuffer, key, keylen);
3737
ret = crypto_aead_alg(tfm)->setkey(tfm, alignbuffer, keylen);
38-
memset(alignbuffer, 0, keylen);
39-
kfree(buffer);
38+
kfree_sensitive(buffer);
4039
return ret;
4140
}
4241

crypto/cipher.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ static int setkey_unaligned(struct crypto_cipher *tfm, const u8 *key,
3434
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
3535
memcpy(alignbuffer, key, keylen);
3636
ret = cia->cia_setkey(crypto_cipher_tfm(tfm), alignbuffer, keylen);
37-
memset(alignbuffer, 0, keylen);
38-
kfree(buffer);
37+
kfree_sensitive(buffer);
3938
return ret;
4039

4140
}

0 commit comments

Comments
 (0)