1
linux/arch/x86/entry
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
..
syscalls uretprobe: change syscall number, again 2024-08-02 15:18:49 +02:00
vdso random: vDSO: add a __vdso_getrandom prototype for all architectures 2024-09-13 17:28:35 +02:00
vsyscall x86/mm: Remove broken vsyscall emulation code from the page fault code 2024-05-01 09:41:43 +02:00
calling.h Core x86 changes for v6.9: 2024-03-11 19:53:15 -07:00
common.c treewide: context_tracking: Rename CONTEXT_* into CT_STATE_* 2024-07-29 07:33:10 +05:30
entry_32.S x86/entry_32: Clear CPU buffers after register restore in NMI return 2024-10-08 15:16:28 -07:00
entry_64_compat.S x86/bhi: Avoid warning in #DB handler due to BHI mitigation 2024-07-03 13:26:30 +02:00
entry_64_fred.S x86/entry: Add fred_entry_from_kvm() for VMX to handle IRQ/NMI 2024-01-31 22:03:16 +01:00
entry_64.S x86/bhi: Add support for clearing branch history at syscall entry 2024-04-08 19:27:05 +02:00
entry_fred.c x86/irq: Install posted MSI notification handler 2024-04-30 00:54:42 +02:00
entry.S x86/stackprotector: Work around strict Clang TLS symbol requirements 2024-11-08 13:16:00 +01:00
Makefile x86/entry: Merge thunk_64.S and thunk_32.S into thunk.S 2024-04-09 09:57:56 +02:00
syscall_32.c x86/syscall: Mark exit[_group] syscall handlers __noreturn 2024-06-28 15:23:38 +02:00
syscall_64.c x86/syscall: Mark exit[_group] syscall handlers __noreturn 2024-06-28 15:23:38 +02:00
syscall_x32.c x86/syscall: Mark exit[_group] syscall handlers __noreturn 2024-06-28 15:23:38 +02:00
thunk.S x86/entry: Merge thunk_64.S and thunk_32.S into thunk.S 2024-04-09 09:57:56 +02:00