aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilad Ben-Yossef <gilad@benyossef.com>2017-11-02 04:10:21 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-11-06 10:46:03 -0500
commite7cdcba451b3ddd68e714875be13e782577c9e4a (patch)
tree6b018f987460b8ed6a66b05b0af736ca89b7810d
parent42996f2d8e540b2baa7c26a4dac2f50dbbc9344d (diff)
staging: ccree: copy IV to DMAable memory
We are being passed an IV buffer from unknown origin, which may be stack allocated and thus not safe for DMA. Allocate a DMA safe buffer for the IV and use that instead. Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/ccree/ssi_cipher.c20
-rw-r--r--drivers/staging/ccree/ssi_cipher.h1
2 files changed, 19 insertions, 2 deletions
diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c
index 78706f5bcfb4..0b691034e6f5 100644
--- a/drivers/staging/ccree/ssi_cipher.c
+++ b/drivers/staging/ccree/ssi_cipher.c
@@ -695,6 +695,7 @@ static int ssi_blkcipher_complete(struct device *dev,
695 struct ablkcipher_request *req = (struct ablkcipher_request *)areq; 695 struct ablkcipher_request *req = (struct ablkcipher_request *)areq;
696 696
697 ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst); 697 ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
698 kfree(req_ctx->iv);
698 699
699 /*Decrease the inflight counter*/ 700 /*Decrease the inflight counter*/
700 if (ctx_p->flow_mode == BYPASS && ctx_p->drvdata->inflight_counter > 0) 701 if (ctx_p->flow_mode == BYPASS && ctx_p->drvdata->inflight_counter > 0)
@@ -757,6 +758,17 @@ static int ssi_blkcipher_process(
757 rc = 0; 758 rc = 0;
758 goto exit_process; 759 goto exit_process;
759 } 760 }
761
762 /* The IV we are handed may be allocted from the stack so
763 * we must copy it to a DMAable buffer before use.
764 */
765 req_ctx->iv = kmalloc(ivsize, GFP_KERNEL);
766 if (!req_ctx->iv) {
767 rc = -ENOMEM;
768 goto exit_process;
769 }
770 memcpy(req_ctx->iv, info, ivsize);
771
760 /*For CTS in case of data size aligned to 16 use CBC mode*/ 772 /*For CTS in case of data size aligned to 16 use CBC mode*/
761 if (((nbytes % AES_BLOCK_SIZE) == 0) && (ctx_p->cipher_mode == DRV_CIPHER_CBC_CTS)) { 773 if (((nbytes % AES_BLOCK_SIZE) == 0) && (ctx_p->cipher_mode == DRV_CIPHER_CBC_CTS)) {
762 ctx_p->cipher_mode = DRV_CIPHER_CBC; 774 ctx_p->cipher_mode = DRV_CIPHER_CBC;
@@ -778,7 +790,9 @@ static int ssi_blkcipher_process(
778 790
779 /* STAT_PHASE_1: Map buffers */ 791 /* STAT_PHASE_1: Map buffers */
780 792
781 rc = ssi_buffer_mgr_map_blkcipher_request(ctx_p->drvdata, req_ctx, ivsize, nbytes, info, src, dst); 793 rc = ssi_buffer_mgr_map_blkcipher_request(ctx_p->drvdata, req_ctx,
794 ivsize, nbytes, req_ctx->iv,
795 src, dst);
782 if (unlikely(rc != 0)) { 796 if (unlikely(rc != 0)) {
783 dev_err(dev, "map_request() failed\n"); 797 dev_err(dev, "map_request() failed\n");
784 goto exit_process; 798 goto exit_process;
@@ -830,8 +844,10 @@ exit_process:
830 if (cts_restore_flag != 0) 844 if (cts_restore_flag != 0)
831 ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS; 845 ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS;
832 846
833 if (rc != -EINPROGRESS) 847 if (rc != -EINPROGRESS) {
834 kfree(req_ctx->backup_info); 848 kfree(req_ctx->backup_info);
849 kfree(req_ctx->iv);
850 }
835 851
836 return rc; 852 return rc;
837} 853}
diff --git a/drivers/staging/ccree/ssi_cipher.h b/drivers/staging/ccree/ssi_cipher.h
index f4999626b94a..25e6335c0d94 100644
--- a/drivers/staging/ccree/ssi_cipher.h
+++ b/drivers/staging/ccree/ssi_cipher.h
@@ -43,6 +43,7 @@ struct blkcipher_req_ctx {
43 u32 out_nents; 43 u32 out_nents;
44 u32 out_mlli_nents; 44 u32 out_mlli_nents;
45 u8 *backup_info; /*store iv for generated IV flow*/ 45 u8 *backup_info; /*store iv for generated IV flow*/
46 u8 *iv;
46 bool is_giv; 47 bool is_giv;
47 struct mlli_params mlli_params; 48 struct mlli_params mlli_params;
48}; 49};