diff mbox series

[v2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK

Message ID 7f27d91e7e78d8aac28e8b6c600fd874b7d5be9f.1544686398.git.christophe.leroy@c-s.fr (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show
Series [v2] crypto: talitos - fix ablkcipher for CONFIG_VMAP_STACK | expand

Commit Message

Christophe Leroy Dec. 13, 2018, 7:34 a.m. UTC
[    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 from areq->info into the request context.

Fixes: 4de9d0b547b9 ("crypto: talitos - Add ablkcipher algorithms")
Cc: stable@vger.kernel.org
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 v2: Using per-request context.

 drivers/crypto/talitos.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Christophe Leroy Dec. 14, 2018, 5:25 p.m. UTC | #1
Le 14/12/2018 à 02:39, Sasha Levin a écrit :
> Hi,
> 
> [This is an automated email]
> 
> This commit has been processed because it contains a "Fixes:" tag,
> fixing commit: 4de9d0b547b9 crypto: talitos - Add ablkcipher algorithms.
> 
> The bot has tested the following trees: v4.19.9, v4.14.88, v4.9.145, v4.4.167, v3.18.129,
> 
> v4.19.9: Build OK!
> v4.14.88: Failed to apply! Possible dependencies:
>      2e13ce0812c6 ("crypto: talitos - DMA map key in setkey()")
>      9a655608a468 ("crypto: talitos - simplify tests in ipsec_esp()")
>      da9de146ebd9 ("crypto: talitos - remove to_talitos_ptr_len()")
> 
> v4.9.145: Failed to apply! Possible dependencies:
>      2e13ce0812c6 ("crypto: talitos - DMA map key in setkey()")
>      9a655608a468 ("crypto: talitos - simplify tests in ipsec_esp()")
>      da9de146ebd9 ("crypto: talitos - remove to_talitos_ptr_len()")
> 
> v4.4.167: Failed to apply! Possible dependencies:
>      246a87cda070 ("crypto: talitos - move mapping helpers before IPSEC functions")
>      2e13ce0812c6 ("crypto: talitos - DMA map key in setkey()")
>      549bd8bc5987 ("crypto: talitos - Implement AEAD for SEC1 using HMAC_SNOOP_NO_AFEU")
>      6a1e8d14156d ("crypto: talitos - making mapping helpers more generic")
>      8e409fe10695 ("crypto: talitos - check return value of sg_nents_for_len")
>      9a655608a468 ("crypto: talitos - simplify tests in ipsec_esp()")
>      b096b544d6c3 ("crypto: talitos - using helpers for all talitos_ptr operations")
>      da9de146ebd9 ("crypto: talitos - remove to_talitos_ptr_len()")
>      e04a61bebc5d ("crypto: talitos - fix memory corruption on SEC2")
> 
> v3.18.129: Failed to apply! Possible dependencies:
>      032d197eaaea ("crypto: talitos - Refactor the sg in/out chain allocation")
>      185eb79f6a65 ("crypto: talitos - Add a helper function to clear j_extent field")
>      20ec9d814e68 ("crypto: sahara - fix spinlock initialization")
>      538caf83374c ("crypto: talitos - helper function for ptr len")
>      5a2bb93f5992 ("crypto: sahara - add support for SHA1/256")
>      5be4d4c94b1f ("crypto: replace scatterwalk_sg_next with sg_next")
>      922f9dc8d366 ("crypto: talitos - fill in talitos descriptor iaw SEC1 or SEC2+")
>      a2b35aa86eea ("crypto: talitos - remove param 'extent' in map_single_talitos_ptr()")
>      a861afbc931b ("crypto: ablkcipher - fixed style errors in ablkcipher.c")
>      aeb4c132f33d ("crypto: talitos - Convert to new AEAD interface")
>      bde9079f3cd5 ("crypto: talitos - avoid out of bound scatterlist iterator")
>      c0c3c89ae347 ("crypto: sahara - replace tasklets with kthread")
>      edc6bd698a4d ("crypto: talitos - talitos_ptr renamed ptr for more lisibility")
>      f129430dd87d ("crypto: nx - Fixing the limit number of bytes to be processed")
> 
> 
> How should we proceed with this patch?

I'll backport it once it is in linux tree.

Christophe

> 
> --
> Thanks,
> Sasha
>
Horia Geanta Dec. 18, 2018, 2:10 p.m. UTC | #2
On 12/13/2018 9:34 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.
> 
Same failure could happen for aead.

> This patch copies the IV from areq->info into the request context.
> 
There is already a per-request structure - talitos_edesc - that should be used
to save the IV.

The best approach to fix the issue (both for ablkcipher and aead) would be to
update talitos_edesc_alloc().

Thanks,
Horia
diff mbox series

Patch

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 6988012deca4..df289758755c 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1664,12 +1664,16 @@  static int common_nonsnoop(struct talitos_edesc *edesc,
 static struct talitos_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request *
 						    areq, bool encrypt)
 {
+	void *req_ctx = ablkcipher_request_ctx(areq);
 	struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
 	struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
 	unsigned int ivsize = crypto_ablkcipher_ivsize(cipher);
 
+	if (ivsize)
+		memcpy(req_ctx, areq->info, ivsize);
+
 	return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst,
-				   areq->info, 0, areq->nbytes, 0, ivsize, 0,
+				   req_ctx, 0, areq->nbytes, 0, ivsize, 0,
 				   areq->base.flags, encrypt);
 }
 
@@ -3066,6 +3070,13 @@  static int talitos_cra_init_ahash(struct crypto_tfm *tfm)
 	return 0;
 }
 
+static int talitos_cra_init_ablkcipher(struct crypto_tfm *tfm)
+{
+	tfm->crt_ablkcipher.reqsize = TALITOS_MAX_IV_LENGTH;
+
+	return talitos_cra_init(tfm);
+}
+
 static void talitos_cra_exit(struct crypto_tfm *tfm)
 {
 	struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
@@ -3149,7 +3160,7 @@  static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
 	switch (t_alg->algt.type) {
 	case CRYPTO_ALG_TYPE_ABLKCIPHER:
 		alg = &t_alg->algt.alg.crypto;
-		alg->cra_init = talitos_cra_init;
+		alg->cra_init = talitos_cra_init_ablkcipher;
 		alg->cra_exit = talitos_cra_exit;
 		alg->cra_type = &crypto_ablkcipher_type;
 		alg->cra_ablkcipher.setkey = ablkcipher_setkey;