Skip to contentSkip to conversation

crypto: ccree - reduce kernel stack usage with clang

PATCH In review Arnd Bergmann 3 participants 3 messages Mar 14, 2019 – Mar 22, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: ccree - reduce kernel stack usage with clang

Building with clang for a 32-bit architecture runs over the stack frame limit in the setkey function:

drivers/crypto/ccree/cc_cipher.c:318:12: error: stack frame size of 1152 bytes in function 'cc_cipher_setkey' [-Werror,-Wframe-larger-than=]

The problem is that there are two large variables: the temporary 'tmp' array and the SHASH_DESC_ON_STACK() declaration. Moving the first into the block in which it is used reduces the total frame size to 768 bytes, which seems more reasonable and is under the warning limit.

Fixes 63ee04c8b491 ("crypto: ccree - add skcipher support")
---
 drivers/crypto/ccree/cc_cipher.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccree/cc_cipher.c +1 -1
index d9c17078517b..0abcdc224ab0 100644
@@ -321,7 +321,6 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
 	struct crypto_tfm *tfm = crypto_skcipher_tfm(sktfm);
 	struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);
 	struct device *dev = drvdata_to_dev(ctx_p->drvdata);
-	u32 tmp[DES3_EDE_EXPKEY_WORDS];
 	struct cc_crypto_alg *cc_alg =
 			container_of(tfm->__crt_alg, struct cc_crypto_alg,
 				     skcipher_alg.base);
@@ -347,6 +346,7 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
 	 * HW does the expansion on its own.
 	 */
 	if (ctx_p->flow_mode == S_DIN_to_DES) {
+		u32 tmp[DES3_EDE_EXPKEY_WORDS];
 		if (keylen == DES3_EDE_KEY_SIZE &&
 		    __des3_ede_setkey(tmp, &tfm->crt_flags, key,
 				      DES3_EDE_KEY_SIZE)) {
Signature · 1 line
2.20.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Arnd Bergmann

Building with clang for a 32-bit architecture runs over the stack frame limit in the setkey function:

Quoted 8 lines

drivers/crypto/ccree/cc_cipher.c:318:12: error: stack frame size of 1152 bytes in function 'cc_cipher_setkey' [-Werror,-Wframe-larger-than=]

The problem is that there are two large variables: the temporary 'tmp' array and the SHASH_DESC_ON_STACK() declaration. Moving the first into the block in which it is used reduces the total frame size to 768 bytes, which seems more reasonable and is under the warning limit.

Thank you , Ard.

I will also revisit splitting that function to further reduce stack usage after I finish tackling the fallout of the new testmgr... :-)

Gilad

Signature · 4 lines
Gilad Ben-Yossef
Chief Coffee Drinker

values of β will give rise to dom!
maintainer
#2 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

Building with clang for a 32-bit architecture runs over the stack frame limit in the setkey function:

drivers/crypto/ccree/cc_cipher.c:318:12: error: stack frame size of 1152 bytes in function 'cc_cipher_setkey' [-Werror,-Wframe-larger-than=]

The problem is that there are two large variables: the temporary 'tmp' array and the SHASH_DESC_ON_STACK() declaration. Moving the first into the block in which it is used reduces the total frame size to 768 bytes, which seems more reasonable and is under the warning limit.

Quoted 5 lines
Fixes 63ee04c8b491 ("crypto: ccree - add skcipher support")
---
 drivers/crypto/ccree/cc_cipher.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt