All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: caam: print debugging hex dumps after unmapping
@ 2019-05-16 14:24 Sascha Hauer
  2019-05-17  6:11 ` Horia Geanta
  2019-05-23  6:52 ` [PATCH] crypto: caam - " Herbert Xu
  0 siblings, 2 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-05-16 14:24 UTC (permalink / raw)
  To: linux-crypto; +Cc: Horia Geantă, kernel, Sascha Hauer

For encryption the destination pointer was still mapped, so the hex dump
may be wrong. The IV still contained the input IV while printing instead
of the output IV as intended.

For decryption the destination pointer was still mapped, so the hex dump
may be wrong. The IV dump was correct.

Do the hex dumps consistenly after the buffers have been unmapped and
in case of IV copied to their final destination.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/crypto/caam/caamalg.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 3e23d4b2cce2..a992ff56fd15 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -1009,15 +1009,6 @@ static void skcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
 	if (err)
 		caam_jr_strstatus(jrdev, err);
 
-#ifdef DEBUG
-	print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
-		       DUMP_PREFIX_ADDRESS, 16, 4, req->iv,
-		       edesc->src_nents > 1 ? 100 : ivsize, 1);
-#endif
-	caam_dump_sg(KERN_ERR, "dst    @" __stringify(__LINE__)": ",
-		     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
-		     edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
-
 	skcipher_unmap(jrdev, edesc, req);
 
 	/*
@@ -1028,6 +1019,15 @@ static void skcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
 		scatterwalk_map_and_copy(req->iv, req->dst, req->cryptlen -
 					 ivsize, ivsize, 0);
 
+#ifdef DEBUG
+	print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
+		       DUMP_PREFIX_ADDRESS, 16, 4, req->iv,
+		       edesc->src_nents > 1 ? 100 : ivsize, 1);
+#endif
+	caam_dump_sg(KERN_ERR, "dst    @" __stringify(__LINE__)": ",
+		     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
+		     edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
+
 	kfree(edesc);
 
 	skcipher_request_complete(req, err);
@@ -1049,6 +1049,8 @@ static void skcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
 	if (err)
 		caam_jr_strstatus(jrdev, err);
 
+	skcipher_unmap(jrdev, edesc, req);
+
 #ifdef DEBUG
 	print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
 		       DUMP_PREFIX_ADDRESS, 16, 4, req->iv, ivsize, 1);
@@ -1057,7 +1059,6 @@ static void skcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
 		     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
 		     edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
 
-	skcipher_unmap(jrdev, edesc, req);
 	kfree(edesc);
 
 	skcipher_request_complete(req, err);
-- 
2.20.1


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

* Re: [PATCH] crypto: caam: print debugging hex dumps after unmapping
  2019-05-16 14:24 [PATCH] crypto: caam: print debugging hex dumps after unmapping Sascha Hauer
@ 2019-05-17  6:11 ` Horia Geanta
  2019-05-23  6:52 ` [PATCH] crypto: caam - " Herbert Xu
  1 sibling, 0 replies; 6+ messages in thread
From: Horia Geanta @ 2019-05-17  6:11 UTC (permalink / raw)
  To: Sascha Hauer, linux-crypto; +Cc: kernel

On 5/16/2019 5:24 PM, Sascha Hauer wrote:
> For encryption the destination pointer was still mapped, so the hex dump
> may be wrong. The IV still contained the input IV while printing instead
> of the output IV as intended.
> 
> For decryption the destination pointer was still mapped, so the hex dump
> may be wrong. The IV dump was correct.
> 
> Do the hex dumps consistenly after the buffers have been unmapped and
> in case of IV copied to their final destination.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Thanks,
Horia

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

* Re: [PATCH] crypto: caam - print debugging hex dumps after unmapping
  2019-05-16 14:24 [PATCH] crypto: caam: print debugging hex dumps after unmapping Sascha Hauer
  2019-05-17  6:11 ` Horia Geanta
@ 2019-05-23  6:52 ` Herbert Xu
  1 sibling, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2019-05-23  6:52 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: linux-crypto, Horia Geantă, kernel

On Thu, May 16, 2019 at 04:24:42PM +0200, Sascha Hauer wrote:
> For encryption the destination pointer was still mapped, so the hex dump
> may be wrong. The IV still contained the input IV while printing instead
> of the output IV as intended.
> 
> For decryption the destination pointer was still mapped, so the hex dump
> may be wrong. The IV dump was correct.
> 
> Do the hex dumps consistenly after the buffers have been unmapped and
> in case of IV copied to their final destination.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
> ---
>  drivers/crypto/caam/caamalg.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)

Patch 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

* Re: [PATCH] crypto: caam: print debugging hex dumps after unmapping
  2019-05-15 16:27 ` Horia Geanta
@ 2019-05-16 14:25   ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-05-16 14:25 UTC (permalink / raw)
  To: Horia Geanta; +Cc: linux-crypto, kernel

On Wed, May 15, 2019 at 04:27:51PM +0000, Horia Geanta wrote:
> On 5/15/2019 4:13 PM, Sascha Hauer wrote:
> > The debugging hex dumps in skcipher_encrypt_done() and
> > skcipher_decrypt_done() are printed while the request is still DMA
> > mapped. This results in bogus hex dumps with things like mixtures
> > between plain text and cipher text. Unmap first before printing.
> > 
> The description is not accurate.
> req->iv is no longer DMA mapped since commit 115957bb3e59 ("crypto: caam - fix
> IV DMA mapping and updating"), so this is not related to IV DMA unmapping vs.
> print order.
> 
> Currently:
> -for encryption, printed req->iv contains the input IV; copy of output IV into
> req->iv is done further below
> -for decryption, printed req->iv should be correct, since output IV is copied
> into req->iv in skcipher_decrypt(), before accelerator runs
> 
> Could you please resubmit with updated message?

Just did that.

Thanks
 Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH] crypto: caam: print debugging hex dumps after unmapping
  2019-05-15 13:13 [PATCH] crypto: caam: " Sascha Hauer
@ 2019-05-15 16:27 ` Horia Geanta
  2019-05-16 14:25   ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Horia Geanta @ 2019-05-15 16:27 UTC (permalink / raw)
  To: Sascha Hauer, linux-crypto; +Cc: kernel

On 5/15/2019 4:13 PM, Sascha Hauer wrote:
> The debugging hex dumps in skcipher_encrypt_done() and
> skcipher_decrypt_done() are printed while the request is still DMA
> mapped. This results in bogus hex dumps with things like mixtures
> between plain text and cipher text. Unmap first before printing.
> 
The description is not accurate.
req->iv is no longer DMA mapped since commit 115957bb3e59 ("crypto: caam - fix
IV DMA mapping and updating"), so this is not related to IV DMA unmapping vs.
print order.

Currently:
-for encryption, printed req->iv contains the input IV; copy of output IV into
req->iv is done further below
-for decryption, printed req->iv should be correct, since output IV is copied
into req->iv in skcipher_decrypt(), before accelerator runs

Could you please resubmit with updated message?

Thanks,
Horia

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

* [PATCH] crypto: caam: print debugging hex dumps after unmapping
@ 2019-05-15 13:13 Sascha Hauer
  2019-05-15 16:27 ` Horia Geanta
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2019-05-15 13:13 UTC (permalink / raw)
  To: linux-crypto; +Cc: Horia Geantă, kernel, Sascha Hauer

The debugging hex dumps in skcipher_encrypt_done() and
skcipher_decrypt_done() are printed while the request is still DMA
mapped. This results in bogus hex dumps with things like mixtures
between plain text and cipher text. Unmap first before printing.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/crypto/caam/caamalg.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 3e23d4b2cce2..a992ff56fd15 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -1009,15 +1009,6 @@ static void skcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
 	if (err)
 		caam_jr_strstatus(jrdev, err);
 
-#ifdef DEBUG
-	print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
-		       DUMP_PREFIX_ADDRESS, 16, 4, req->iv,
-		       edesc->src_nents > 1 ? 100 : ivsize, 1);
-#endif
-	caam_dump_sg(KERN_ERR, "dst    @" __stringify(__LINE__)": ",
-		     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
-		     edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
-
 	skcipher_unmap(jrdev, edesc, req);
 
 	/*
@@ -1028,6 +1019,15 @@ static void skcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
 		scatterwalk_map_and_copy(req->iv, req->dst, req->cryptlen -
 					 ivsize, ivsize, 0);
 
+#ifdef DEBUG
+	print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
+		       DUMP_PREFIX_ADDRESS, 16, 4, req->iv,
+		       edesc->src_nents > 1 ? 100 : ivsize, 1);
+#endif
+	caam_dump_sg(KERN_ERR, "dst    @" __stringify(__LINE__)": ",
+		     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
+		     edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
+
 	kfree(edesc);
 
 	skcipher_request_complete(req, err);
@@ -1049,6 +1049,8 @@ static void skcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
 	if (err)
 		caam_jr_strstatus(jrdev, err);
 
+	skcipher_unmap(jrdev, edesc, req);
+
 #ifdef DEBUG
 	print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
 		       DUMP_PREFIX_ADDRESS, 16, 4, req->iv, ivsize, 1);
@@ -1057,7 +1059,6 @@ static void skcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
 		     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
 		     edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
 
-	skcipher_unmap(jrdev, edesc, req);
 	kfree(edesc);
 
 	skcipher_request_complete(req, err);
-- 
2.20.1


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

end of thread, other threads:[~2019-05-23  6:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-16 14:24 [PATCH] crypto: caam: print debugging hex dumps after unmapping Sascha Hauer
2019-05-17  6:11 ` Horia Geanta
2019-05-23  6:52 ` [PATCH] crypto: caam - " Herbert Xu
  -- strict thread matches above, loose matches on Subject: below --
2019-05-15 13:13 [PATCH] crypto: caam: " Sascha Hauer
2019-05-15 16:27 ` Horia Geanta
2019-05-16 14:25   ` Sascha Hauer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.