LinuxPPC-Dev Archive on lore.kernel.org
 help / Atom feed
* [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc()
@ 2019-01-08  6:56 Christophe Leroy
  2019-01-08  6:56 ` [PATCH v4 2/2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK Christophe Leroy
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Christophe Leroy @ 2019-01-08  6:56 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller, Horia Geanta
  Cc: linuxppc-dev, linux-crypto, stable, linux-kernel

This patch moves the mapping of IV after the kmalloc(). This
avoids having to unmap in case kmalloc() fails.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 new in v4

 drivers/crypto/talitos.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 45e20707cef8..54d80e7edb86 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1361,23 +1361,18 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
 	struct talitos_private *priv = dev_get_drvdata(dev);
 	bool is_sec1 = has_ftr_sec1(priv);
 	int max_len = is_sec1 ? TALITOS1_MAX_DATA_LEN : TALITOS2_MAX_DATA_LEN;
-	void *err;
 
 	if (cryptlen + authsize > max_len) {
 		dev_err(dev, "length exceeds h/w max limit\n");
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (ivsize)
-		iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE);
-
 	if (!dst || dst == src) {
 		src_len = assoclen + cryptlen + authsize;
 		src_nents = sg_nents_for_len(src, src_len);
 		if (src_nents < 0) {
 			dev_err(dev, "Invalid number of src SG.\n");
-			err = ERR_PTR(-EINVAL);
-			goto error_sg;
+			return ERR_PTR(-EINVAL);
 		}
 		src_nents = (src_nents == 1) ? 0 : src_nents;
 		dst_nents = dst ? src_nents : 0;
@@ -1387,16 +1382,14 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
 		src_nents = sg_nents_for_len(src, src_len);
 		if (src_nents < 0) {
 			dev_err(dev, "Invalid number of src SG.\n");
-			err = ERR_PTR(-EINVAL);
-			goto error_sg;
+			return ERR_PTR(-EINVAL);
 		}
 		src_nents = (src_nents == 1) ? 0 : src_nents;
 		dst_len = assoclen + cryptlen + (encrypt ? authsize : 0);
 		dst_nents = sg_nents_for_len(dst, dst_len);
 		if (dst_nents < 0) {
 			dev_err(dev, "Invalid number of dst SG.\n");
-			err = ERR_PTR(-EINVAL);
-			goto error_sg;
+			return ERR_PTR(-EINVAL);
 		}
 		dst_nents = (dst_nents == 1) ? 0 : dst_nents;
 	}
@@ -1425,10 +1418,10 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
 		alloc_len += sizeof(struct talitos_desc);
 
 	edesc = kmalloc(alloc_len, GFP_DMA | flags);
-	if (!edesc) {
-		err = ERR_PTR(-ENOMEM);
-		goto error_sg;
-	}
+	if (!edesc)
+		return ERR_PTR(-ENOMEM);
+	if (ivsize)
+		iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE);
 	memset(&edesc->desc, 0, sizeof(edesc->desc));
 
 	edesc->src_nents = src_nents;
@@ -1445,10 +1438,6 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
 						     DMA_BIDIRECTIONAL);
 	}
 	return edesc;
-error_sg:
-	if (iv_dma)
-		dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
-	return err;
 }
 
 static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq, u8 *iv,
-- 
2.13.3


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

* [PATCH v4 2/2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK
  2019-01-08  6:56 [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() Christophe Leroy
@ 2019-01-08  6:56 ` Christophe Leroy
  2019-01-08  9:48   ` Horia Geanta
  2019-01-08  9:47 ` [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() Horia Geanta
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Christophe Leroy @ 2019-01-08  6:56 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller, Horia Geanta
  Cc: linuxppc-dev, linux-crypto, stable, linux-kernel

[    2.364486] WARNING: CPU: 0 PID: 60 at ./arch/powerpc/include/asm/io.h:837 dma_nommu_map_page+0x44/0xd4
[    2.373579] CPU: 0 PID: 60 Comm: cryptomgr_test Tainted: G        W         4.20.0-rc5-00560-g6bfb52e23a00-dirty #531
[    2.384740] NIP:  c000c540 LR: c000c584 CTR: 00000000
[    2.389743] REGS: c95abab0 TRAP: 0700   Tainted: G        W          (4.20.0-rc5-00560-g6bfb52e23a00-dirty)
[    2.400042] MSR:  00029032 <EE,ME,IR,DR,RI>  CR: 24042204  XER: 00000000
[    2.406669]
[    2.406669] GPR00: c02f2244 c95abb60 c6262990 c95abd80 0000256a 00000001 00000001 00000001
[    2.406669] GPR08: 00000000 00002000 00000010 00000010 24042202 00000000 00000100 c95abd88
[    2.406669] GPR16: 00000000 c05569d4 00000001 00000010 c95abc88 c0615664 00000004 00000000
[    2.406669] GPR24: 00000010 c95abc88 c95abc88 00000000 c61ae210 c7ff6d40 c61ae210 00003d68
[    2.441559] NIP [c000c540] dma_nommu_map_page+0x44/0xd4
[    2.446720] LR [c000c584] dma_nommu_map_page+0x88/0xd4
[    2.451762] Call Trace:
[    2.454195] [c95abb60] [82000808] 0x82000808 (unreliable)
[    2.459572] [c95abb80] [c02f2244] talitos_edesc_alloc+0xbc/0x3c8
[    2.465493] [c95abbb0] [c02f2600] ablkcipher_edesc_alloc+0x4c/0x5c
[    2.471606] [c95abbd0] [c02f4ed0] ablkcipher_encrypt+0x20/0x64
[    2.477389] [c95abbe0] [c02023b0] __test_skcipher+0x4bc/0xa08
[    2.483049] [c95abe00] [c0204b60] test_skcipher+0x2c/0xcc
[    2.488385] [c95abe20] [c0204c48] alg_test_skcipher+0x48/0xbc
[    2.494064] [c95abe40] [c0205cec] alg_test+0x164/0x2e8
[    2.499142] [c95abf00] [c0200dec] cryptomgr_test+0x48/0x50
[    2.504558] [c95abf10] [c0039ff4] kthread+0xe4/0x110
[    2.509471] [c95abf40] [c000e1d0] ret_from_kernel_thread+0x14/0x1c
[    2.515532] Instruction dump:
[    2.518468] 7c7e1b78 7c9d2378 7cbf2b78 41820054 3d20c076 8089c200 3d20c076 7c84e850
[    2.526127] 8129c204 7c842e70 7f844840 419c0008 <0fe00000> 2f9e0000 54847022 7c84fa14
[    2.533960] ---[ end trace bf78d94af73fe3b8 ]---
[    2.539123] talitos ff020000.crypto: master data transfer error
[    2.544775] talitos ff020000.crypto: TEA error: ISR 0x20000000_00000040
[    2.551625] alg: skcipher: encryption failed on test 1 for ecb-aes-talitos: ret=22

IV cannot be on stack when CONFIG_VMAP_STACK is selected because the stack
cannot be DMA mapped anymore.

This patch copies the IV into the extended descriptor.

Fixes: 4de9d0b547b9 ("crypto: talitos - Add ablkcipher algorithms")
Cc: stable@vger.kernel.org
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 v4: Split in two patches ; made the copy unconditional.

 v3: Using struct edesc buffer.

 v2: Using per-request context.

 drivers/crypto/talitos.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 54d80e7edb86..f8e2c5c3f4eb 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1416,12 +1416,15 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
 	/* if its a ahash, add space for a second desc next to the first one */
 	if (is_sec1 && !dst)
 		alloc_len += sizeof(struct talitos_desc);
+	alloc_len += ivsize;
 
 	edesc = kmalloc(alloc_len, GFP_DMA | flags);
 	if (!edesc)
 		return ERR_PTR(-ENOMEM);
-	if (ivsize)
+	if (ivsize) {
+		iv = memcpy(((u8 *)edesc) + alloc_len - ivsize, iv, ivsize);
 		iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE);
+	}
 	memset(&edesc->desc, 0, sizeof(edesc->desc));
 
 	edesc->src_nents = src_nents;
-- 
2.13.3


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

* Re: [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc()
  2019-01-08  6:56 [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() Christophe Leroy
  2019-01-08  6:56 ` [PATCH v4 2/2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK Christophe Leroy
@ 2019-01-08  9:47 ` Horia Geanta
  2019-01-08  9:51 ` Christophe Leroy
  2019-01-10 14:05 ` Herbert Xu
  3 siblings, 0 replies; 6+ messages in thread
From: Horia Geanta @ 2019-01-08  9:47 UTC (permalink / raw)
  To: Christophe Leroy, Herbert Xu, David S. Miller
  Cc: linuxppc-dev, linux-crypto, stable, linux-kernel

On 1/8/2019 8:56 AM, Christophe Leroy wrote:
> This patch moves the mapping of IV after the kmalloc(). This
> avoids having to unmap in case kmalloc() fails.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Since patch 2/2 is Cc-ing stable, this one should do the same.
Herbert, could you append the commit message before applying it?

Thanks,
Horia

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

* Re: [PATCH v4 2/2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK
  2019-01-08  6:56 ` [PATCH v4 2/2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK Christophe Leroy
@ 2019-01-08  9:48   ` Horia Geanta
  0 siblings, 0 replies; 6+ messages in thread
From: Horia Geanta @ 2019-01-08  9:48 UTC (permalink / raw)
  To: Christophe Leroy, Herbert Xu, David S. Miller
  Cc: linuxppc-dev, linux-crypto, stable, linux-kernel

On 1/8/2019 8:56 AM, Christophe Leroy wrote:
> [    2.364486] WARNING: CPU: 0 PID: 60 at ./arch/powerpc/include/asm/io.h:837 dma_nommu_map_page+0x44/0xd4
> [    2.373579] CPU: 0 PID: 60 Comm: cryptomgr_test Tainted: G        W         4.20.0-rc5-00560-g6bfb52e23a00-dirty #531
> [    2.384740] NIP:  c000c540 LR: c000c584 CTR: 00000000
> [    2.389743] REGS: c95abab0 TRAP: 0700   Tainted: G        W          (4.20.0-rc5-00560-g6bfb52e23a00-dirty)
> [    2.400042] MSR:  00029032 <EE,ME,IR,DR,RI>  CR: 24042204  XER: 00000000
> [    2.406669]
> [    2.406669] GPR00: c02f2244 c95abb60 c6262990 c95abd80 0000256a 00000001 00000001 00000001
> [    2.406669] GPR08: 00000000 00002000 00000010 00000010 24042202 00000000 00000100 c95abd88
> [    2.406669] GPR16: 00000000 c05569d4 00000001 00000010 c95abc88 c0615664 00000004 00000000
> [    2.406669] GPR24: 00000010 c95abc88 c95abc88 00000000 c61ae210 c7ff6d40 c61ae210 00003d68
> [    2.441559] NIP [c000c540] dma_nommu_map_page+0x44/0xd4
> [    2.446720] LR [c000c584] dma_nommu_map_page+0x88/0xd4
> [    2.451762] Call Trace:
> [    2.454195] [c95abb60] [82000808] 0x82000808 (unreliable)
> [    2.459572] [c95abb80] [c02f2244] talitos_edesc_alloc+0xbc/0x3c8
> [    2.465493] [c95abbb0] [c02f2600] ablkcipher_edesc_alloc+0x4c/0x5c
> [    2.471606] [c95abbd0] [c02f4ed0] ablkcipher_encrypt+0x20/0x64
> [    2.477389] [c95abbe0] [c02023b0] __test_skcipher+0x4bc/0xa08
> [    2.483049] [c95abe00] [c0204b60] test_skcipher+0x2c/0xcc
> [    2.488385] [c95abe20] [c0204c48] alg_test_skcipher+0x48/0xbc
> [    2.494064] [c95abe40] [c0205cec] alg_test+0x164/0x2e8
> [    2.499142] [c95abf00] [c0200dec] cryptomgr_test+0x48/0x50
> [    2.504558] [c95abf10] [c0039ff4] kthread+0xe4/0x110
> [    2.509471] [c95abf40] [c000e1d0] ret_from_kernel_thread+0x14/0x1c
> [    2.515532] Instruction dump:
> [    2.518468] 7c7e1b78 7c9d2378 7cbf2b78 41820054 3d20c076 8089c200 3d20c076 7c84e850
> [    2.526127] 8129c204 7c842e70 7f844840 419c0008 <0fe00000> 2f9e0000 54847022 7c84fa14
> [    2.533960] ---[ end trace bf78d94af73fe3b8 ]---
> [    2.539123] talitos ff020000.crypto: master data transfer error
> [    2.544775] talitos ff020000.crypto: TEA error: ISR 0x20000000_00000040
> [    2.551625] alg: skcipher: encryption failed on test 1 for ecb-aes-talitos: ret=22
> 
> IV cannot be on stack when CONFIG_VMAP_STACK is selected because the stack
> cannot be DMA mapped anymore.
> 
> This patch copies the IV into the extended descriptor.
> 
> Fixes: 4de9d0b547b9 ("crypto: talitos - Add ablkcipher algorithms")
> Cc: stable@vger.kernel.org
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Thanks,
Horia

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

* Re: [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc()
  2019-01-08  6:56 [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() Christophe Leroy
  2019-01-08  6:56 ` [PATCH v4 2/2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK Christophe Leroy
  2019-01-08  9:47 ` [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() Horia Geanta
@ 2019-01-08  9:51 ` Christophe Leroy
  2019-01-10 14:05 ` Herbert Xu
  3 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2019-01-08  9:51 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller, Horia Geanta
  Cc: linuxppc-dev, linux-crypto, stable, linux-kernel



Le 08/01/2019 à 07:56, Christophe Leroy a écrit :
> This patch moves the mapping of IV after the kmalloc(). This
> avoids having to unmap in case kmalloc() fails.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Cc: stable@vger.kernel.org

> ---
>   new in v4
> 
>   drivers/crypto/talitos.c | 25 +++++++------------------
>   1 file changed, 7 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
> index 45e20707cef8..54d80e7edb86 100644
> --- a/drivers/crypto/talitos.c
> +++ b/drivers/crypto/talitos.c
> @@ -1361,23 +1361,18 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
>   	struct talitos_private *priv = dev_get_drvdata(dev);
>   	bool is_sec1 = has_ftr_sec1(priv);
>   	int max_len = is_sec1 ? TALITOS1_MAX_DATA_LEN : TALITOS2_MAX_DATA_LEN;
> -	void *err;
>   
>   	if (cryptlen + authsize > max_len) {
>   		dev_err(dev, "length exceeds h/w max limit\n");
>   		return ERR_PTR(-EINVAL);
>   	}
>   
> -	if (ivsize)
> -		iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE);
> -
>   	if (!dst || dst == src) {
>   		src_len = assoclen + cryptlen + authsize;
>   		src_nents = sg_nents_for_len(src, src_len);
>   		if (src_nents < 0) {
>   			dev_err(dev, "Invalid number of src SG.\n");
> -			err = ERR_PTR(-EINVAL);
> -			goto error_sg;
> +			return ERR_PTR(-EINVAL);
>   		}
>   		src_nents = (src_nents == 1) ? 0 : src_nents;
>   		dst_nents = dst ? src_nents : 0;
> @@ -1387,16 +1382,14 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
>   		src_nents = sg_nents_for_len(src, src_len);
>   		if (src_nents < 0) {
>   			dev_err(dev, "Invalid number of src SG.\n");
> -			err = ERR_PTR(-EINVAL);
> -			goto error_sg;
> +			return ERR_PTR(-EINVAL);
>   		}
>   		src_nents = (src_nents == 1) ? 0 : src_nents;
>   		dst_len = assoclen + cryptlen + (encrypt ? authsize : 0);
>   		dst_nents = sg_nents_for_len(dst, dst_len);
>   		if (dst_nents < 0) {
>   			dev_err(dev, "Invalid number of dst SG.\n");
> -			err = ERR_PTR(-EINVAL);
> -			goto error_sg;
> +			return ERR_PTR(-EINVAL);
>   		}
>   		dst_nents = (dst_nents == 1) ? 0 : dst_nents;
>   	}
> @@ -1425,10 +1418,10 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
>   		alloc_len += sizeof(struct talitos_desc);
>   
>   	edesc = kmalloc(alloc_len, GFP_DMA | flags);
> -	if (!edesc) {
> -		err = ERR_PTR(-ENOMEM);
> -		goto error_sg;
> -	}
> +	if (!edesc)
> +		return ERR_PTR(-ENOMEM);
> +	if (ivsize)
> +		iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE);
>   	memset(&edesc->desc, 0, sizeof(edesc->desc));
>   
>   	edesc->src_nents = src_nents;
> @@ -1445,10 +1438,6 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
>   						     DMA_BIDIRECTIONAL);
>   	}
>   	return edesc;
> -error_sg:
> -	if (iv_dma)
> -		dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
> -	return err;
>   }
>   
>   static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq, u8 *iv,
> 

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

* Re: [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc()
  2019-01-08  6:56 [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() Christophe Leroy
                   ` (2 preceding siblings ...)
  2019-01-08  9:51 ` Christophe Leroy
@ 2019-01-10 14:05 ` Herbert Xu
  3 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2019-01-10 14:05 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Horia Geanta, linux-kernel, stable, linux-crypto, linuxppc-dev,
	David S. Miller

On Tue, Jan 08, 2019 at 06:56:46AM +0000, Christophe Leroy wrote:
> This patch moves the mapping of IV after the kmalloc(). This
> avoids having to unmap in case kmalloc() fails.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
>  new in v4
> 
>  drivers/crypto/talitos.c | 25 +++++++------------------
>  1 file changed, 7 insertions(+), 18 deletions(-)

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

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-08  6:56 [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() Christophe Leroy
2019-01-08  6:56 ` [PATCH v4 2/2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK Christophe Leroy
2019-01-08  9:48   ` Horia Geanta
2019-01-08  9:47 ` [PATCH v4 1/2] crypto: talitos - reorder code in talitos_edesc_alloc() Horia Geanta
2019-01-08  9:51 ` Christophe Leroy
2019-01-10 14:05 ` Herbert Xu

LinuxPPC-Dev Archive on lore.kernel.org

Archives are clonable: git clone --mirror https://lore.kernel.org/linuxppc-dev/0 linuxppc-dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linuxppc-dev linuxppc-dev/ https://lore.kernel.org/linuxppc-dev \
		linuxppc-dev@lists.ozlabs.org linuxppc-dev@ozlabs.org linuxppc-dev@archiver.kernel.org
	public-inbox-index linuxppc-dev


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.ozlabs.lists.linuxppc-dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox