1
linux/arch/x86/kernel/cpu
Ard Biesheuvel 577c134d31 x86/stackprotector: Work around strict Clang TLS symbol requirements
GCC and Clang both implement stack protector support based on Thread Local
Storage (TLS) variables, and this is used in the kernel to implement per-task
stack cookies, by copying a task's stack cookie into a per-CPU variable every
time it is scheduled in.

Both now also implement -mstack-protector-guard-symbol=, which permits the TLS
variable to be specified directly. This is useful because it will allow to
move away from using a fixed offset of 40 bytes into the per-CPU area on
x86_64, which requires a lot of special handling in the per-CPU code and the
runtime relocation code.

However, while GCC is rather lax in its implementation of this command line
option, Clang actually requires that the provided symbol name refers to a TLS
variable (i.e., one declared with __thread), although it also permits the
variable to be undeclared entirely, in which case it will use an implicit
declaration of the right type.

The upshot of this is that Clang will emit the correct references to the stack
cookie variable in most cases, e.g.,

  10d:       64 a1 00 00 00 00       mov    %fs:0x0,%eax
                     10f: R_386_32   __stack_chk_guard

However, if a non-TLS definition of the symbol in question is visible in the
same compilation unit (which amounts to the whole of vmlinux if LTO is
enabled), it will drop the per-CPU prefix and emit a load from a bogus
address.

Work around this by using a symbol name that never occurs in C code, and emit
it as an alias in the linker script.

Fixes: 3fb0fdb3bb ("x86/stackprotector/32: Make the canary into a regular percpu variable")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Cc: stable@vger.kernel.org
Link: https://github.com/ClangBuiltLinux/linux/issues/1854
Link: https://lore.kernel.org/r/20241105155801.1779119-2-brgerst@gmail.com
2024-11-08 13:16:00 +01:00
..
mce [tree-wide] finally take no_llseek out 2024-09-27 08:18:43 -07:00
microcode x86/microcode/AMD: Split load_microcode_amd() 2024-10-22 16:48:00 +02:00
mtrr x86/cpu: KVM: Add common defines for architectural memory types (PAT, MTRRs, etc.) 2024-08-22 11:25:46 -07:00
resctrl x86/resctrl: Annotate get_mem_config() functions as __init 2024-10-08 21:05:10 +02:00
sgx struct fd layout change (and conversion to accessor helpers) 2024-09-23 09:35:36 -07:00
.gitignore
acrn.c
amd.c x86/CPU/AMD: Clear virtualized VMLOAD/VMSAVE on Zen4 client 2024-11-05 17:48:32 +01:00
aperfmperf.c x86/sched: Add basic support for CPU capacity scaling 2024-09-04 13:36:40 +02:00
bugs.c x86/bugs: Do not use UNTRAIN_RET with IBPB on entry 2024-10-10 10:38:21 +02:00
cacheinfo.c
centaur.c
common.c x86/stackprotector: Work around strict Clang TLS symbol requirements 2024-11-08 13:16:00 +01:00
cpu.h x86/topology/intel: Unlock CPUID before evaluating anything 2024-05-31 20:25:56 +02:00
cpuid-deps.c x86/msr: Switch between WRMSRNS and WRMSR with the alternatives mechanism 2024-08-25 19:23:00 +02:00
cyrix.c
debugfs.c
feat_ctl.c x86/cpu: Clarify the error message when BIOS does not support SGX 2024-08-25 14:41:19 +02:00
hygon.c
hypervisor.c
intel_epb.c
intel.c x86/cpu/intel: Replace PAT erratum model/family magic numbers with symbolic IFM references 2024-09-03 11:18:58 +02:00
Makefile
match.c
mkcapflags.sh x86/cpufeatures: Flip the /proc/cpuinfo appearance logic 2024-06-20 21:04:22 +02:00
mshyperv.c Updates for x86 timers: 2024-09-17 15:27:01 +02:00
perfctr-watchdog.c
powerflags.c
proc.c
rdrand.c
scattered.c x86/cpufeatures: Add AMD FAST CPPC feature flag 2024-06-11 16:12:12 -05:00
topology_amd.c x86/topology/amd: Evaluate SMT in CPUID leaf 0x8000001e only on family 0x17 and greater 2024-05-30 15:58:55 +02:00
topology_common.c
topology_ext.c
topology.c
topology.h
transmeta.c
tsx.c
umc.c
umwait.c
vmware.c x86/vmware: Add TDX hypercall support 2024-06-25 17:15:48 +02:00
vortex.c
zhaoxin.c