aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-06-10 23:28:34 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-06-12 10:45:09 -0400
commit81781e681551ed3f56c9202e9adc7ef941cba654 (patch)
tree9f9577f0edb591a80e6d5c39b23061839f5dca30 /drivers/crypto
parent1a5b951f256d772a4ab758bda3a0667b788c0d2a (diff)
crypto: picoxcell - Clamp AEAD SG list by input length
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>
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/picoxcell_crypto.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/drivers/crypto/picoxcell_crypto.c b/drivers/crypto/picoxcell_crypto.c
index 9eb27c71cedf..c2fd860745ad 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)
318 struct spacc_ddt *src_ddt, *dst_ddt; 318 struct spacc_ddt *src_ddt, *dst_ddt;
319 unsigned ivsize = crypto_aead_ivsize(crypto_aead_reqtfm(areq)); 319 unsigned ivsize = crypto_aead_ivsize(crypto_aead_reqtfm(areq));
320 unsigned nents = sg_count(areq->src, areq->cryptlen); 320 unsigned nents = sg_count(areq->src, areq->cryptlen);
321 unsigned total;
321 dma_addr_t iv_addr; 322 dma_addr_t iv_addr;
322 struct scatterlist *cur; 323 struct scatterlist *cur;
323 int i, dst_ents, src_ents, assoc_ents; 324 int i, dst_ents, src_ents, assoc_ents;
@@ -361,11 +362,18 @@ static int spacc_aead_make_ddts(struct spacc_req *req, u8 *giv)
361 * Map the associated data. For decryption we don't copy the 362 * Map the associated data. For decryption we don't copy the
362 * associated data. 363 * associated data.
363 */ 364 */
365 total = areq->assoclen;
364 for_each_sg(areq->assoc, cur, assoc_ents, i) { 366 for_each_sg(areq->assoc, cur, assoc_ents, i) {
365 ddt_set(src_ddt++, sg_dma_address(cur), sg_dma_len(cur)); 367 unsigned len = sg_dma_len(cur);
368
369 if (len > total)
370 len = total;
371
372 total -= len;
373
374 ddt_set(src_ddt++, sg_dma_address(cur), len);
366 if (req->is_encrypt) 375 if (req->is_encrypt)
367 ddt_set(dst_ddt++, sg_dma_address(cur), 376 ddt_set(dst_ddt++, sg_dma_address(cur), len);
368 sg_dma_len(cur));
369 } 377 }
370 ddt_set(src_ddt++, iv_addr, ivsize); 378 ddt_set(src_ddt++, iv_addr, ivsize);
371 379