kernel_samsung_a53x/arch
Michael Roth bcbea52292 x86/head/64: Re-enable stack protection
commit 469693d8f62299709e8ba56d8fb3da9ea990213c upstream.

Due to

  103a4908ad4d ("x86/head/64: Disable stack protection for head$(BITS).o")

kernel/head{32,64}.c are compiled with -fno-stack-protector to allow
a call to set_bringup_idt_handler(), which would otherwise have stack
protection enabled with CONFIG_STACKPROTECTOR_STRONG.

While sufficient for that case, there may still be issues with calls to
any external functions that were compiled with stack protection enabled
that in-turn make stack-protected calls, or if the exception handlers
set up by set_bringup_idt_handler() make calls to stack-protected
functions.

Subsequent patches for SEV-SNP CPUID validation support will introduce
both such cases. Attempting to disable stack protection for everything
in scope to address that is prohibitive since much of the code, like the
SEV-ES #VC handler, is shared code that remains in use after boot and
could benefit from having stack protection enabled. Attempting to inline
calls is brittle and can quickly balloon out to library/helper code
where that's not really an option.

Instead, re-enable stack protection for head32.c/head64.c, and make the
appropriate changes to ensure the segment used for the stack canary is
initialized in advance of any stack-protected C calls.

For head64.c:

- The BSP will enter from startup_64() and call into C code
  (startup_64_setup_env()) shortly after setting up the stack, which
  may result in calls to stack-protected code. Set up %gs early to allow
  for this safely.
- APs will enter from secondary_startup_64*(), and %gs will be set up
  soon after. There is one call to C code prior to %gs being setup
  (__startup_secondary_64()), but it is only to fetch 'sme_me_mask'
  global, so just load 'sme_me_mask' directly instead, and remove the
  now-unused __startup_secondary_64() function.

For head32.c:

- BSPs/APs will set %fs to __BOOT_DS prior to any C calls. In recent
  kernels, the compiler is configured to access the stack canary at
  %fs:__stack_chk_guard [1], which overlaps with the initial per-cpu
  '__stack_chk_guard' variable in the initial/"master" .data..percpu
  area. This is sufficient to allow access to the canary for use
  during initial startup, so no changes are needed there.

[1] 3fb0fdb3bbe7 ("x86/stackprotector/32: Make the canary into a regular percpu variable")

  [ bp: Massage commit message. ]

Suggested-by: Joerg Roedel <jroedel@suse.de> #for 64-bit %gs set up
Signed-off-by: Michael Roth <michael.roth@amd.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20220307213356.2797205-24-brijesh.singh@amd.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-19 09:23:16 +01:00
..
alpha Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
arc ARC: fix spare error 2024-11-18 12:12:17 +01:00
arm arm: dts: marvell: Fix maxium->maxim typo in brownstone dts 2024-11-19 09:22:14 +01:00
arm64 KVM: arm64: vgic-its: Test for valid IRQ in its_sync_lpi_pending_table() 2024-11-18 22:25:37 +01:00
c6x Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
csky Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
h8300 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hexagon hexagon: vmlinux.lds.S: handle attributes section 2024-11-19 09:22:41 +01:00
ia64 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
m68k Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
microblaze Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mips MIPS: Clear Cause.BD in instruction_pointer_set 2024-11-19 08:44:35 +01:00
nds32 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nios2 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
openrisc Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
parisc parisc: Strip upper 32 bit of sum in csum_ipv6_magic for 64-bit builds 2024-11-19 09:22:16 +01:00
powerpc powerpc: xor_vmx: Add '-mhard-float' to CFLAGS 2024-11-19 09:22:41 +01:00
riscv riscv: Fix spurious errors from __get/put_kernel_nofault 2024-11-19 09:23:10 +01:00
s390 s390/entry: align system call table on 8 bytes 2024-11-19 09:23:10 +01:00
sh sh: bios: Revive earlyprintk support 2024-11-18 11:43:04 +01:00
sparc sparc: vDSO: fix return value of __setup handler 2024-11-19 09:22:15 +01:00
um um: allow not setting extra rpaths in the linux binary 2024-11-18 23:19:35 +01:00
x86 x86/head/64: Re-enable stack protection 2024-11-19 09:23:16 +01:00
xtensa Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00