Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1472590 > unrolled thread

(none)

Started byIaroslav Gridin <voker57@gmail.com>
First post2016-08-30 18:00 +0200
Last post2016-08-30 18:00 +0200
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  (none) Iaroslav Gridin <voker57@gmail.com> - 2016-08-30 18:00 +0200
    [PATCH 2/4] crypto: qce: Avoid repeat hash finalization Iaroslav Gridin <voker57@gmail.com> - 2016-08-30 18:00 +0200
    [PATCH 3/4] crypto: qce: Ensure QCE receives no zero-sized updates Iaroslav Gridin <voker57@gmail.com> - 2016-08-30 18:00 +0200

#1472590 — (none)

FromIaroslav Gridin <voker57@gmail.com>
Date2016-08-30 18:00 +0200
Subject(none)
Message-ID<sbTC9-6Nf-9@gated-at.bofh.it>
This set of patches fixes QCE digest code, preventing lockups and incorrect results.

[toc] | [next] | [standalone]


#1472591 — [PATCH 2/4] crypto: qce: Avoid repeat hash finalization

FromIaroslav Gridin <voker57@gmail.com>
Date2016-08-30 18:00 +0200
Subject[PATCH 2/4] crypto: qce: Avoid repeat hash finalization
Message-ID<sbTCa-6Nf-33@gated-at.bofh.it>
In reply to#1472590
From: Voker57 <voker57@gmail.com>

Calling QCE finalization when hash have already been finalized causes
a lockup. Avoid it by introducing finalized flag.
Signed-off-by: Iaroslav Gridin <voker57@gmail.com>
---
 drivers/crypto/qce/sha.c | 6 ++++++
 drivers/crypto/qce/sha.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c
index a124bb9..a068d39 100644
--- a/drivers/crypto/qce/sha.c
+++ b/drivers/crypto/qce/sha.c
@@ -139,6 +139,7 @@ static int qce_ahash_init(struct ahash_request *req)
 	rctx->first_blk = true;
 	rctx->last_blk = false;
 	rctx->flags = tmpl->alg_flags;
+	rctx->finalized = false;
 	memcpy(rctx->digest, std_iv, sizeof(rctx->digest));
 
 	return 0;
@@ -314,7 +315,12 @@ static int qce_ahash_final(struct ahash_request *req)
 	if (!rctx->buflen)
 		return 0;
 
+	/* If hash is already been finalized, don't do anything */
+	if (rctx->finalized)
+		return 0;
+
 	rctx->last_blk = true;
+	rctx->finalized = true;
 
 	rctx->src_orig = req->src;
 	rctx->nbytes_orig = req->nbytes;
diff --git a/drivers/crypto/qce/sha.h b/drivers/crypto/qce/sha.h
index 236bb5e9..b24568f 100644
--- a/drivers/crypto/qce/sha.h
+++ b/drivers/crypto/qce/sha.h
@@ -59,6 +59,7 @@ struct qce_sha_reqctx {
 	u64 count;
 	bool first_blk;
 	bool last_blk;
+	bool finalized;
 	struct scatterlist sg[2];
 	u8 *authkey;
 	unsigned int authklen;
-- 
2.9.3

[toc] | [prev] | [next] | [standalone]


#1472594 — [PATCH 3/4] crypto: qce: Ensure QCE receives no zero-sized updates

FromIaroslav Gridin <voker57@gmail.com>
Date2016-08-30 18:00 +0200
Subject[PATCH 3/4] crypto: qce: Ensure QCE receives no zero-sized updates
Message-ID<sbTC9-6Nf-15@gated-at.bofh.it>
In reply to#1472590
From: Voker57 <voker57@gmail.com>

Zero-sized updates lock QCE, so ensure there's always some data left
for the final update, up to blocksize.
Signed-off-by: Iaroslav Gridin <voker57@gmail.com>
---
 drivers/crypto/qce/sha.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c
index a068d39..f199f28 100644
--- a/drivers/crypto/qce/sha.c
+++ b/drivers/crypto/qce/sha.c
@@ -240,9 +240,11 @@ static int qce_ahash_update(struct ahash_request *req)
 	struct qce_device *qce = tmpl->qce;
 	struct scatterlist *sg_last, *sg;
 	unsigned int total, len;
+	unsigned int tmpbuflen = 0;
 	unsigned int hash_later;
 	unsigned int nbytes;
 	unsigned int blocksize;
+	unsigned int src_offset;
 
 	blocksize = crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
 	rctx->count += req->nbytes;
@@ -265,21 +267,30 @@ static int qce_ahash_update(struct ahash_request *req)
 	 * if we have data from previous update copy them on buffer. The old
 	 * data will be combined with current request bytes.
 	 */
-	if (rctx->buflen)
+	if (rctx->buflen) {
 		memcpy(rctx->tmpbuf, rctx->buf, rctx->buflen);
+		tmpbuflen = rctx->buflen;
+	}
 
 	/* calculate how many bytes will be hashed later */
 	hash_later = total % blocksize;
-	if (hash_later) {
-		unsigned int src_offset = req->nbytes - hash_later;
-		scatterwalk_map_and_copy(rctx->buf, req->src, src_offset,
-					 hash_later, 0);
-	}
+	/* ensure we always have something on buffer */
+	if (hash_later == 0)
+		hash_later = blocksize;
+	src_offset = req->nbytes - hash_later;
+	scatterwalk_map_and_copy(rctx->buf, req->src, src_offset,
+				 hash_later, 0);
+	rctx->buflen = hash_later;
 
 	/* here nbytes is multiple of blocksize */
 	nbytes = total - hash_later;
 
-	len = rctx->buflen;
+	len = tmpbuflen;
+
+	/* Zero-length update is a no-op */
+	if (nbytes == 0)
+		return 0;
+
 	sg = sg_last = req->src;
 
 	while (len < nbytes && sg) {
@@ -293,15 +304,14 @@ static int qce_ahash_update(struct ahash_request *req)
 
 	sg_mark_end(sg_last);
 
-	if (rctx->buflen) {
+	if (tmpbuflen) {
 		sg_init_table(rctx->sg, 2);
-		sg_set_buf(rctx->sg, rctx->tmpbuf, rctx->buflen);
+		sg_set_buf(rctx->sg, rctx->tmpbuf, tmpbuflen);
 		sg_chain(rctx->sg, 2, req->src);
 		req->src = rctx->sg;
 	}
 
 	req->nbytes = nbytes;
-	rctx->buflen = hash_later;
 
 	return qce->async_req_enqueue(tmpl->qce, &req->base);
 }
-- 
2.9.3

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web