linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: lib/curve25519-hacl64 - Disable KASAN with clang-17 and older
@ 2025-06-09 22:45 Nathan Chancellor
  2025-06-10  9:42 ` Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nathan Chancellor @ 2025-06-09 22:45 UTC (permalink / raw)
  To: Eric Biggers, Jason A. Donenfeld, Ard Biesheuvel
  Cc: linux-crypto, llvm, patches, Nathan Chancellor

After commit 6f110a5e4f99 ("Disable SLUB_TINY for build testing"), which
causes CONFIG_KASAN to be enabled in allmodconfig again, arm64
allmodconfig builds with clang-17 and older show an instance of
-Wframe-larger-than (which breaks the build with CONFIG_WERROR=y):

  lib/crypto/curve25519-hacl64.c:757:6: error: stack frame size (2336) exceeds limit (2048) in 'curve25519_generic' [-Werror,-Wframe-larger-than]
    757 | void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
        |      ^

When KASAN is disabled, the stack usage is roughly quartered:

  lib/crypto/curve25519-hacl64.c:757:6: error: stack frame size (608) exceeds limit (128) in 'curve25519_generic' [-Werror,-Wframe-larger-than]
    757 | void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
        |      ^

Using '-Rpass-analysis=stack-frame-layout' shows the following variables
and many, many 8-byte spills when KASAN is enabled:

  Offset: [SP-144], Type: Variable, Align: 8, Size: 40
  Offset: [SP-464], Type: Variable, Align: 8, Size: 320
  Offset: [SP-784], Type: Variable, Align: 8, Size: 320
  Offset: [SP-864], Type: Variable, Align: 32, Size: 80
  Offset: [SP-896], Type: Variable, Align: 32, Size: 32
  Offset: [SP-1016], Type: Variable, Align: 8, Size: 120

When KASAN is disabled, there are still spills but not at many and the
variables list is smaller:

  Offset: [SP-192], Type: Variable, Align: 32, Size: 80
  Offset: [SP-224], Type: Variable, Align: 32, Size: 32
  Offset: [SP-344], Type: Variable, Align: 8, Size: 120

Disable KASAN for this file when using clang-17 or older to avoid
blowing out the stack, clearing up the warning.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 lib/crypto/Makefile | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile
index 3e79283b617d..18664127ecd6 100644
--- a/lib/crypto/Makefile
+++ b/lib/crypto/Makefile
@@ -35,6 +35,10 @@ obj-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC)	+= libcurve25519-generic.o
 libcurve25519-generic-y				:= curve25519-fiat32.o
 libcurve25519-generic-$(CONFIG_ARCH_SUPPORTS_INT128)	:= curve25519-hacl64.o
 libcurve25519-generic-y				+= curve25519-generic.o
+# clang versions prior to 18 may blow out the stack with KASAN
+ifeq ($(call clang-min-version, 180000),)
+KASAN_SANITIZE_curve25519-hacl64.o := n
+endif
 
 obj-$(CONFIG_CRYPTO_LIB_CURVE25519)		+= libcurve25519.o
 libcurve25519-y					+= curve25519.o

---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250609-curve25519-hacl64-disable-kasan-clang-faf6e97315e4

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: lib/curve25519-hacl64 - Disable KASAN with clang-17 and older
  2025-06-09 22:45 [PATCH] crypto: lib/curve25519-hacl64 - Disable KASAN with clang-17 and older Nathan Chancellor
@ 2025-06-10  9:42 ` Ard Biesheuvel
  2025-06-10 17:41 ` Jason A. Donenfeld
  2025-06-10 18:42 ` Eric Biggers
  2 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2025-06-10  9:42 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Eric Biggers, Jason A. Donenfeld, linux-crypto, llvm, patches

On Tue, 10 Jun 2025 at 00:45, Nathan Chancellor <nathan@kernel.org> wrote:
>
> After commit 6f110a5e4f99 ("Disable SLUB_TINY for build testing"), which
> causes CONFIG_KASAN to be enabled in allmodconfig again, arm64
> allmodconfig builds with clang-17 and older show an instance of
> -Wframe-larger-than (which breaks the build with CONFIG_WERROR=y):
>
>   lib/crypto/curve25519-hacl64.c:757:6: error: stack frame size (2336) exceeds limit (2048) in 'curve25519_generic' [-Werror,-Wframe-larger-than]
>     757 | void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
>         |      ^
>
> When KASAN is disabled, the stack usage is roughly quartered:
>
>   lib/crypto/curve25519-hacl64.c:757:6: error: stack frame size (608) exceeds limit (128) in 'curve25519_generic' [-Werror,-Wframe-larger-than]
>     757 | void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
>         |      ^
>
> Using '-Rpass-analysis=stack-frame-layout' shows the following variables
> and many, many 8-byte spills when KASAN is enabled:
>
>   Offset: [SP-144], Type: Variable, Align: 8, Size: 40
>   Offset: [SP-464], Type: Variable, Align: 8, Size: 320
>   Offset: [SP-784], Type: Variable, Align: 8, Size: 320
>   Offset: [SP-864], Type: Variable, Align: 32, Size: 80
>   Offset: [SP-896], Type: Variable, Align: 32, Size: 32
>   Offset: [SP-1016], Type: Variable, Align: 8, Size: 120
>
> When KASAN is disabled, there are still spills but not at many and the
> variables list is smaller:
>
>   Offset: [SP-192], Type: Variable, Align: 32, Size: 80
>   Offset: [SP-224], Type: Variable, Align: 32, Size: 32
>   Offset: [SP-344], Type: Variable, Align: 8, Size: 120
>
> Disable KASAN for this file when using clang-17 or older to avoid
> blowing out the stack, clearing up the warning.
>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  lib/crypto/Makefile | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile
> index 3e79283b617d..18664127ecd6 100644
> --- a/lib/crypto/Makefile
> +++ b/lib/crypto/Makefile
> @@ -35,6 +35,10 @@ obj-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC)  += libcurve25519-generic.o
>  libcurve25519-generic-y                                := curve25519-fiat32.o
>  libcurve25519-generic-$(CONFIG_ARCH_SUPPORTS_INT128)   := curve25519-hacl64.o
>  libcurve25519-generic-y                                += curve25519-generic.o
> +# clang versions prior to 18 may blow out the stack with KASAN
> +ifeq ($(call clang-min-version, 180000),)
> +KASAN_SANITIZE_curve25519-hacl64.o := n
> +endif
>
>  obj-$(CONFIG_CRYPTO_LIB_CURVE25519)            += libcurve25519.o
>  libcurve25519-y                                        += curve25519.o
>
> ---
> base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
> change-id: 20250609-curve25519-hacl64-disable-kasan-clang-faf6e97315e4
>
> Best regards,
> --
> Nathan Chancellor <nathan@kernel.org>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: lib/curve25519-hacl64 - Disable KASAN with clang-17 and older
  2025-06-09 22:45 [PATCH] crypto: lib/curve25519-hacl64 - Disable KASAN with clang-17 and older Nathan Chancellor
  2025-06-10  9:42 ` Ard Biesheuvel
@ 2025-06-10 17:41 ` Jason A. Donenfeld
  2025-06-10 18:42 ` Eric Biggers
  2 siblings, 0 replies; 4+ messages in thread
From: Jason A. Donenfeld @ 2025-06-10 17:41 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Eric Biggers, Ard Biesheuvel, linux-crypto, llvm, patches

On Mon, Jun 09, 2025 at 03:45:20PM -0700, Nathan Chancellor wrote:
> After commit 6f110a5e4f99 ("Disable SLUB_TINY for build testing"), which
> causes CONFIG_KASAN to be enabled in allmodconfig again, arm64
> allmodconfig builds with clang-17 and older show an instance of
> -Wframe-larger-than (which breaks the build with CONFIG_WERROR=y):
> 
>   lib/crypto/curve25519-hacl64.c:757:6: error: stack frame size (2336) exceeds limit (2048) in 'curve25519_generic' [-Werror,-Wframe-larger-than]
>     757 | void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
>         |      ^
> 
> When KASAN is disabled, the stack usage is roughly quartered:
> 
>   lib/crypto/curve25519-hacl64.c:757:6: error: stack frame size (608) exceeds limit (128) in 'curve25519_generic' [-Werror,-Wframe-larger-than]
>     757 | void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
>         |      ^
> 
> Using '-Rpass-analysis=stack-frame-layout' shows the following variables
> and many, many 8-byte spills when KASAN is enabled:
> 
>   Offset: [SP-144], Type: Variable, Align: 8, Size: 40
>   Offset: [SP-464], Type: Variable, Align: 8, Size: 320
>   Offset: [SP-784], Type: Variable, Align: 8, Size: 320
>   Offset: [SP-864], Type: Variable, Align: 32, Size: 80
>   Offset: [SP-896], Type: Variable, Align: 32, Size: 32
>   Offset: [SP-1016], Type: Variable, Align: 8, Size: 120
> 
> When KASAN is disabled, there are still spills but not at many and the
> variables list is smaller:
> 
>   Offset: [SP-192], Type: Variable, Align: 32, Size: 80
>   Offset: [SP-224], Type: Variable, Align: 32, Size: 32
>   Offset: [SP-344], Type: Variable, Align: 8, Size: 120
> 
> Disable KASAN for this file when using clang-17 or older to avoid
> blowing out the stack, clearing up the warning.
> 
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>  lib/crypto/Makefile | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile
> index 3e79283b617d..18664127ecd6 100644
> --- a/lib/crypto/Makefile
> +++ b/lib/crypto/Makefile
> @@ -35,6 +35,10 @@ obj-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC)	+= libcurve25519-generic.o
>  libcurve25519-generic-y				:= curve25519-fiat32.o
>  libcurve25519-generic-$(CONFIG_ARCH_SUPPORTS_INT128)	:= curve25519-hacl64.o
>  libcurve25519-generic-y				+= curve25519-generic.o
> +# clang versions prior to 18 may blow out the stack with KASAN
> +ifeq ($(call clang-min-version, 180000),)
> +KASAN_SANITIZE_curve25519-hacl64.o := n
> +endif

Seems reasonable. We've had a hassle with this for a while.

    Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: lib/curve25519-hacl64 - Disable KASAN with clang-17 and older
  2025-06-09 22:45 [PATCH] crypto: lib/curve25519-hacl64 - Disable KASAN with clang-17 and older Nathan Chancellor
  2025-06-10  9:42 ` Ard Biesheuvel
  2025-06-10 17:41 ` Jason A. Donenfeld
@ 2025-06-10 18:42 ` Eric Biggers
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Biggers @ 2025-06-10 18:42 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Jason A. Donenfeld, Ard Biesheuvel, linux-crypto, llvm, patches

On Mon, Jun 09, 2025 at 03:45:20PM -0700, Nathan Chancellor wrote:
> After commit 6f110a5e4f99 ("Disable SLUB_TINY for build testing"), which
> causes CONFIG_KASAN to be enabled in allmodconfig again, arm64
> allmodconfig builds with clang-17 and older show an instance of
> -Wframe-larger-than (which breaks the build with CONFIG_WERROR=y):
> 
>   lib/crypto/curve25519-hacl64.c:757:6: error: stack frame size (2336) exceeds limit (2048) in 'curve25519_generic' [-Werror,-Wframe-larger-than]
>     757 | void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
>         |      ^
> 
> When KASAN is disabled, the stack usage is roughly quartered:
> 
>   lib/crypto/curve25519-hacl64.c:757:6: error: stack frame size (608) exceeds limit (128) in 'curve25519_generic' [-Werror,-Wframe-larger-than]
>     757 | void curve25519_generic(u8 mypublic[CURVE25519_KEY_SIZE],
>         |      ^
> 
> Using '-Rpass-analysis=stack-frame-layout' shows the following variables
> and many, many 8-byte spills when KASAN is enabled:
> 
>   Offset: [SP-144], Type: Variable, Align: 8, Size: 40
>   Offset: [SP-464], Type: Variable, Align: 8, Size: 320
>   Offset: [SP-784], Type: Variable, Align: 8, Size: 320
>   Offset: [SP-864], Type: Variable, Align: 32, Size: 80
>   Offset: [SP-896], Type: Variable, Align: 32, Size: 32
>   Offset: [SP-1016], Type: Variable, Align: 8, Size: 120
> 
> When KASAN is disabled, there are still spills but not at many and the
> variables list is smaller:
> 
>   Offset: [SP-192], Type: Variable, Align: 32, Size: 80
>   Offset: [SP-224], Type: Variable, Align: 32, Size: 32
>   Offset: [SP-344], Type: Variable, Align: 8, Size: 120
> 
> Disable KASAN for this file when using clang-17 or older to avoid
> blowing out the stack, clearing up the warning.
> 
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>  lib/crypto/Makefile | 4 ++++
>  1 file changed, 4 insertions(+)
> 

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-fixes

Thanks!

- Eric

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-10 18:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-09 22:45 [PATCH] crypto: lib/curve25519-hacl64 - Disable KASAN with clang-17 and older Nathan Chancellor
2025-06-10  9:42 ` Ard Biesheuvel
2025-06-10 17:41 ` Jason A. Donenfeld
2025-06-10 18:42 ` Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).