2023-06-01 10:17:09

by Cabiddu, Giovanni

[permalink] [raw]
Subject: [PATCH 0/2] 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(-)

--
2.40.1



2023-06-01 10:17:26

by Cabiddu, Giovanni

[permalink] [raw]
Subject: [PATCH 2/2] crypto: qat - unmap buffers before free for RSA

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")
Signed-off-by: Hareshx Sankar Raj <[email protected]>
Co-developed-by: Bolemx Sivanagaleela <[email protected]>
Signed-off-by: Bolemx Sivanagaleela <[email protected]>
Reviewed-by: Giovanni Cabiddu <[email protected]>
Signed-off-by: Giovanni Cabiddu <[email protected]>
---
drivers/crypto/intel/qat/qat_common/qat_asym_algs.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c b/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c
index 8806242469a0..4128200a9032 100644
--- a/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c
+++ b/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c
@@ -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,
--
2.40.1


2023-06-07 08:05:54

by Cabiddu, Giovanni

[permalink] [raw]
Subject: Re: [PATCH 0/2] crypto: qat - unmap buffers before free

Hi Herbert,

On Thu, Jun 01, 2023 at 11:09:58AM +0100, Giovanni Cabiddu wrote:
> 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(-)
Just in case you haven't seen it. There is a RESEND for the same set with
an additional Reviewed-by tag.

Regards,

--
Giovanni