All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] crypto: picoxcell - Clamp AEAD SG list by input length
@ 2015-06-11  3:27 Herbert Xu
  2015-06-11  3:28 ` [PATCH 1/3] crypto: picoxcell - Include linux/sizes.h Herbert Xu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Herbert Xu @ 2015-06-11  3:27 UTC (permalink / raw)
  To: Jamie Iles, Linux Crypto Mailing List

Hi:

This series of patches adds a couple of minor fixes to picoxcell,
but most importantly allows it to be used with the new AEAD interface
by ensuring that it clamps the AD SG list by the AD length.

This is compile-tested only.

Cheers,
-- 
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] 5+ messages in thread

* [PATCH 1/3] crypto: picoxcell - Include linux/sizes.h
  2015-06-11  3:27 [PATCH 0/3] crypto: picoxcell - Clamp AEAD SG list by input length Herbert Xu
@ 2015-06-11  3:28 ` Herbert Xu
  2015-06-11  3:28 ` [PATCH 2/3] crypto: picoxcell - Make use of sg_nents_for_len Herbert Xu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2015-06-11  3:28 UTC (permalink / raw)
  To: Jamie Iles, Linux Crypto Mailing List

This driver uses SZ_64K so it should include linux/sizes.h rather
than relying on others to pull it in for it.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 drivers/crypto/picoxcell_crypto.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/picoxcell_crypto.c b/drivers/crypto/picoxcell_crypto.c
index eb2a0ca..aabf9d4 100644
--- a/drivers/crypto/picoxcell_crypto.c
+++ b/drivers/crypto/picoxcell_crypto.c
@@ -40,6 +40,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/scatterlist.h>
 #include <linux/sched.h>
+#include <linux/sizes.h>
 #include <linux/slab.h>
 #include <linux/timer.h>
 

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

* [PATCH 2/3] crypto: picoxcell - Make use of sg_nents_for_len
  2015-06-11  3:27 [PATCH 0/3] crypto: picoxcell - Clamp AEAD SG list by input length Herbert Xu
  2015-06-11  3:28 ` [PATCH 1/3] crypto: picoxcell - Include linux/sizes.h Herbert Xu
@ 2015-06-11  3:28 ` Herbert Xu
  2015-06-11  3:28 ` [PATCH 3/3] crypto: picoxcell - Clamp AEAD SG list by input length Herbert Xu
  2015-06-17  8:23 ` [PATCH 0/3] " Jamie Iles
  3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2015-06-11  3:28 UTC (permalink / raw)
  To: Jamie Iles, Linux Crypto Mailing List

This patch makes use of the new sg_nents_for_len helper to replace
the custom sg_count function.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

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

diff --git a/drivers/crypto/picoxcell_crypto.c b/drivers/crypto/picoxcell_crypto.c
index aabf9d4..9eb27c7 100644
--- a/drivers/crypto/picoxcell_crypto.c
+++ b/drivers/crypto/picoxcell_crypto.c
@@ -262,18 +262,9 @@ static unsigned spacc_load_ctx(struct spacc_generic_ctx *ctx,
 }
 
 /* Count the number of scatterlist entries in a scatterlist. */
-static int sg_count(struct scatterlist *sg_list, int nbytes)
+static inline int sg_count(struct scatterlist *sg_list, int nbytes)
 {
-	struct scatterlist *sg = sg_list;
-	int sg_nents = 0;
-
-	while (nbytes > 0) {
-		++sg_nents;
-		nbytes -= sg->length;
-		sg = sg_next(sg);
-	}
-
-	return sg_nents;
+	return sg_nents_for_len(sg_list, nbytes);
 }
 
 static inline void ddt_set(struct spacc_ddt *ddt, dma_addr_t phys, size_t len)

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

* [PATCH 3/3] crypto: picoxcell - Clamp AEAD SG list by input length
  2015-06-11  3:27 [PATCH 0/3] crypto: picoxcell - Clamp AEAD SG list by input length Herbert Xu
  2015-06-11  3:28 ` [PATCH 1/3] crypto: picoxcell - Include linux/sizes.h Herbert Xu
  2015-06-11  3:28 ` [PATCH 2/3] crypto: picoxcell - Make use of sg_nents_for_len Herbert Xu
@ 2015-06-11  3:28 ` Herbert Xu
  2015-06-17  8:23 ` [PATCH 0/3] " Jamie Iles
  3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2015-06-11  3:28 UTC (permalink / raw)
  To: Jamie Iles, Linux Crypto Mailing List

Currently the driver assumes that the SG list contains exactly
the number of bytes required.  This assumption is incorrect.
    
Up until now this has been harmless.  However with the new AEAD
interface this now breaks as the AD SG list contains more bytes
than just the AD.
    
This patch fixes this by always clamping the AD SG list by the
specified AD length.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 drivers/crypto/picoxcell_crypto.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/picoxcell_crypto.c b/drivers/crypto/picoxcell_crypto.c
index 9eb27c7..c2fd860 100644
--- a/drivers/crypto/picoxcell_crypto.c
+++ b/drivers/crypto/picoxcell_crypto.c
@@ -318,6 +318,7 @@ static int spacc_aead_make_ddts(struct spacc_req *req, u8 *giv)
 	struct spacc_ddt *src_ddt, *dst_ddt;
 	unsigned ivsize = crypto_aead_ivsize(crypto_aead_reqtfm(areq));
 	unsigned nents = sg_count(areq->src, areq->cryptlen);
+	unsigned total;
 	dma_addr_t iv_addr;
 	struct scatterlist *cur;
 	int i, dst_ents, src_ents, assoc_ents;
@@ -361,11 +362,18 @@ static int spacc_aead_make_ddts(struct spacc_req *req, u8 *giv)
 	 * Map the associated data. For decryption we don't copy the
 	 * associated data.
 	 */
+	total = areq->assoclen;
 	for_each_sg(areq->assoc, cur, assoc_ents, i) {
-		ddt_set(src_ddt++, sg_dma_address(cur), sg_dma_len(cur));
+		unsigned len = sg_dma_len(cur);
+
+		if (len > total)
+			len = total;
+
+		total -= len;
+
+		ddt_set(src_ddt++, sg_dma_address(cur), len);
 		if (req->is_encrypt)
-			ddt_set(dst_ddt++, sg_dma_address(cur),
-				sg_dma_len(cur));
+			ddt_set(dst_ddt++, sg_dma_address(cur), len);
 	}
 	ddt_set(src_ddt++, iv_addr, ivsize);
 

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

* Re: [PATCH 0/3] crypto: picoxcell - Clamp AEAD SG list by input length
  2015-06-11  3:27 [PATCH 0/3] crypto: picoxcell - Clamp AEAD SG list by input length Herbert Xu
                   ` (2 preceding siblings ...)
  2015-06-11  3:28 ` [PATCH 3/3] crypto: picoxcell - Clamp AEAD SG list by input length Herbert Xu
@ 2015-06-17  8:23 ` Jamie Iles
  3 siblings, 0 replies; 5+ messages in thread
From: Jamie Iles @ 2015-06-17  8:23 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Jamie Iles, Linux Crypto Mailing List

On Thu, Jun 11, 2015 at 11:27:03AM +0800, Herbert Xu wrote:
> Hi:
> 
> This series of patches adds a couple of minor fixes to picoxcell,
> but most importantly allows it to be used with the new AEAD interface
> by ensuring that it clamps the AD SG list by the AD length.
> 
> This is compile-tested only.

Looks good, thanks Herbert!

Acked-by: Jamie Iles <jamie@jamieiles.com>

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

end of thread, other threads:[~2015-06-17  8:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-11  3:27 [PATCH 0/3] crypto: picoxcell - Clamp AEAD SG list by input length Herbert Xu
2015-06-11  3:28 ` [PATCH 1/3] crypto: picoxcell - Include linux/sizes.h Herbert Xu
2015-06-11  3:28 ` [PATCH 2/3] crypto: picoxcell - Make use of sg_nents_for_len Herbert Xu
2015-06-11  3:28 ` [PATCH 3/3] crypto: picoxcell - Clamp AEAD SG list by input length Herbert Xu
2015-06-17  8:23 ` [PATCH 0/3] " Jamie Iles

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.