Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

Pull crypto fixes from Herbert Xu:
"This fixes the following issues:

- Fix pointer size when caam is used with AArch64 boot loader on
AArch32 kernel.

- Fix ahash state corruption in marvell driver.

- Fix buggy algif_aed tag handling.

- Prevent mcryptd from being used with incompatible algorithms which
can cause crashes"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
crypto: algif_aead - fix uninitialized variable warning
crypto: mcryptd - Check mcryptd algorithm compatibility
crypto: algif_aead - fix AEAD tag memory handling
crypto: caam - fix pointer size for AArch64 boot loader, AArch32 kernel
crypto: marvell - Don't corrupt state of an STD req for re-stepped ahash
crypto: marvell - Don't copy hash operation twice into the SRAM

+57 -37
+37 -22
crypto/algif_aead.c
··· 81 81 { 82 82 unsigned as = crypto_aead_authsize(crypto_aead_reqtfm(&ctx->aead_req)); 83 83 84 - return ctx->used >= ctx->aead_assoclen + as; 84 + /* 85 + * The minimum amount of memory needed for an AEAD cipher is 86 + * the AAD and in case of decryption the tag. 87 + */ 88 + return ctx->used >= ctx->aead_assoclen + (ctx->enc ? 0 : as); 85 89 } 86 90 87 91 static void aead_reset_ctx(struct aead_ctx *ctx) ··· 420 416 unsigned int i, reqlen = GET_REQ_SIZE(tfm); 421 417 int err = -ENOMEM; 422 418 unsigned long used; 423 - size_t outlen; 419 + size_t outlen = 0; 424 420 size_t usedpages = 0; 425 421 426 422 lock_sock(sk); ··· 430 426 goto unlock; 431 427 } 432 428 433 - used = ctx->used; 434 - outlen = used; 435 - 436 429 if (!aead_sufficient_data(ctx)) 437 430 goto unlock; 431 + 432 + used = ctx->used; 433 + if (ctx->enc) 434 + outlen = used + as; 435 + else 436 + outlen = used - as; 438 437 439 438 req = sock_kmalloc(sk, reqlen, GFP_KERNEL); 440 439 if (unlikely(!req)) ··· 452 445 aead_request_set_ad(req, ctx->aead_assoclen); 453 446 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 454 447 aead_async_cb, sk); 455 - used -= ctx->aead_assoclen + (ctx->enc ? as : 0); 448 + used -= ctx->aead_assoclen; 456 449 457 450 /* take over all tx sgls from ctx */ 458 451 areq->tsgl = sock_kmalloc(sk, sizeof(*areq->tsgl) * sgl->cur, ··· 468 461 areq->tsgls = sgl->cur; 469 462 470 463 /* create rx sgls */ 471 - while (iov_iter_count(&msg->msg_iter)) { 464 + while (outlen > usedpages && iov_iter_count(&msg->msg_iter)) { 472 465 size_t seglen = min_t(size_t, iov_iter_count(&msg->msg_iter), 473 466 (outlen - usedpages)); 474 467 ··· 498 491 499 492 last_rsgl = rsgl; 500 493 501 - /* we do not need more iovecs as we have sufficient memory */ 502 - if (outlen <= usedpages) 503 - break; 504 - 505 494 iov_iter_advance(&msg->msg_iter, err); 506 495 } 507 - err = -EINVAL; 496 + 508 497 /* ensure output buffer is sufficiently large */ 509 - if (usedpages < outlen) 510 - goto free; 498 + if (usedpages < outlen) { 499 + err = -EINVAL; 500 + goto unlock; 501 + } 511 502 512 503 aead_request_set_crypt(req, areq->tsgl, areq->first_rsgl.sgl.sg, used, 513 504 areq->iv); ··· 576 571 goto unlock; 577 572 } 578 573 574 + /* data length provided by caller via sendmsg/sendpage */ 579 575 used = ctx->used; 580 576 581 577 /* ··· 591 585 if (!aead_sufficient_data(ctx)) 592 586 goto unlock; 593 587 594 - outlen = used; 588 + /* 589 + * Calculate the minimum output buffer size holding the result of the 590 + * cipher operation. When encrypting data, the receiving buffer is 591 + * larger by the tag length compared to the input buffer as the 592 + * encryption operation generates the tag. For decryption, the input 593 + * buffer provides the tag which is consumed resulting in only the 594 + * plaintext without a buffer for the tag returned to the caller. 595 + */ 596 + if (ctx->enc) 597 + outlen = used + as; 598 + else 599 + outlen = used - as; 595 600 596 601 /* 597 602 * The cipher operation input data is reduced by the associated data 598 603 * length as this data is processed separately later on. 599 604 */ 600 - used -= ctx->aead_assoclen + (ctx->enc ? as : 0); 605 + used -= ctx->aead_assoclen; 601 606 602 607 /* convert iovecs of output buffers into scatterlists */ 603 - while (iov_iter_count(&msg->msg_iter)) { 608 + while (outlen > usedpages && iov_iter_count(&msg->msg_iter)) { 604 609 size_t seglen = min_t(size_t, iov_iter_count(&msg->msg_iter), 605 610 (outlen - usedpages)); 606 611 ··· 638 621 639 622 last_rsgl = rsgl; 640 623 641 - /* we do not need more iovecs as we have sufficient memory */ 642 - if (outlen <= usedpages) 643 - break; 644 624 iov_iter_advance(&msg->msg_iter, err); 645 625 } 646 626 647 - err = -EINVAL; 648 627 /* ensure output buffer is sufficiently large */ 649 - if (usedpages < outlen) 628 + if (usedpages < outlen) { 629 + err = -EINVAL; 650 630 goto unlock; 631 + } 651 632 652 633 sg_mark_end(sgl->sg + sgl->cur - 1); 653 634 aead_request_set_crypt(&ctx->aead_req, sgl->sg, ctx->first_rsgl.sgl.sg,
+12 -7
crypto/mcryptd.c
··· 254 254 goto out; 255 255 } 256 256 257 - static inline void mcryptd_check_internal(struct rtattr **tb, u32 *type, 257 + static inline bool mcryptd_check_internal(struct rtattr **tb, u32 *type, 258 258 u32 *mask) 259 259 { 260 260 struct crypto_attr_type *algt; 261 261 262 262 algt = crypto_get_attr_type(tb); 263 263 if (IS_ERR(algt)) 264 - return; 265 - if ((algt->type & CRYPTO_ALG_INTERNAL)) 266 - *type |= CRYPTO_ALG_INTERNAL; 267 - if ((algt->mask & CRYPTO_ALG_INTERNAL)) 268 - *mask |= CRYPTO_ALG_INTERNAL; 264 + return false; 265 + 266 + *type |= algt->type & CRYPTO_ALG_INTERNAL; 267 + *mask |= algt->mask & CRYPTO_ALG_INTERNAL; 268 + 269 + if (*type & *mask & CRYPTO_ALG_INTERNAL) 270 + return true; 271 + else 272 + return false; 269 273 } 270 274 271 275 static int mcryptd_hash_init_tfm(struct crypto_tfm *tfm) ··· 496 492 u32 mask = 0; 497 493 int err; 498 494 499 - mcryptd_check_internal(tb, &type, &mask); 495 + if (!mcryptd_check_internal(tb, &type, &mask)) 496 + return -EINVAL; 500 497 501 498 halg = ahash_attr_alg(tb[1], type, mask); 502 499 if (IS_ERR(halg))
+3 -2
drivers/crypto/caam/ctrl.c
··· 558 558 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel, 559 559 * long pointers in master configuration register 560 560 */ 561 - clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK, MCFGR_AWCACHE_CACH | 562 - MCFGR_AWCACHE_BUFF | MCFGR_WDENABLE | MCFGR_LARGE_BURST | 561 + clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK | MCFGR_LONG_PTR, 562 + MCFGR_AWCACHE_CACH | MCFGR_AWCACHE_BUFF | 563 + MCFGR_WDENABLE | MCFGR_LARGE_BURST | 563 564 (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0)); 564 565 565 566 /*
+5 -6
drivers/crypto/marvell/hash.c
··· 168 168 mv_cesa_adjust_op(engine, &creq->op_tmpl); 169 169 memcpy_toio(engine->sram, &creq->op_tmpl, sizeof(creq->op_tmpl)); 170 170 171 - digsize = crypto_ahash_digestsize(crypto_ahash_reqtfm(req)); 172 - for (i = 0; i < digsize / 4; i++) 173 - writel_relaxed(creq->state[i], engine->regs + CESA_IVDIG(i)); 174 - 175 - mv_cesa_adjust_op(engine, &creq->op_tmpl); 176 - memcpy_toio(engine->sram, &creq->op_tmpl, sizeof(creq->op_tmpl)); 171 + if (!sreq->offset) { 172 + digsize = crypto_ahash_digestsize(crypto_ahash_reqtfm(req)); 173 + for (i = 0; i < digsize / 4; i++) 174 + writel_relaxed(creq->state[i], engine->regs + CESA_IVDIG(i)); 175 + } 177 176 178 177 if (creq->cache_ptr) 179 178 memcpy_toio(engine->sram + CESA_SA_DATA_SRAM_OFFSET,