2023-06-05 21:16:41

by Cabiddu, Giovanni

[permalink] [raw]
Subject: [RESEND 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.

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(-)

--
2.40.1



2023-06-05 21:16:41

by Cabiddu, Giovanni

[permalink] [raw]
Subject: [RESEND 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]>
Reviewed-by: Andy Shevchenko <[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-05 21:16:41

by Cabiddu, Giovanni

[permalink] [raw]
Subject: [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.

Fixes: 029aa4624a7f ("crypto: qat - remove dma_free_coherent() for DH")
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]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Giovanni Cabiddu <[email protected]>
---
drivers/crypto/intel/qat/qat_common/qat_asym_algs.c | 5 ++---
1 file changed, 2 insertions(+), 3 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 935a7e012946..8806242469a0 100644
--- a/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c
+++ b/drivers/crypto/intel/qat/qat_common/qat_asym_algs.c
@@ -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,
--
2.40.1


2023-06-16 12:43:33

by Herbert Xu

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

On Mon, Jun 05, 2023 at 10:06:05PM +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.
>
> 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(-)
>
> --
> 2.40.1

All applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt