Skip to contentSkip to conversation

crypto: qat - unmap buffers before free

PATCH RESEND In review Giovanni Cabiddu 2 participants 4 messages Jun 5, 2023 – Jun 16, 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.

Resending adding Reviewed-by Andy got from an internal review.

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 RESEND 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.

---
 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 RESEND 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.

---
 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
maintainer
#3 lore raw
In reply to Giovanni Cabiddu
Quoted 6 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.

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

Quoted 11 lines

Resending adding Reviewed-by Andy got from an internal review.

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

All 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