Skip to contentSkip to conversation

crypto: xilinx - clear AES key buffer before freeing it

PATCH In review Thorsten Blum 3 participants 3 messages Sep 8 – Sep 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: xilinx - clear AES key buffer before freeing it

In xilinx_aes_aead_exit(), the AES key buffer is freed without being cleared, which allows key material to remain in memory. Use kfree_sensitive() to clear the buffer before freeing it.

Fixes c315cb0005be ("crypto: xilinx - Change coherent DMA to streaming DMA API")
---
 drivers/crypto/xilinx/zynqmp-aes-gcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/xilinx/zynqmp-aes-gcm.c +1 -1
index d54c268dfe34..ebee37dddb1f 100644
@@ -766,7 +766,7 @@ static void xilinx_aes_aead_exit(struct crypto_aead *aead)
 	struct xilinx_aead_tfm_ctx *tfm_ctx = crypto_tfm_ctx(tfm);
 
 	dma_unmap_single(tfm_ctx->dev, tfm_ctx->key_dma_addr, AES_KEYSIZE_256, DMA_TO_DEVICE);
-	kfree(tfm_ctx->key);
+	kfree_sensitive(tfm_ctx->key);
 	if (tfm_ctx->fbk_cipher) {
 		crypto_free_aead(tfm_ctx->fbk_cipher);
 		tfm_ctx->fbk_cipher = NULL;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Thorsten Blum

In xilinx_aes_aead_exit(), the AES key buffer is freed without being cleared, which allows key material to remain in memory. Use kfree_sensitive() to clear the buffer before freeing it.

Fixes c315cb0005be ("crypto: xilinx - Change coherent DMA to streaming DMA API")
---
  drivers/crypto/xilinx/zynqmp-aes-gcm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/xilinx/zynqmp-aes-gcm.c +0 -0
index d54c268dfe34..ebee37dddb1f 100644

drivers/crypto/xilinx/zynqmp-aes-gcm.c static void xilinx_aes_aead_exit(struct crypto_aead *aead) · line 772

Quoted 8 lines
drivers/crypto/xilinx/zynqmp-aes-gcm.c +1 -1
@@ -766,7 +766,7 @@ static void xilinx_aes_aead_exit(struct crypto_aead *aead)
  	struct xilinx_aead_tfm_ctx *tfm_ctx = crypto_tfm_ctx(tfm);
 
  	dma_unmap_single(tfm_ctx->dev, tfm_ctx->key_dma_addr, AES_KEYSIZE_256, DMA_TO_DEVICE);
-	kfree(tfm_ctx->key);
+	kfree_sensitive(tfm_ctx->key);
  	if (tfm_ctx->fbk_cipher) {
  		crypto_free_aead(tfm_ctx->fbk_cipher);
  		tfm_ctx->fbk_cipher = NULL;
maintainer
#2 lore raw
In reply to Thorsten Blum
Quoted 10 lines · Thorsten Blum

In xilinx_aes_aead_exit(), the AES key buffer is freed without being cleared, which allows key material to remain in memory. Use kfree_sensitive() to clear the buffer before freeing it.

Fixes c315cb0005be ("crypto: xilinx - Change coherent DMA to streaming DMA API")
---
 drivers/crypto/xilinx/zynqmp-aes-gcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt