Skip to contentSkip to conversation

crypto: qat - unmap buffers before free

PATCH Superseded Giovanni Cabiddu 1 participant 4 messages Jun 1, 2023 – Jun 7, 2023

Subsystems (2)
lore
Share & tools
lore

Giovanni Cabiddu

author maintainer
#0 lore raw

cover crypto: qat - unmap buffers before free

The callbacks functions for RSA and DH free the memory allocated for the source and destination buffers before unmapping it.
This sequence is not correct.

Change the cleanup sequence to unmap the buffers before freeing them.

Hareshx Sankar Raj (2):
crypto: qat - unmap buffer before free for DH
crypto: qat - unmap buffers before free for RSA

 .../crypto/intel/qat/qat_common/qat_asym_algs.c    | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH 1/2 crypto: qat - unmap buffer before free for DH

From: Hareshx Sankar Raj <[email protected]>

The callback function for DH frees the memory allocated for the destination buffer before unmapping it.
This sequence is wrong.

Change the cleanup sequence to unmap the buffer before freeing it.

Fixes 029aa4624a7f ("crypto: qat - remove dma_free_coherent() for DH")
---
 drivers/crypto/intel/qat/qat_common/qat_asym_algs.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/crypto/intel/qat/qat_common/qat_asym_algs.c +2 -3
index 935a7e012946..8806242469a0 100644
@@ -170,15 +170,14 @@ static void qat_dh_cb(struct icp_qat_fw_pke_resp *resp)
 	}
 
 	areq->dst_len = req->ctx.dh->p_size;
+	dma_unmap_single(dev, req->out.dh.r, req->ctx.dh->p_size,
+			 DMA_FROM_DEVICE);
 	if (req->dst_align) {
 		scatterwalk_map_and_copy(req->dst_align, areq->dst, 0,
 					 areq->dst_len, 1);
 		kfree_sensitive(req->dst_align);
 	}
 
-	dma_unmap_single(dev, req->out.dh.r, req->ctx.dh->p_size,
-			 DMA_FROM_DEVICE);
-
 	dma_unmap_single(dev, req->phy_in, sizeof(struct qat_dh_input_params),
 			 DMA_TO_DEVICE);
 	dma_unmap_single(dev, req->phy_out,
Signature · 1 line
2.40.1
author maintainer
#2 lore raw

PATCH 2/2 crypto: qat - unmap buffers before free for RSA

In reply to Giovanni Cabiddu

From: Hareshx Sankar Raj <[email protected]>

The callback function for RSA frees the memory allocated for the source and destination buffers before unmapping them.
This sequence is wrong.

Change the cleanup sequence to unmap the buffers before freeing them.

Fixes 3dfaf0071ed7 ("crypto: qat - remove dma_free_coherent() for RSA")
---
 drivers/crypto/intel/qat/qat_common/qat_asym_algs.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/crypto/intel/qat/qat_common/qat_asym_algs.c +4 -5
index 8806242469a0..4128200a9032 100644
@@ -520,12 +520,14 @@ static void qat_rsa_cb(struct icp_qat_fw_pke_resp *resp)
 
 	err = (err == ICP_QAT_FW_COMN_STATUS_FLAG_OK) ? 0 : -EINVAL;
 
-	kfree_sensitive(req->src_align);
-
 	dma_unmap_single(dev, req->in.rsa.enc.m, req->ctx.rsa->key_sz,
 			 DMA_TO_DEVICE);
 
+	kfree_sensitive(req->src_align);
+
 	areq->dst_len = req->ctx.rsa->key_sz;
+	dma_unmap_single(dev, req->out.rsa.enc.c, req->ctx.rsa->key_sz,
+			 DMA_FROM_DEVICE);
 	if (req->dst_align) {
 		scatterwalk_map_and_copy(req->dst_align, areq->dst, 0,
 					 areq->dst_len, 1);
@@ -533,9 +535,6 @@ static void qat_rsa_cb(struct icp_qat_fw_pke_resp *resp)
 		kfree_sensitive(req->dst_align);
 	}
 
-	dma_unmap_single(dev, req->out.rsa.enc.c, req->ctx.rsa->key_sz,
-			 DMA_FROM_DEVICE);
-
 	dma_unmap_single(dev, req->phy_in, sizeof(struct qat_rsa_input_params),
 			 DMA_TO_DEVICE);
 	dma_unmap_single(dev, req->phy_out,
Signature · 1 line
2.40.1
author maintainer
#3 lore raw
In reply to Giovanni Cabiddu

Hi Herbert,

Quoted 4 lines · Giovanni Cabiddu

The callbacks functions for RSA and DH free the memory allocated for the source and destination buffers before unmapping it.
This sequence is not correct.

Quoted 8 lines

Change the cleanup sequence to unmap the buffers before freeing them.

Hareshx Sankar Raj (2):
crypto: qat - unmap buffer before free for DH
crypto: qat - unmap buffers before free for RSA

 .../crypto/intel/qat/qat_common/qat_asym_algs.c    | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Just in case you haven't seen it. There is a RESEND for the same set with an additional Reviewed-by tag.

Regards,

Signature · 1 line
Giovanni