android_kernel_xiaomi_sm7250/arch/arm/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
..
.gitignore UPSTREAM: crypto: arm[64]/poly1305 - add artifact to .gitignore files 2020-10-25 11:48:04 +01:00
aes-ce-core.S crypto: arm/aes-ce - remove cra_alignmask 2017-02-03 18:16:16 +08:00
aes-ce-glue.c crypto: algapi - make crypto_xor() take separate dst and src arguments 2017-08-04 09:27:15 +08:00
aes-cipher-core.S FROMGIT: crypto: arm/aes - add some hardening against cache-timing attacks 2018-12-05 09:48:14 -08:00
aes-cipher-glue.c crypto: arm/aes - replace scalar AES cipher 2017-01-13 00:26:50 +08:00
aes-neonbs-core.S crypto: arm/aes - don't use IV buffer to return final keystream block 2017-02-03 18:16:21 +08:00
aes-neonbs-glue.c crypto: arm/aes-neonbs - don't access already-freed walk.iv 2019-05-22 07:37:37 +02:00
blake2b-neon-core.S BACKPORT: crypto: arm/blake2b - add NEON-accelerated BLAKE2b 2021-10-20 10:54:59 -07:00
blake2b-neon-glue.c BACKPORT: crypto: arm/blake2b - add NEON-accelerated BLAKE2b 2021-10-20 10:54:59 -07:00
blake2s-core.S BACKPORT: lib/crypto: blake2s: include as built-in 2022-07-07 17:14:19 +00: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
chacha-glue.c UPSTREAM: crypto: arch/lib - limit simd usage to 4k chunks 2020-10-25 11:48:05 +01:00
chacha-neon-core.S FROMGIT: crypto: arm/chacha20 - refactor to allow varying number of rounds 2018-12-05 09:48:15 -08:00
chacha-scalar-core.S UPSTREAM: crypto: arm/chacha - remove dependency on generic ChaCha driver 2020-10-24 14:43:36 +02:00
crc32-ce-core.S crypto: arm/crc32 - fix build error with outdated binutils 2017-03-01 19:47:51 +08:00
crc32-ce-glue.c crypto: arm/crc32 - avoid warning when compiling with Clang 2019-11-20 18:47:11 +01:00
crct10dif-ce-core.S crypto: arm/crct10dif - revert to C code for short inputs 2019-03-23 20:09:54 +01:00
crct10dif-ce-glue.c crypto: arm/crct10dif - revert to C code for short inputs 2019-03-23 20:09:54 +01:00
curve25519-core.S UPSTREAM: crypto: arm/curve25519 - wire up NEON implementation 2020-10-24 22:42:44 +02:00
curve25519-glue.c UPSTREAM: crypto: arm/curve25519 - include <linux/scatterlist.h> 2020-10-25 11:48:07 +01:00
ghash-ce-core.S crypto: arm/ghash - add NEON accelerated fallback for vmull.p64 2017-08-04 09:27:24 +08:00
ghash-ce-glue.c crypto: ahash - remove useless setting of cra_type 2018-07-09 00:30:26 +08:00
Kconfig BACKPORT: crypto: arm/blake2b - add NEON-accelerated BLAKE2b 2021-10-20 10:54:59 -07:00
Makefile BACKPORT: lib/crypto: blake2s: include as built-in 2022-07-07 17:14:19 +00:00
nh-neon-core.S FROMGIT: crypto: arm/nhpoly1305 - add NEON-accelerated NHPoly1305 2018-12-05 09:48:15 -08:00
nhpoly1305-neon-glue.c FROMGIT: crypto: arm/nhpoly1305 - add NEON-accelerated NHPoly1305 2018-12-05 09:48:15 -08:00
poly1305-armv4.pl UPSTREAM: crypto: arm/poly1305 - incorporate OpenSSL/CRYPTOGAMS NEON implementation 2020-10-24 22:42:43 +02:00
poly1305-core.S_shipped UPSTREAM: crypto: arm/poly1305 - incorporate OpenSSL/CRYPTOGAMS NEON implementation 2020-10-24 22:42:43 +02:00
poly1305-glue.c UPSTREAM: crypto: poly1305 - fix poly1305_core_setkey() declaration 2022-07-07 09:42:40 +00:00
sha1_glue.c crypto: shash - remove useless setting of type flags 2018-07-09 00:30:24 +08:00
sha1_neon_glue.c crypto: shash - remove useless setting of type flags 2018-07-09 00:30:24 +08:00
sha1-armv4-large.S crypto: clarify licensing of OpenSSL asm code 2018-05-31 00:13:44 +08:00
sha1-armv7-neon.S crypto: arm/sha1-neon - add support for building in Thumb2 mode 2016-09-07 21:08:29 +08:00
sha1-ce-core.S crypto: arm/sha1-ce - move SHA-1 ARMv8 implementation to base layer 2015-04-10 21:39:44 +08:00
sha1-ce-glue.c crypto: shash - remove useless setting of type flags 2018-07-09 00:30:24 +08:00
sha1.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sha2-ce-core.S crypto: arm/sha2-ce - move SHA-224/256 ARMv8 implementation to base layer 2015-04-10 21:39:45 +08:00
sha2-ce-glue.c crypto: shash - remove useless setting of type flags 2018-07-09 00:30:24 +08:00
sha256_glue.c treewide: convert ISO_8859-1 text comments to utf-8 2018-08-23 18:48:43 -07:00
sha256_glue.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sha256_neon_glue.c treewide: convert ISO_8859-1 text comments to utf-8 2018-08-23 18:48:43 -07:00
sha256-armv4.pl crypto: sha256/arm - fix crash bug in Thumb2 build 2019-04-20 09:16:03 +02:00
sha256-core.S_shipped crypto: sha256/arm - fix crash bug in Thumb2 build 2019-04-20 09:16:03 +02:00
sha512-armv4.pl crypto: sha512/arm - fix crash bug in Thumb2 build 2019-04-20 09:16:03 +02:00
sha512-core.S_shipped crypto: sha512/arm - fix crash bug in Thumb2 build 2019-04-20 09:16:03 +02:00
sha512-glue.c crypto: shash - remove useless setting of type flags 2018-07-09 00:30:24 +08:00
sha512-neon-glue.c crypto: shash - remove useless setting of type flags 2018-07-09 00:30:24 +08:00
sha512.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00