Skip to contentSkip to conversation

crypto/ecc: increase frame warning limit

PATCH In review [email protected] 3 participants 3 messages Jul 12, 2024 – Jul 13, 2024 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto/ecc: increase frame warning limit

From: Peng Hao <[email protected]>

When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.

crypto/ecc.c:1129:13: error: stack frame size (2136) exceeds limit (2048) in 'ecc_point_double_jacobian' [-Werror,-Wframe-larger-than] static void ecc_point_double_jacobian(u64 *x1, u64 *y1, u64 *z1,

            ^

Since many arrays are defined in ecc_point_double_jacobian, they occupy a lot of stack space, but are difficult to adjust. just increase the limit for configurations that have KASAN or KCSAN enabled.

---
 crypto/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
crypto/Makefile +6 -0
index edbbaa3ffef5..ab7bebaa7218 100644
@@ -190,6 +190,12 @@ obj-$(CONFIG_CRYPTO_ECC) += ecc.o
 obj-$(CONFIG_CRYPTO_ESSIV) += essiv.o
 obj-$(CONFIG_CRYPTO_CURVE25519) += curve25519-generic.o
 
+ifneq ($(CONFIG_FRAME_WARN),0)
+ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y)
+CFLAGS_ecc.o = -Wframe-larger-than=2776
+endif
+endif
+
 ecdh_generic-y += ecdh.o
 ecdh_generic-y += ecdh_helper.o
 obj-$(CONFIG_CRYPTO_ECDH) += ecdh_generic.o
Signature · 1 line
2.27.0
#1 lore raw

(cc Arnd, Nathan)

Quoted 24 lines · On Fri, 12 Jul 2024 at 13:37, <[email protected]> wrote:

From: Peng Hao <[email protected]>

When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.

crypto/ecc.c:1129:13: error: stack frame size (2136) exceeds limit (2048) in 'ecc_point_double_jacobian' [-Werror,-Wframe-larger-than] static void ecc_point_double_jacobian(u64 *x1, u64 *y1, u64 *z1,

            ^

Since many arrays are defined in ecc_point_double_jacobian, they occupy a lot of stack space, but are difficult to adjust. just increase the limit for configurations that have KASAN or KCSAN enabled.

---
 crypto/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
crypto/Makefile +0 -0
index edbbaa3ffef5..ab7bebaa7218 100644

crypto/Makefile obj-$(CONFIG_CRYPTO_ECC) += ecc.o · line 198

Quoted 9 lines
crypto/Makefile +6 -0
@@ -190,6 +190,12 @@ obj-$(CONFIG_CRYPTO_ECC) += ecc.o
 obj-$(CONFIG_CRYPTO_ESSIV) += essiv.o
 obj-$(CONFIG_CRYPTO_CURVE25519) += curve25519-generic.o
 
+ifneq ($(CONFIG_FRAME_WARN),0)
+ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y)
+CFLAGS_ecc.o = -Wframe-larger-than=2776
+endif
+endif
+

I don't think this is an acceptable workaround - this applies to all functions in the file, which call into each other as well.

It would be better if we could figure out why the stack blows up like this on clang, which could be related to inlining behavior or other compiler heuristics that prevent stack allocations from being reused.

Arnd, Nathan: any insights?

#2 lore raw

Hi Ard,

Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · On Fri, 12 Jul 2024 at 13:37, <[email protected]> wrote:

From: Peng Hao <[email protected]>

When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.

crypto/ecc.c:1129:13: error: stack frame size (2136) exceeds limit (2048) in 'ecc_point_double_jacobian' [-Werror,-Wframe-larger-than] static void ecc_point_double_jacobian(u64 *x1, u64 *y1, u64 *z1,

            ^

Since many arrays are defined in ecc_point_double_jacobian, they occupy a lot of stack space, but are difficult to adjust. just increase the limit for configurations that have KASAN or KCSAN enabled.

---
 crypto/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)
crypto/Makefile +0 -0
index edbbaa3ffef5..ab7bebaa7218 100644
@@ -190,6 +190,12 @@ obj-$(CONFIG_CRYPTO_ECC) += ecc.o
 obj-$(CONFIG_CRYPTO_ESSIV) += essiv.o
 obj-$(CONFIG_CRYPTO_CURVE25519) += curve25519-generic.o
 
Quoted 9 lines

crypto/Makefile obj-$(CONFIG_CRYPTO_ECC) += ecc.o · line 198

Quoted 6 lines
crypto/Makefile +6 -0
+ifneq ($(CONFIG_FRAME_WARN),0)
+ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y)
+CFLAGS_ecc.o = -Wframe-larger-than=2776
+endif
+endif
+

I don't think this is an acceptable workaround - this applies to all functions in the file, which call into each other as well.

Agreed, as I stated on a review of another patch this same submitter sent for a similar warning in infiniband:

https://lore.kernel.org/20240709212608.GA1649561@thelio-3990X/

Unfortunately, this appears to be getting copy and pasted from AMDGPU, which needed it for their horrible DCN code that comes from some other upstream source.

Quoted 3 lines

It would be better if we could figure out why the stack blows up like this on clang, which could be related to inlining behavior or other compiler heuristics that prevent stack allocations from being reused.

I asked for further details like configuration in my second message in that thread and it never materialized:

https://lore.kernel.org/20240709212608.GA1649561@thelio-3990X/

I suspect this might just be a KASAN_STACK warning, which is known to generate high stack usage warnings (as noted in the Kconfig text),we will have to wait for confirmation:

https://github.com/ClangBuiltLinux/linux/issues/39

Cheers,
Nathan