diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-10-12 12:32:53 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-10-12 12:32:53 -0400 |
commit | 73a752cce2d4e9f704b097e63a79c68d71f7992d (patch) | |
tree | 5ff822f5ebc3944c84fc70b55abab6ffbda998b8 | |
parent | 0de50ea7b5c9e232dcd1cc07c014509c324ff1b8 (diff) | |
parent | b61907bb42409adf9b3120f741af7c57dd7e3db2 (diff) |
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu:
- fix crashes in skcipher/shash from zero-length input.
- fix softirq GFP_KERNEL allocation in shash_setkey_unaligned.
- error path bug fix in xts create function.
- fix compiler warning regressions in axis and stm32
* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
crypto: shash - Fix zero-length shash ahash digest crash
crypto: skcipher - Fix crash on zero-length input
crypto: shash - Fix a sleep-in-atomic bug in shash_setkey_unaligned
crypto: xts - Fix an error handling path in 'create()'
crypto: stm32 - Try to fix hash padding
crypto: axis - hide an unused variable
-rw-r--r-- | crypto/shash.c | 10 | ||||
-rw-r--r-- | crypto/skcipher.c | 17 | ||||
-rw-r--r-- | crypto/xts.c | 6 | ||||
-rw-r--r-- | drivers/crypto/axis/artpec6_crypto.c | 4 | ||||
-rw-r--r-- | drivers/crypto/stm32/stm32-hash.c | 15 |
5 files changed, 32 insertions, 20 deletions
diff --git a/crypto/shash.c b/crypto/shash.c index 5e31c8d776df..325a14da5827 100644 --- a/crypto/shash.c +++ b/crypto/shash.c | |||
@@ -41,7 +41,7 @@ static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key, | |||
41 | int err; | 41 | int err; |
42 | 42 | ||
43 | absize = keylen + (alignmask & ~(crypto_tfm_ctx_alignment() - 1)); | 43 | absize = keylen + (alignmask & ~(crypto_tfm_ctx_alignment() - 1)); |
44 | buffer = kmalloc(absize, GFP_KERNEL); | 44 | buffer = kmalloc(absize, GFP_ATOMIC); |
45 | if (!buffer) | 45 | if (!buffer) |
46 | return -ENOMEM; | 46 | return -ENOMEM; |
47 | 47 | ||
@@ -275,12 +275,14 @@ static int shash_async_finup(struct ahash_request *req) | |||
275 | 275 | ||
276 | int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc) | 276 | int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc) |
277 | { | 277 | { |
278 | struct scatterlist *sg = req->src; | ||
279 | unsigned int offset = sg->offset; | ||
280 | unsigned int nbytes = req->nbytes; | 278 | unsigned int nbytes = req->nbytes; |
279 | struct scatterlist *sg; | ||
280 | unsigned int offset; | ||
281 | int err; | 281 | int err; |
282 | 282 | ||
283 | if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) { | 283 | if (nbytes && |
284 | (sg = req->src, offset = sg->offset, | ||
285 | nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset))) { | ||
284 | void *data; | 286 | void *data; |
285 | 287 | ||
286 | data = kmap_atomic(sg_page(sg)); | 288 | data = kmap_atomic(sg_page(sg)); |
diff --git a/crypto/skcipher.c b/crypto/skcipher.c index 4faa0fd53b0c..d5692e35fab1 100644 --- a/crypto/skcipher.c +++ b/crypto/skcipher.c | |||
@@ -426,14 +426,9 @@ static int skcipher_copy_iv(struct skcipher_walk *walk) | |||
426 | 426 | ||
427 | static int skcipher_walk_first(struct skcipher_walk *walk) | 427 | static int skcipher_walk_first(struct skcipher_walk *walk) |
428 | { | 428 | { |
429 | walk->nbytes = 0; | ||
430 | |||
431 | if (WARN_ON_ONCE(in_irq())) | 429 | if (WARN_ON_ONCE(in_irq())) |
432 | return -EDEADLK; | 430 | return -EDEADLK; |
433 | 431 | ||
434 | if (unlikely(!walk->total)) | ||
435 | return 0; | ||
436 | |||
437 | walk->buffer = NULL; | 432 | walk->buffer = NULL; |
438 | if (unlikely(((unsigned long)walk->iv & walk->alignmask))) { | 433 | if (unlikely(((unsigned long)walk->iv & walk->alignmask))) { |
439 | int err = skcipher_copy_iv(walk); | 434 | int err = skcipher_copy_iv(walk); |
@@ -452,10 +447,15 @@ static int skcipher_walk_skcipher(struct skcipher_walk *walk, | |||
452 | { | 447 | { |
453 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | 448 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
454 | 449 | ||
450 | walk->total = req->cryptlen; | ||
451 | walk->nbytes = 0; | ||
452 | |||
453 | if (unlikely(!walk->total)) | ||
454 | return 0; | ||
455 | |||
455 | scatterwalk_start(&walk->in, req->src); | 456 | scatterwalk_start(&walk->in, req->src); |
456 | scatterwalk_start(&walk->out, req->dst); | 457 | scatterwalk_start(&walk->out, req->dst); |
457 | 458 | ||
458 | walk->total = req->cryptlen; | ||
459 | walk->iv = req->iv; | 459 | walk->iv = req->iv; |
460 | walk->oiv = req->iv; | 460 | walk->oiv = req->iv; |
461 | 461 | ||
@@ -509,6 +509,11 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk, | |||
509 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); | 509 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); |
510 | int err; | 510 | int err; |
511 | 511 | ||
512 | walk->nbytes = 0; | ||
513 | |||
514 | if (unlikely(!walk->total)) | ||
515 | return 0; | ||
516 | |||
512 | walk->flags &= ~SKCIPHER_WALK_PHYS; | 517 | walk->flags &= ~SKCIPHER_WALK_PHYS; |
513 | 518 | ||
514 | scatterwalk_start(&walk->in, req->src); | 519 | scatterwalk_start(&walk->in, req->src); |
diff --git a/crypto/xts.c b/crypto/xts.c index d86c11a8c882..e31828ed0046 100644 --- a/crypto/xts.c +++ b/crypto/xts.c | |||
@@ -554,8 +554,10 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb) | |||
554 | ctx->name[len - 1] = 0; | 554 | ctx->name[len - 1] = 0; |
555 | 555 | ||
556 | if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, | 556 | if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, |
557 | "xts(%s)", ctx->name) >= CRYPTO_MAX_ALG_NAME) | 557 | "xts(%s)", ctx->name) >= CRYPTO_MAX_ALG_NAME) { |
558 | return -ENAMETOOLONG; | 558 | err = -ENAMETOOLONG; |
559 | goto err_drop_spawn; | ||
560 | } | ||
559 | } else | 561 | } else |
560 | goto err_drop_spawn; | 562 | goto err_drop_spawn; |
561 | 563 | ||
diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c index d9fbbf01062b..0f9754e07719 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c | |||
@@ -349,8 +349,6 @@ struct artpec6_crypto_aead_req_ctx { | |||
349 | /* The crypto framework makes it hard to avoid this global. */ | 349 | /* The crypto framework makes it hard to avoid this global. */ |
350 | static struct device *artpec6_crypto_dev; | 350 | static struct device *artpec6_crypto_dev; |
351 | 351 | ||
352 | static struct dentry *dbgfs_root; | ||
353 | |||
354 | #ifdef CONFIG_FAULT_INJECTION | 352 | #ifdef CONFIG_FAULT_INJECTION |
355 | static DECLARE_FAULT_ATTR(artpec6_crypto_fail_status_read); | 353 | static DECLARE_FAULT_ATTR(artpec6_crypto_fail_status_read); |
356 | static DECLARE_FAULT_ATTR(artpec6_crypto_fail_dma_array_full); | 354 | static DECLARE_FAULT_ATTR(artpec6_crypto_fail_dma_array_full); |
@@ -2984,6 +2982,8 @@ struct dbgfs_u32 { | |||
2984 | char *desc; | 2982 | char *desc; |
2985 | }; | 2983 | }; |
2986 | 2984 | ||
2985 | static struct dentry *dbgfs_root; | ||
2986 | |||
2987 | static void artpec6_crypto_init_debugfs(void) | 2987 | static void artpec6_crypto_init_debugfs(void) |
2988 | { | 2988 | { |
2989 | dbgfs_root = debugfs_create_dir("artpec6_crypto", NULL); | 2989 | dbgfs_root = debugfs_create_dir("artpec6_crypto", NULL); |
diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c index b585ce54a802..4835dd4a9e50 100644 --- a/drivers/crypto/stm32/stm32-hash.c +++ b/drivers/crypto/stm32/stm32-hash.c | |||
@@ -553,9 +553,9 @@ static int stm32_hash_dma_send(struct stm32_hash_dev *hdev) | |||
553 | { | 553 | { |
554 | struct stm32_hash_request_ctx *rctx = ahash_request_ctx(hdev->req); | 554 | struct stm32_hash_request_ctx *rctx = ahash_request_ctx(hdev->req); |
555 | struct scatterlist sg[1], *tsg; | 555 | struct scatterlist sg[1], *tsg; |
556 | int err = 0, len = 0, reg, ncp; | 556 | int err = 0, len = 0, reg, ncp = 0; |
557 | unsigned int i; | 557 | unsigned int i; |
558 | const u32 *buffer = (const u32 *)rctx->buffer; | 558 | u32 *buffer = (void *)rctx->buffer; |
559 | 559 | ||
560 | rctx->sg = hdev->req->src; | 560 | rctx->sg = hdev->req->src; |
561 | rctx->total = hdev->req->nbytes; | 561 | rctx->total = hdev->req->nbytes; |
@@ -620,10 +620,13 @@ static int stm32_hash_dma_send(struct stm32_hash_dev *hdev) | |||
620 | reg |= HASH_CR_DMAA; | 620 | reg |= HASH_CR_DMAA; |
621 | stm32_hash_write(hdev, HASH_CR, reg); | 621 | stm32_hash_write(hdev, HASH_CR, reg); |
622 | 622 | ||
623 | for (i = 0; i < DIV_ROUND_UP(ncp, sizeof(u32)); i++) | 623 | if (ncp) { |
624 | stm32_hash_write(hdev, HASH_DIN, buffer[i]); | 624 | memset(buffer + ncp, 0, |
625 | 625 | DIV_ROUND_UP(ncp, sizeof(u32)) - ncp); | |
626 | stm32_hash_set_nblw(hdev, ncp); | 626 | writesl(hdev->io_base + HASH_DIN, buffer, |
627 | DIV_ROUND_UP(ncp, sizeof(u32))); | ||
628 | } | ||
629 | stm32_hash_set_nblw(hdev, DIV_ROUND_UP(ncp, sizeof(u32))); | ||
627 | reg = stm32_hash_read(hdev, HASH_STR); | 630 | reg = stm32_hash_read(hdev, HASH_STR); |
628 | reg |= HASH_STR_DCAL; | 631 | reg |= HASH_STR_DCAL; |
629 | stm32_hash_write(hdev, HASH_STR, reg); | 632 | stm32_hash_write(hdev, HASH_STR, reg); |