android_kernel_motorola_sm6225/arch/x86/crypto
Jason A. Donenfeld 107101e75a UPSTREAM: lib/crypto: blake2s: avoid indirect calls to compression function for Clang CFI
blake2s_compress_generic is weakly aliased by blake2s_compress. The
current harness for function selection uses a function pointer, which is
ordinarily inlined and resolved at compile time. But when Clang's CFI is
enabled, CFI still triggers when making an indirect call via a weak
symbol. This seems like a bug in Clang's CFI, as though it's bucketing
weak symbols and strong symbols differently. It also only seems to
trigger when "full LTO" mode is used, rather than "thin LTO".

[    0.000000][    T0] Kernel panic - not syncing: CFI failure (target: blake2s_compress_generic+0x0/0x1444)
[    0.000000][    T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.16.0-mainline-06981-g076c855b846e #1
[    0.000000][    T0] Hardware name: MT6873 (DT)
[    0.000000][    T0] Call trace:
[    0.000000][    T0]  dump_backtrace+0xfc/0x1dc
[    0.000000][    T0]  dump_stack_lvl+0xa8/0x11c
[    0.000000][    T0]  panic+0x194/0x464
[    0.000000][    T0]  __cfi_check_fail+0x54/0x58
[    0.000000][    T0]  __cfi_slowpath_diag+0x354/0x4b0
[    0.000000][    T0]  blake2s_update+0x14c/0x178
[    0.000000][    T0]  _extract_entropy+0xf4/0x29c
[    0.000000][    T0]  crng_initialize_primary+0x24/0x94
[    0.000000][    T0]  rand_initialize+0x2c/0x6c
[    0.000000][    T0]  start_kernel+0x2f8/0x65c
[    0.000000][    T0]  __primary_switched+0xc4/0x7be4
[    0.000000][    T0] Rebooting in 5 seconds..

Nonetheless, the function pointer method isn't so terrific anyway, so
this patch replaces it with a simple boolean, which also gets inlined
away. This successfully works around the Clang bug.

In general, I'm not too keen on all of the indirection involved here; it
clearly does more harm than good. Hopefully the whole thing can get
cleaned up down the road when lib/crypto is overhauled more
comprehensively. But for now, we go with a simple bandaid.

Fixes: 6048fdcc5f26 ("lib/crypto: blake2s: include as built-in")
Link: https://github.com/ClangBuiltLinux/linux/issues/1567
Reported-by: Miles Chen <miles.chen@mediatek.com>
Tested-by: Miles Chen <miles.chen@mediatek.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: John Stultz <john.stultz@linaro.org>
Acked-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

(cherry picked from commit d2a02e3c8bb6b347818518edff5a4b40ff52d6d8)
Change-Id: I3a6461e3f05f57cd898f8a4f46e73fb0214037ef
Signed-off-by: Eric Biggers <ebiggers@google.com>
2022-07-07 17:14:19 +00:00
..
sha1-mb crypto: ahash - remove useless setting of cra_type 2018-07-09 00:30:26 +08:00
sha256-mb crypto: ahash - remove useless setting of cra_type 2018-07-09 00:30:26 +08:00
sha512-mb crypto: ahash - remove useless setting of cra_type 2018-07-09 00:30:26 +08:00
.gitignore UPSTREAM: crypto: x86/poly1305 - fix .gitignore typo 2020-10-25 11:47:57 +01:00
aegis128-aesni-asm.S Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2018-08-13 13:35:26 -07:00
aegis128-aesni-glue.c crypto: x86/aegis - fix handling chunked inputs and MAY_SLEEP 2019-03-23 20:09:55 +01:00
aegis128l-aesni-asm.S Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2018-08-13 13:35:26 -07:00
aegis128l-aesni-glue.c crypto: x86/aegis - fix handling chunked inputs and MAY_SLEEP 2019-03-23 20:09:55 +01:00
aegis256-aesni-asm.S Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2018-08-13 13:35:26 -07:00
aegis256-aesni-glue.c crypto: x86/aegis - fix handling chunked inputs and MAY_SLEEP 2019-03-23 20:09:55 +01:00
aes-i586-asm_32.S
aes-x86_64-asm_64.S crypto: x86/aes - Don't use %rbp as temporary register 2017-05-23 12:52:05 +08:00
aes_ctrby8_avx-x86_64.S crypto: aesni - add compatibility with IAS 2020-08-19 08:15:03 +02:00
aes_glue.c
aesni-intel_asm.S crypto: aesni - Fix build with LLVM_IAS=1 2020-08-19 08:14:51 +02:00
aesni-intel_avx-x86_64.S x86/asm/64: Use 32-bit XOR to zero registers 2018-07-03 09:59:29 +02:00
aesni-intel_glue.c crypto: x86/aesni-gcm - fix crash on empty plaintext 2019-03-23 20:09:55 +01:00
blake2s-core.S UPSTREAM: crypto: blake2s - x86_64 SIMD implementation 2020-10-24 22:42:43 +02:00
blake2s-glue.c BACKPORT: lib/crypto: blake2s: include as built-in 2022-07-07 17:14:19 +00:00
blake2s-shash.c UPSTREAM: lib/crypto: blake2s: avoid indirect calls to compression function for Clang CFI 2022-07-07 17:14:19 +00:00
blowfish-x86_64-asm_64.S crypto: x86/blowfish - Fix RBP usage 2017-09-20 17:42:31 +08:00
blowfish_glue.c crypto: x86/blowfish: convert to skcipher interface 2018-03-03 00:03:29 +08:00
camellia-aesni-avx-asm_64.S x86/retpoline/crypto: Convert crypto assembler indirect jumps 2018-01-12 00:14:29 +01:00
camellia-aesni-avx2-asm_64.S x86/retpoline/crypto: Convert crypto assembler indirect jumps 2018-01-12 00:14:29 +01:00
camellia-x86_64-asm_64.S crypto: x86/camellia - Fix RBP usage 2017-09-20 17:42:31 +08:00
camellia_aesni_avx2_glue.c crypto: x86/camellia-aesni-avx, avx2 - convert to skcipher interface 2018-03-03 00:03:32 +08:00
camellia_aesni_avx_glue.c crypto: x86/camellia-aesni-avx, avx2 - convert to skcipher interface 2018-03-03 00:03:32 +08:00
camellia_glue.c crypto: x86/camellia - convert to skcipher interface 2018-03-03 00:03:32 +08:00
cast5-avx-x86_64-asm_64.S crypto: x86/cast5 - Fix RBP usage 2017-09-20 17:42:32 +08:00
cast5_avx_glue.c crypto: x86/glue_helper - rename glue_skwalk_fpu_begin() 2018-03-03 00:03:35 +08:00
cast6-avx-x86_64-asm_64.S crypto: x86/cast6 - Fix RBP usage 2017-09-20 17:42:33 +08:00
cast6_avx_glue.c crypto: x86/cast6-avx - convert to skcipher interface 2018-03-03 00:03:28 +08:00
chacha-avx2-x86_64.S UPSTREAM: crypto: x86/chacha20 - refactor to allow varying number of rounds 2020-10-24 11:31:43 +02:00
chacha-avx512vl-x86_64.S UPSTREAM: crypto: x86/chacha20 - refactor to allow varying number of rounds 2020-10-24 11:31:43 +02:00
chacha-ssse3-x86_64.S UPSTREAM: crypto: x86/chacha-sse3 - use unaligned loads for state array 2020-10-25 11:48:06 +01:00
chacha_glue.c UPSTREAM: crypto: x86/chacha-sse3 - use unaligned loads for state array 2020-10-25 11:48:06 +01:00
crc32-pclmul_asm.S crypto: crc32-pclmul - remove useless relative addressing 2017-10-07 12:10:30 +08:00
crc32-pclmul_glue.c crypto: hash - annotate algorithms taking optional key 2018-01-12 23:03:35 +11:00
crc32c-intel_glue.c crypto: hash - annotate algorithms taking optional key 2018-01-12 23:03:35 +11:00
crc32c-pcl-intel-asm_64.S crypto: x86/crc32c - fix building with clang ias 2021-01-23 15:49:55 +01:00
crct10dif-pcl-asm_64.S
crct10dif-pclmul_glue.c crypto: x86/crct10dif-pcl - fix use via crypto_shash_digest() 2019-05-22 07:37:37 +02:00
curve25519-x86_64.c UPSTREAM: crypto: curve25519-x86_64 - Use XORL r32,32 2020-10-25 11:48:08 +01:00
des3_ede-asm_64.S crypto: x86/des3_ede - Fix RBP usage 2017-09-20 17:42:34 +08:00
des3_ede_glue.c crypto: x86/des3_ede - des3_ede_skciphers[] can be static 2018-03-09 22:45:53 +08:00
fpu.c
ghash-clmulni-intel_asm.S
ghash-clmulni-intel_glue.c crypto: ahash - remove useless setting of cra_type 2018-07-09 00:30:26 +08:00
glue_helper-asm-avx.S
glue_helper-asm-avx2.S
glue_helper.c crypto: x86/glue_helper - rename glue_skwalk_fpu_begin() 2018-03-03 00:03:35 +08:00
Makefile BACKPORT: lib/crypto: blake2s: include as built-in 2022-07-07 17:14:19 +00:00
morus640-sse2-asm.S Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2018-08-13 13:35:26 -07:00
morus640-sse2-glue.c crypto: x86/aegis,morus - Do not require OSXSAVE for SSE2 2018-09-14 14:08:27 +08:00
morus640_glue.c crypto: x86/morus - fix handling chunked inputs and MAY_SLEEP 2019-03-23 20:09:55 +01:00
morus1280-avx2-asm.S Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2018-08-13 13:35:26 -07:00
morus1280-avx2-glue.c crypto: x86/aegis,morus - Fix and simplify CPUID checks 2018-08-07 17:51:15 +08:00
morus1280-sse2-asm.S Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2018-08-13 13:35:26 -07:00
morus1280-sse2-glue.c crypto: x86/aegis,morus - Do not require OSXSAVE for SSE2 2018-09-14 14:08:27 +08:00
morus1280_glue.c crypto: x86/morus - fix handling chunked inputs and MAY_SLEEP 2019-03-23 20:09:55 +01:00
poly1305-x86_64-cryptogams.pl UPSTREAM: crypto: poly1305-x86_64 - Use XORL r32,32 2020-10-25 11:48:09 +01:00
poly1305_glue.c UPSTREAM: crypto: poly1305 - fix poly1305_core_setkey() declaration 2022-07-07 09:42:40 +00:00
serpent-avx-x86_64-asm_64.S
serpent-avx2-asm_64.S
serpent-sse2-i586-asm_32.S
serpent-sse2-x86_64-asm_64.S
serpent_avx2_glue.c crypto: x86/serpent-avx,avx2 - convert to skcipher interface 2018-03-03 00:03:22 +08:00
serpent_avx_glue.c crypto: x86/serpent-avx,avx2 - convert to skcipher interface 2018-03-03 00:03:22 +08:00
serpent_sse2_glue.c crypto: x86/serpent-sse2 - convert to skcipher interface 2018-03-03 00:03:20 +08:00
sha1_avx2_x86_64_asm.S FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha1_ni_asm.S
sha1_ssse3_asm.S FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha1_ssse3_glue.c FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha256-avx-asm.S FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha256-avx2-asm.S FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha256-ssse3-asm.S FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha256_ni_asm.S
sha256_ssse3_glue.c FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha512-avx-asm.S FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha512-avx2-asm.S FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha512-ssse3-asm.S FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
sha512_ssse3_glue.c FROMLIST: crypto, x86/sha: Eliminate casts on asm implementations 2020-01-24 21:15:47 +00:00
twofish-avx-x86_64-asm_64.S crypto: x86/twofish - Fix RBP usage 2017-09-20 17:42:38 +08:00
twofish-i586-asm_32.S
twofish-x86_64-asm_64-3way.S crypto: x86/twofish-3way - Fix %rbp usage 2017-12-28 17:56:44 +11:00
twofish-x86_64-asm_64.S
twofish_avx_glue.c crypto: x86/twofish-avx - convert to skcipher interface 2018-03-03 00:03:25 +08:00
twofish_glue.c
twofish_glue_3way.c crypto: x86/twofish-3way - convert to skcipher interface 2018-03-03 00:03:24 +08:00