1
linux/arch
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
..
alpha move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
arc move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
arm This pull request contains Broadcom ARM-based SoCs Device Tree fixes for 2024-10-11 10:03:30 +00:00
arm64 arm64 fixes for -rc6 2024-11-01 07:54:11 -10:00
csky
hexagon hexagon: vdso: Fix build failure 2024-09-23 08:17:50 -07:00
loongarch LoongArch: KVM: Mark hrtimer to expire in hard interrupt context 2024-10-23 22:15:44 +08:00
m68k m68knommu: updates and fixes for v6.12 2024-09-24 10:48:44 -07:00
microblaze move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
mips for-6.12-rc5-tag 2024-11-01 07:31:47 -10:00
nios2 move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
openrisc
parisc move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
powerpc powerpc/powernv: Free name on error in opal_event_init() 2024-10-16 09:26:50 +11:00
riscv RISC-V Fixes for 6.11-rc6 2024-11-01 08:26:38 -10:00
s390 s390 fixes for 6.12-rc4 2024-10-18 07:01:59 -07:00
sh move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
sparc move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
um move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
x86 x86/stackprotector: Work around strict Clang TLS symbol requirements 2024-11-08 13:16:00 +01:00
xtensa move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
.gitignore
Kconfig cfi: tweak llvm version for HAVE_CFI_ICALL_NORMALIZE_INTEGERS 2024-10-31 00:41:37 +01:00