android_kernel_xiaomi_sm7250/lib
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
..
842
crypto UPSTREAM: lib/crypto: blake2s: avoid indirect calls to compression function for Clang CFI 2022-07-07 17:14:19 +00:00
fonts
lz4
lzo
mpi lib/mpi: use kcalloc in mpi_resize 2021-09-22 11:47:51 +02:00
raid6 lib/raid6/test/Makefile: Use $(pound) instead of \# for Make 4.3 2022-04-15 14:14:54 +02:00
reed_solomon
vdso
xz lib/xz: Validate the value before assigning it to an enum variable 2021-11-26 11:36:06 +01:00
zlib_deflate
zlib_inflate
zstd
.gitignore
argv_split.c
ashldi3.c
ashrdi3.c
asn1_decoder.c
assoc_array.c assoc_array: Fix BUG_ON during garbage collect 2022-06-06 08:24:20 +02:00
atomic64_test.c
atomic64.c
audit.c
bcd.c
bch.c
bitmap.c
bitrev.c
bsearch.c
btree.c
bucket_locks.c
bug.c
build_OID_registry
bust_spinlocks.c
check_signature.c
checksum.c
clz_ctz.c
clz_tab.c
cmdline.c
cmpdi2.c
compat_audit.c
cordic.c
cpu_rmap.c
cpumask.c
crc4.c
crc7.c
crc8.c
crc16.c
crc32.c
crc32defs.h
crc32test.c
crc64.c
crc-ccitt.c
crc-itu-t.c
crc-t10dif.c
ctype.c
debug_info.c
debug_locks.c
debugobjects.c
dec_and_lock.c
decompress_bunzip2.c
decompress_inflate.c
decompress_unlz4.c lib/decompress_unlz4.c: correctly handle zero-padding around initrds. 2021-07-20 16:16:10 +02:00
decompress_unlzma.c
decompress_unlzo.c
decompress_unxz.c lib/xz: Avoid overlapping memcpy() with invalid input with in-place decompression 2021-11-26 11:36:06 +01:00
decompress.c
devres.c
digsig.c
div64.c
dump_stack.c
dynamic_debug.c
dynamic_queue_limits.c
earlycpio.c
error-inject.c
errseq.c
extable.c
fault-inject.c
fdt_empty_tree.c
fdt_ro.c
fdt_rw.c
fdt_strerror.c
fdt_sw.c
fdt_wip.c
fdt.c
find_bit_benchmark.c
find_bit.c
flex_array.c
flex_proportions.c
gcd.c
gen_crc32table.c
gen_crc64table.c
genalloc.c
glob.c
globtest.c
hexdump.c ANDROID: GKI: update the abi .xml file due to hex_to_bin() changes 2022-05-13 09:30:42 +02:00
hweight.c
idr.c
inflate.c
int_sqrt.c
interval_tree_test.c
interval_tree.c
iomap_copy.c
iomap.c
iommu-helper.c
ioremap.c
iov_iter.c lib/iov_iter: initialize "flags" in new pipe_buffer 2022-02-23 11:58:41 +01:00
irq_poll.c
irq_regs.c
is_single_threaded.c
jedec_ddr_data.c
kasprintf.c
Kconfig BACKPORT: lib/crypto: add prompts back to crypto libraries 2022-07-07 17:14:19 +00:00
Kconfig.debug Revert "ARM: 8800/1: use choice for kernel unwinders" 2021-12-28 13:39:06 +01:00
Kconfig.kasan
Kconfig.kgdb
Kconfig.ubsan
kfifo.c
klist.c
kobject_uevent.c kobject_uevent: remove warning in init_uevent_argv() 2021-05-22 10:59:47 +02:00
kobject.c
kstrtox.c lib: vsprintf: Fix handling of number field widths in vsscanf 2021-07-20 16:15:45 +02:00
kstrtox.h lib: vsprintf: Fix handling of number field widths in vsscanf 2021-07-20 16:15:45 +02:00
lcm.c
libcrc32c.c
list_debug.c
list_sort.c
llist.c
locking-selftest-hardirq.h
locking-selftest-mutex.h
locking-selftest-rlock-hardirq.h
locking-selftest-rlock-softirq.h
locking-selftest-rlock.h
locking-selftest-rsem.h
locking-selftest-rtmutex.h
locking-selftest-softirq.h
locking-selftest-spin-hardirq.h
locking-selftest-spin-softirq.h
locking-selftest-spin.h
locking-selftest-wlock-hardirq.h
locking-selftest-wlock-softirq.h
locking-selftest-wlock.h
locking-selftest-wsem.h
locking-selftest.c
lockref.c
logic_pio.c
lru_cache.c
lshrdi3.c
Makefile
memory-notifier-error-inject.c
memweight.c
muldi3.c
net_utils.c
netdev-notifier-error-inject.c
nlattr.c
nmi_backtrace.c
nodemask.c nodemask: Fix return values to be unsigned 2022-06-14 16:59:38 +02:00
notifier-error-inject.c
notifier-error-inject.h
of-reconfig-notifier-error-inject.c
oid_registry.c
once.c once: Fix panic when module unload 2021-09-03 09:58:00 +02:00
parman.c
parser.c
pci_iomap.c
percpu_counter.c
percpu_test.c
percpu-refcount.c
plist.c
pm-notifier-error-inject.c
prime_numbers.c
radix-tree.c
random32.c
ratelimit.c
rational.c
rbtree_test.c
rbtree.c
reciprocal_div.c
refcount.c
rhashtable.c
sbitmap.c
scatterlist.c
seq_buf.c seq_buf: Fix overflow in seq_buf_putmem_hex() 2021-07-20 16:16:05 +02:00
sg_pool.c
sg_split.c
sha1.c
sha256.c
show_mem.c
siphash.c siphash: use _unaligned version by default 2021-12-08 08:50:13 +01:00
smp_processor_id.c
sort.c
stackdepot.c lib: stackdepot: turn depot_lock spinlock to raw_spinlock 2021-05-22 10:59:49 +02:00
stmp_device.c
string_helpers.c
string.c
strncpy_from_user.c
strnlen_user.c
syscall.c
test_bitfield.c
test_bitmap.c
test_bpf.c bpf/tests: Do not PASS tests without actually testing the result 2021-09-22 11:48:04 +02:00
test_debug_virtual.c
test_firmware.c
test_hash.c
test_hexdump.c
test_ida.c
test_kasan.c
test_kmod.c lib/test: use after free in register_test_dev_kmod() 2022-04-15 14:14:53 +02:00
test_list_sort.c
test_meminit.c
test_module.c
test_overflow.c
test_parman.c
test_printf.c
test_rhashtable.c
test_siphash.c
test_sort.c
test_stackinit.c
test_static_key_base.c
test_static_keys.c
test_string.c
test_sysctl.c
test_ubsan.c
test_user_copy.c
test_uuid.c
test-kstrtox.c
test-string_helpers.c
textsearch.c
timerqueue.c Revert "lib/timerqueue: Rely on rbtree semantics for next timer" 2021-10-13 12:15:04 +02:00
ts_bm.c
ts_fsm.c
ts_kmp.c
ubsan.c
ubsan.h
ucmpdi2.c
ucs2_string.c
usercopy.c
uuid.c
vsprintf.c This is the 4.19.198 stable release 2021-07-20 16:38:59 +02:00
win_minmax.c
xxhash.c