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

ubifs: replay: Fix high stack usage

Having two shash descriptors on the stack cause a very significant kernel
stack usage that can cross the warning threshold:

fs/ubifs/replay.c: In function 'authenticate_sleb':
fs/ubifs/replay.c:633:1: error: the frame size of 1144 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]

Normally, gcc optimizes the out, but with CONFIG_CC_OPTIMIZE_FOR_DEBUGGING,
it does not. Splitting the two stack allocations into separate functions
means that they will use the same memory again. In normal configurations
(optimizing for size or performance), those should get inlined and we get
the same behavior as before.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Arnd Bergmann and committed by
Richard Weinberger
eb66eff6 40e020c1

+24 -11
+24 -11
fs/ubifs/replay.c
··· 533 533 return data == 0xFFFFFFFF; 534 534 } 535 535 536 + /* authenticate_sleb_hash and authenticate_sleb_hmac are split out for stack usage */ 537 + static int authenticate_sleb_hash(struct ubifs_info *c, struct shash_desc *log_hash, u8 *hash) 538 + { 539 + SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm); 540 + 541 + hash_desc->tfm = c->hash_tfm; 542 + hash_desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; 543 + 544 + ubifs_shash_copy_state(c, log_hash, hash_desc); 545 + return crypto_shash_final(hash_desc, hash); 546 + } 547 + 548 + static int authenticate_sleb_hmac(struct ubifs_info *c, u8 *hash, u8 *hmac) 549 + { 550 + SHASH_DESC_ON_STACK(hmac_desc, c->hmac_tfm); 551 + 552 + hmac_desc->tfm = c->hmac_tfm; 553 + hmac_desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; 554 + 555 + return crypto_shash_digest(hmac_desc, hash, c->hash_len, hmac); 556 + } 557 + 536 558 /** 537 559 * authenticate_sleb - authenticate one scan LEB 538 560 * @c: UBIFS file-system description object ··· 596 574 597 575 if (snod->type == UBIFS_AUTH_NODE) { 598 576 struct ubifs_auth_node *auth = snod->node; 599 - SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm); 600 - SHASH_DESC_ON_STACK(hmac_desc, c->hmac_tfm); 601 577 602 - hash_desc->tfm = c->hash_tfm; 603 - hash_desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; 604 - 605 - ubifs_shash_copy_state(c, log_hash, hash_desc); 606 - err = crypto_shash_final(hash_desc, hash); 578 + err = authenticate_sleb_hash(c, log_hash, hash); 607 579 if (err) 608 580 goto out; 609 581 610 - hmac_desc->tfm = c->hmac_tfm; 611 - hmac_desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; 612 - err = crypto_shash_digest(hmac_desc, hash, c->hash_len, 613 - hmac); 582 + err = authenticate_sleb_hmac(c, hash, hmac); 614 583 if (err) 615 584 goto out; 616 585