stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/7] crypto: ccree: fix free of unallocated mlli buffer
       [not found] <20190115134318.28712-1-gilad@benyossef.com>
@ 2019-01-15 13:43 ` Gilad Ben-Yossef
  2019-01-15 13:43 ` [PATCH 5/7] crypto: ccree: unmap buffer before copying IV Gilad Ben-Yossef
  2019-01-15 13:43 ` [PATCH 7/7] crypto: ccree: don't copy zero size ciphertext Gilad Ben-Yossef
  2 siblings, 0 replies; 3+ messages in thread
From: Gilad Ben-Yossef @ 2019-01-15 13:43 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: Hadar Gat, stable, linux-crypto, linux-kernel

From: Hadar Gat <hadar.gat@arm.com>

In cc_unmap_aead_request(), call dma_pool_free() for mlli buffer only
if an item is allocated from the pool and not always if there is a
pool allocated.
This fixes a kernel panic when trying to free a non-allocated item.

Cc: stable@vger.kernel.org
Signed-off-by: Hadar Gat <hadar.gat@arm.com>
Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
---
 drivers/crypto/ccree/cc_buffer_mgr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ccree/cc_buffer_mgr.c b/drivers/crypto/ccree/cc_buffer_mgr.c
index 237a87a57830..0ee1c52da0a4 100644
--- a/drivers/crypto/ccree/cc_buffer_mgr.c
+++ b/drivers/crypto/ccree/cc_buffer_mgr.c
@@ -614,10 +614,10 @@ void cc_unmap_aead_request(struct device *dev, struct aead_request *req)
 				 hw_iv_size, DMA_BIDIRECTIONAL);
 	}
 
-	/*In case a pool was set, a table was
-	 *allocated and should be released
-	 */
-	if (areq_ctx->mlli_params.curr_pool) {
+	/* Release pool */
+	if ((areq_ctx->assoc_buff_type == CC_DMA_BUF_MLLI ||
+	     areq_ctx->data_buff_type == CC_DMA_BUF_MLLI) &&
+	    (areq_ctx->mlli_params.mlli_virt_addr)) {
 		dev_dbg(dev, "free MLLI buffer: dma=%pad virt=%pK\n",
 			&areq_ctx->mlli_params.mlli_dma_addr,
 			areq_ctx->mlli_params.mlli_virt_addr);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 5/7] crypto: ccree: unmap buffer before copying IV
       [not found] <20190115134318.28712-1-gilad@benyossef.com>
  2019-01-15 13:43 ` [PATCH 3/7] crypto: ccree: fix free of unallocated mlli buffer Gilad Ben-Yossef
@ 2019-01-15 13:43 ` Gilad Ben-Yossef
  2019-01-15 13:43 ` [PATCH 7/7] crypto: ccree: don't copy zero size ciphertext Gilad Ben-Yossef
  2 siblings, 0 replies; 3+ messages in thread
From: Gilad Ben-Yossef @ 2019-01-15 13:43 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: stable, linux-crypto, linux-kernel

We were copying the last ciphertext block into the IV field
for CBC before removing the DMA mapping of the output buffer
with the result of the buffer sometime being out-of-sync cache
wise and were getting intermittent cases of bad output IV.

Fix it by moving the DMA buffer unmapping before the copy.

Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Fixes: 00904aa0cd59 ("crypto: ccree - fix iv handling")
Cc: <stable@vger.kernel.org>
---
 drivers/crypto/ccree/cc_cipher.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c
index cc92b031fad1..98ea53524250 100644
--- a/drivers/crypto/ccree/cc_cipher.c
+++ b/drivers/crypto/ccree/cc_cipher.c
@@ -652,6 +652,8 @@ static void cc_cipher_complete(struct device *dev, void *cc_req, int err)
 	unsigned int ivsize = crypto_skcipher_ivsize(sk_tfm);
 	unsigned int len;
 
+	cc_unmap_cipher_request(dev, req_ctx, ivsize, src, dst);
+
 	switch (ctx_p->cipher_mode) {
 	case DRV_CIPHER_CBC:
 		/*
@@ -681,7 +683,6 @@ static void cc_cipher_complete(struct device *dev, void *cc_req, int err)
 		break;
 	}
 
-	cc_unmap_cipher_request(dev, req_ctx, ivsize, src, dst);
 	kzfree(req_ctx->iv);
 
 	skcipher_request_complete(req, err);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 7/7] crypto: ccree: don't copy zero size ciphertext
       [not found] <20190115134318.28712-1-gilad@benyossef.com>
  2019-01-15 13:43 ` [PATCH 3/7] crypto: ccree: fix free of unallocated mlli buffer Gilad Ben-Yossef
  2019-01-15 13:43 ` [PATCH 5/7] crypto: ccree: unmap buffer before copying IV Gilad Ben-Yossef
@ 2019-01-15 13:43 ` Gilad Ben-Yossef
  2 siblings, 0 replies; 3+ messages in thread
From: Gilad Ben-Yossef @ 2019-01-15 13:43 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: stable, linux-crypto, linux-kernel

For decryption in CBC mode we need to save the last ciphertext block
for use as the next IV. However, we were trying to do this also with
zero sized ciphertext resulting in a panic.

Fix this by only doing the copy if the ciphertext length is at least
of IV size.

Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Cc: stable@vger.kernel.org
---
 drivers/crypto/ccree/cc_cipher.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c
index 98ea53524250..e202d7c7ea00 100644
--- a/drivers/crypto/ccree/cc_cipher.c
+++ b/drivers/crypto/ccree/cc_cipher.c
@@ -800,7 +800,8 @@ static int cc_cipher_decrypt(struct skcipher_request *req)
 
 	memset(req_ctx, 0, sizeof(*req_ctx));
 
-	if (ctx_p->cipher_mode == DRV_CIPHER_CBC) {
+	if ((ctx_p->cipher_mode == DRV_CIPHER_CBC) &&
+	    (req->cryptlen >= ivsize)) {
 
 		/* Allocate and save the last IV sized bytes of the source,
 		 * which will be lost in case of in-place decryption.
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-15 13:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190115134318.28712-1-gilad@benyossef.com>
2019-01-15 13:43 ` [PATCH 3/7] crypto: ccree: fix free of unallocated mlli buffer Gilad Ben-Yossef
2019-01-15 13:43 ` [PATCH 5/7] crypto: ccree: unmap buffer before copying IV Gilad Ben-Yossef
2019-01-15 13:43 ` [PATCH 7/7] crypto: ccree: don't copy zero size ciphertext Gilad Ben-Yossef

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).