linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: dcp - fix scatterlist linearization for hash
@ 2020-02-25 15:05 Dragos Rosioru (OSS)
  2020-02-25 19:13 ` Horia Geanta
  2020-03-06  1:49 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Dragos Rosioru (OSS) @ 2020-02-25 15:05 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller, Shawn Guo, Sascha Hauer
  Cc: linux-kernel, linux-crypto, linux-arm-kernel, Horia Geanta,
	Marek Vasut, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team

From: Rosioru Dragos <dragos.rosioru@nxp.com>

The incorrect traversal of the scatterlist, during the linearization phase
lead to computing the hash value of the wrong input buffer.
New implementation uses scatterwalk_map_and_copy()
to address this issue.

Cc: <stable@vger.kernel.org>
Fixes: 15b59e7c3733 ("crypto: mxs - Add Freescale MXS DCP driver")
Signed-off-by: Rosioru Dragos <dragos.rosioru@nxp.com>
---
 drivers/crypto/mxs-dcp.c | 58 +++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 30 deletions(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 435ac1c..d845302 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -20,6 +20,7 @@
 #include <crypto/sha.h>
 #include <crypto/internal/hash.h>
 #include <crypto/internal/skcipher.h>
+#include <crypto/scatterwalk.h>
 
 #define DCP_MAX_CHANS	4
 #define DCP_BUF_SZ	PAGE_SIZE
@@ -611,49 +612,46 @@ static int dcp_sha_req_to_buf(struct crypto_async_request *arq)
 	struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm);
 	struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req);
 	struct hash_alg_common *halg = crypto_hash_alg_common(tfm);
-	const int nents = sg_nents(req->src);
 
 	uint8_t *in_buf = sdcp->coh->sha_in_buf;
 	uint8_t *out_buf = sdcp->coh->sha_out_buf;
 
-	uint8_t *src_buf;
-
 	struct scatterlist *src;
 
-	unsigned int i, len, clen;
+	unsigned int i, len, clen, oft = 0;
 	int ret;
 
 	int fin = rctx->fini;
 	if (fin)
 		rctx->fini = 0;
 
-	for_each_sg(req->src, src, nents, i) {
-		src_buf = sg_virt(src);
-		len = sg_dma_len(src);
-
-		do {
-			if (actx->fill + len > DCP_BUF_SZ)
-				clen = DCP_BUF_SZ - actx->fill;
-			else
-				clen = len;
-
-			memcpy(in_buf + actx->fill, src_buf, clen);
-			len -= clen;
-			src_buf += clen;
-			actx->fill += clen;
+	src = req->src;
+	len = req->nbytes;
 
-			/*
-			 * If we filled the buffer and still have some
-			 * more data, submit the buffer.
-			 */
-			if (len && actx->fill == DCP_BUF_SZ) {
-				ret = mxs_dcp_run_sha(req);
-				if (ret)
-					return ret;
-				actx->fill = 0;
-				rctx->init = 0;
-			}
-		} while (len);
+	while (len) {
+		if (actx->fill + len > DCP_BUF_SZ)
+			clen = DCP_BUF_SZ - actx->fill;
+		else
+			clen = len;
+
+		scatterwalk_map_and_copy(in_buf + actx->fill, src, oft, clen,
+					 0);
+
+		len -= clen;
+		oft += clen;
+		actx->fill += clen;
+
+		/*
+		 * If we filled the buffer and still have some
+		 * more data, submit the buffer.
+		 */
+		if (len && actx->fill == DCP_BUF_SZ) {
+			ret = mxs_dcp_run_sha(req);
+			if (ret)
+				return ret;
+			actx->fill = 0;
+			rctx->init = 0;
+		}
 	}
 
 	if (fin) {
-- 
2.7.4


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

* Re: [PATCH] crypto: dcp - fix scatterlist linearization for hash
  2020-02-25 15:05 [PATCH] crypto: dcp - fix scatterlist linearization for hash Dragos Rosioru (OSS)
@ 2020-02-25 19:13 ` Horia Geanta
  2020-03-06  1:49 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Horia Geanta @ 2020-02-25 19:13 UTC (permalink / raw)
  To: Dragos Rosioru (OSS),
	Herbert Xu, David S. Miller, Shawn Guo, Sascha Hauer
  Cc: linux-kernel, linux-crypto, linux-arm-kernel, Marek Vasut,
	Pengutronix Kernel Team, Fabio Estevam, dl-linux-imx

On 2/25/2020 5:06 PM, Dragos Rosioru (OSS) wrote:
> From: Rosioru Dragos <dragos.rosioru@nxp.com>
> 
> The incorrect traversal of the scatterlist, during the linearization phase
> lead to computing the hash value of the wrong input buffer.
> New implementation uses scatterwalk_map_and_copy()
> to address this issue.
> 
> Cc: <stable@vger.kernel.org>
> Fixes: 15b59e7c3733 ("crypto: mxs - Add Freescale MXS DCP driver")
> Signed-off-by: Rosioru Dragos <dragos.rosioru@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>

Thanks,
Horia

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

* Re: [PATCH] crypto: dcp - fix scatterlist linearization for hash
  2020-02-25 15:05 [PATCH] crypto: dcp - fix scatterlist linearization for hash Dragos Rosioru (OSS)
  2020-02-25 19:13 ` Horia Geanta
@ 2020-03-06  1:49 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2020-03-06  1:49 UTC (permalink / raw)
  To: Dragos Rosioru (OSS)
  Cc: David S. Miller, Shawn Guo, Sascha Hauer, linux-kernel,
	linux-crypto, linux-arm-kernel, Horia Geanta, Marek Vasut,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team

On Tue, Feb 25, 2020 at 05:05:52PM +0200, Dragos Rosioru (OSS) wrote:
> From: Rosioru Dragos <dragos.rosioru@nxp.com>
> 
> The incorrect traversal of the scatterlist, during the linearization phase
> lead to computing the hash value of the wrong input buffer.
> New implementation uses scatterwalk_map_and_copy()
> to address this issue.
> 
> Cc: <stable@vger.kernel.org>
> Fixes: 15b59e7c3733 ("crypto: mxs - Add Freescale MXS DCP driver")
> Signed-off-by: Rosioru Dragos <dragos.rosioru@nxp.com>
> ---
>  drivers/crypto/mxs-dcp.c | 58 +++++++++++++++++++++++-------------------------
>  1 file changed, 28 insertions(+), 30 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] 3+ messages in thread

end of thread, other threads:[~2020-03-06  1:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-25 15:05 [PATCH] crypto: dcp - fix scatterlist linearization for hash Dragos Rosioru (OSS)
2020-02-25 19:13 ` Horia Geanta
2020-03-06  1:49 ` Herbert Xu

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).