linux-brain/arch/x86/boot/compressed
Arvind Sankar 624c2782b4 x86/asm: Replace __force_order with a memory clobber
[ Upstream commit aa5cacdc29d76a005cbbee018a47faa6e724dd2d ]

The CRn accessor functions use __force_order as a dummy operand to
prevent the compiler from reordering CRn reads/writes with respect to
each other.

The fact that the asm is volatile should be enough to prevent this:
volatile asm statements should be executed in program order. However GCC
4.9.x and 5.x have a bug that might result in reordering. This was fixed
in 8.1, 7.3 and 6.5. Versions prior to these, including 5.x and 4.9.x,
may reorder volatile asm statements with respect to each other.

There are some issues with __force_order as implemented:
- It is used only as an input operand for the write functions, and hence
  doesn't do anything additional to prevent reordering writes.
- It allows memory accesses to be cached/reordered across write
  functions, but CRn writes affect the semantics of memory accesses, so
  this could be dangerous.
- __force_order is not actually defined in the kernel proper, but the
  LLVM toolchain can in some cases require a definition: LLVM (as well
  as GCC 4.9) requires it for PIE code, which is why the compressed
  kernel has a definition, but also the clang integrated assembler may
  consider the address of __force_order to be significant, resulting in
  a reference that requires a definition.

Fix this by:
- Using a memory clobber for the write functions to additionally prevent
  caching/reordering memory accesses across CRn writes.
- Using a dummy input operand with an arbitrary constant address for the
  read functions, instead of a global variable. This will prevent reads
  from being reordered across writes, while allowing memory loads to be
  cached/reordered across CRn reads, which should be safe.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82602
Link: https://lore.kernel.org/lkml/20200527135329.1172644-1-arnd@arndb.de/
Link: https://lkml.kernel.org/r/20200902232152.3709896-1-nivedita@alum.mit.edu
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-10-29 09:58:01 +01:00
..
.gitignore x86, boot: add new generated files to the appropriate .gitignore files 2009-06-02 21:13:30 -07:00
acpi.c x86/boot: Handle malformed SRAT tables during early ACPI parsing 2020-02-14 16:34:11 -05:00
cmdline.c x86/boot: Build the command line parsing code unconditionally 2019-02-01 11:51:01 +01:00
cpuflags.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
early_serial_console.c x86, boot: Don't compile early_serial_console.c when !CONFIG_EARLY_PRINTK 2014-08-17 14:58:24 -07:00
eboot.c x86, efi: Never relocate kernel below lowest acceptable address 2019-10-31 09:40:19 +01:00
eboot.h efi/x86: Align efi_uga_draw_protocol typedef names to convention 2018-07-22 14:13:42 +02:00
efi_stub_32.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
efi_stub_64.S x86/efi: Avoid triple faults during EFI mixed mode calls 2015-02-13 15:42:56 +00:00
efi_thunk_64.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
error.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
error.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
head_32.S x86/boot: Correct relocation destination on old linkers 2020-06-22 09:31:07 +02:00
head_64.S x86/boot: Correct relocation destination on old linkers 2020-06-22 09:31:07 +02:00
kaslr_64.c x86/boot/compressed: Don't declare __force_order in kaslr_64.c 2020-03-12 13:00:15 +01:00
kaslr.c x86/boot/KASLR: Always return a value from process_mem_region 2019-03-06 22:55:30 +01:00
Makefile x86/boot/compressed: Disable relocation relaxation 2020-09-23 12:40:46 +02:00
mem_encrypt.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
misc.c x86/boot/64: Round memory hole size up to next PMD page 2019-10-11 18:47:23 +02:00
misc.h x86, boot: Remove multiple copy of static function sanitize_boot_params() 2019-07-18 21:41:57 +02:00
mkpiggy.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 268 2019-06-05 17:30:29 +02:00
pgtable_64.c x86/asm: Replace __force_order with a memory clobber 2020-10-29 09:58:01 +01:00
pgtable.h x86/boot/compressed/64: Set EFER.LME=1 in 32-bit trampoline before returning to long mode 2019-01-29 21:58:59 +01:00
string.c x86/boot: Provide KASAN compatible aliases for string routines 2019-05-24 08:44:16 +02:00
vmlinux.lds.S x86/build: Use the single-argument OUTPUT_FORMAT() linker script command 2019-01-16 12:21:53 +01:00