android_kernel_xiaomi_sm8450/arch/x86/lib
Andy Lutomirski f594871732 x86/stackprotector/32: Make the canary into a regular percpu variable
[ Upstream commit 3fb0fdb3bbe7aed495109b3296b06c2409734023 ]

On 32-bit kernels, the stackprotector canary is quite nasty -- it is
stored at %gs:(20), which is nasty because 32-bit kernels use %fs for
percpu storage.  It's even nastier because it means that whether %gs
contains userspace state or kernel state while running kernel code
depends on whether stackprotector is enabled (this is
CONFIG_X86_32_LAZY_GS), and this setting radically changes the way
that segment selectors work.  Supporting both variants is a
maintenance and testing mess.

Merely rearranging so that percpu and the stack canary
share the same segment would be messy as the 32-bit percpu address
layout isn't currently compatible with putting a variable at a fixed
offset.

Fortunately, GCC 8.1 added options that allow the stack canary to be
accessed as %fs:__stack_chk_guard, effectively turning it into an ordinary
percpu variable.  This lets us get rid of all of the code to manage the
stack canary GDT descriptor and the CONFIG_X86_32_LAZY_GS mess.

(That name is special.  We could use any symbol we want for the
 %fs-relative mode, but for CONFIG_SMP=n, gcc refuses to let us use any
 name other than __stack_chk_guard.)

Forcibly disable stackprotector on older compilers that don't support
the new options and turn the stack canary into a percpu variable. The
"lazy GS" approach is now used for all 32-bit configurations.

Also makes load_gs_index() work on 32-bit kernels. On 64-bit kernels,
it loads the GS selector and updates the user GSBASE accordingly. (This
is unchanged.) On 32-bit kernels, it loads the GS selector and updates
GSBASE, which is now always the user base. This means that the overall
effect is the same on 32-bit and 64-bit, which avoids some ifdeffery.

 [ bp: Massage commit message. ]

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/c0ff7dba14041c7e5d1cae5d4df052f03759bef3.1613243844.git.luto@kernel.org
Stable-dep-of: e3f269ed0acc ("x86/pm: Work around false positive kmemleak report in msr_build_context()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-13 12:58:45 +02:00
..
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
atomic64_32.c x86: Adjust asm constraints in atomic64 wrappers 2012-01-20 17:29:31 -08:00
atomic64_386_32.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
atomic64_cx8_32.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
cache-smp.c smp: Remove smp_call_function() and on_each_cpu() return values 2019-06-23 14:26:26 +02:00
checksum_32.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
clear_page_64.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
cmdline.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
cmpxchg8b_emu.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
cmpxchg16b_emu.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
copy_mc_64.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
copy_mc.c iov_iter, x86: Be consistent about the __user tag on copy_mc_to_user() 2023-11-20 11:06:43 +01:00
copy_page_64.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
copy_user_64.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
cpu.c x86/lib/cpu: Address missing prototypes warning 2019-08-08 08:25:53 +02:00
csum-copy_64.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
csum-partial_64.c x86/lib: Fix indentation issue, remove extra tab 2019-03-21 12:24:38 +01:00
csum-wrappers_64.c amd64: switch csum_partial_copy_generic() to new calling conventions 2020-08-20 15:45:22 -04:00
delay.c x86/delay: Fix the wrong asm constraint in delay_loop() 2022-06-09 10:21:00 +02:00
error-inject.c x86: Prepare inline-asm for straight-line-speculation 2022-07-25 11:26:29 +02:00
getuser.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
hweight.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
inat.c x86/insn: Add a __ignore_sync_check__ marker 2022-07-25 11:26:11 +02:00
insn-eval.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-04-13 12:58:45 +02:00
insn.c x86/insn: Add an insn_decode() API 2022-07-25 11:26:11 +02:00
iomap_copy_64.S x86/asm: Fix an assembler warning with current binutils 2023-01-24 07:19:56 +01:00
iomem.c x86: explicitly align IO accesses in memcpy_{to,from}io 2019-02-01 09:07:48 -08:00
kaslr.c x86/kaslr: Fix incorrect i8254 outb() parameters 2019-01-11 21:35:47 +01:00
Makefile * Extend the recovery from MCE in kernel space also to processes which 2020-10-12 10:14:38 -07:00
memcpy_32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
memcpy_64.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
memmove_64.S x86: Use return-thunk in asm code 2022-07-25 11:26:39 +02:00
memset_64.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
misc.c x86/lib: Fix overflow when counting digits 2024-01-25 14:37:39 -08:00
mmx_32.c x86/mmx: Use KFPU_387 for MMX string operations 2021-01-27 11:55:13 +01:00
msr-reg-export.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
msr-reg.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
msr-smp.c x86/msr: Fix wr/rdmsr_safe_regs_on_cpu() prototypes 2021-05-22 11:40:51 +02:00
msr.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
putuser.S x86: Prepare asm files for straight-line-speculation 2022-07-25 11:26:28 +02:00
retpoline.S x86/retpoline,kprobes: Fix position of thunk sections with CONFIG_LTO_CLANG 2023-08-26 15:26:58 +02:00
string_32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
strstr_32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
usercopy_32.c docs/core-api/mm: fix user memory accessors formatting 2019-03-05 21:07:20 -08:00
usercopy_64.c x86: __memcpy_flushcache: fix wrong alignment if size > 2^32 2022-05-09 09:05:06 +02:00
usercopy.c x86/nmi: Fix NMI uaccess race against CR3 switching 2018-08-31 17:08:22 +02:00
x86-opcode-map.txt x86/insn: Add Control-flow Enforcement (CET) instructions to the opcode map 2020-03-26 12:21:40 +01:00