linux/lib/crypto
Nathan Chancellor 6f02e337cb lib/crypto/curve25519-hacl64: Disable KASAN with clang-17 and older
commit 2f13daee2a upstream.

After commit 6f110a5e4f ("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: "Jason A. Donenfeld" <Jason@zx2c4.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250609-curve25519-hacl64-disable-kasan-clang-v1-1-08ea0ac5ccff@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-10-19 16:34:00 +02:00
..
mpi crypto: lib/mpi - Fix an "Uninitialized scalar variable" issue 2024-10-16 13:38:16 +08:00
aes.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
aescfb.c crypto: lib - implement library version of AES in CFB mode 2024-05-09 22:30:51 +03:00
aesgcm.c crypto: lib/aesgcm - Add kernel docs for aesgcm_mac 2023-11-17 19:16:28 +08:00
arc4.c crypto: lib - add missing MODULE_DESCRIPTION() macros 2024-06-07 19:46:39 +08:00
blake2s-generic.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
blake2s-selftest.c crypto: lib/blake2s - Split up test function to halve stack usage 2022-12-30 22:56:27 +08:00
blake2s.c crypto: remove MODULE_LICENSE in non-modules 2023-04-13 13:13:51 -07:00
chacha.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
chacha20poly1305-selftest.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
chacha20poly1305.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
curve25519-fiat32.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
curve25519-generic.c crypto: curve25519 - Fix selftest build error 2020-01-16 15:18:13 +08:00
curve25519-hacl64.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
curve25519-selftest.c crypto: lib/curve25519 - re-add selftests 2019-12-27 18:18:03 +08:00
curve25519.c crypto: lib - rename 'mod_init' & 'mod_exit' functions to be module-specific 2021-07-16 15:49:36 +08:00
des.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
gf128mul.c crypto: lib/gf128mul - make gf128mul_lle time invariant 2022-11-11 18:14:59 +08:00
Kconfig crypto: lib/Kconfig - Hide arch options from user 2025-05-02 07:59:32 +02:00
libchacha.c crypto: lib - add missing MODULE_DESCRIPTION() macros 2024-06-07 19:46:39 +08:00
Makefile lib/crypto/curve25519-hacl64: Disable KASAN with clang-17 and older 2025-10-19 16:34:00 +02:00
memneq.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
poly1305-donna32.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
poly1305-donna64.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
poly1305.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
sha1.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
sha256.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
utils.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00