OpenCloudOS-Kernel/arch/x86
Alexandre Chartre dae3543db8 x86/bhi: Avoid warning in #DB handler due to BHI mitigation
[ Upstream commit ac8b270b61d48fcc61f052097777e3b5e11591e0 ]

When BHI mitigation is enabled, if SYSENTER is invoked with the TF flag set
then entry_SYSENTER_compat() uses CLEAR_BRANCH_HISTORY and calls the
clear_bhb_loop() before the TF flag is cleared. This causes the #DB handler
(exc_debug_kernel()) to issue a warning because single-step is used outside the
entry_SYSENTER_compat() function.

To address this issue, entry_SYSENTER_compat() should use CLEAR_BRANCH_HISTORY
after making sure the TF flag is cleared.

The problem can be reproduced with the following sequence:

  $ cat sysenter_step.c
  int main()
  { asm("pushf; pop %ax; bts $8,%ax; push %ax; popf; sysenter"); }

  $ gcc -o sysenter_step sysenter_step.c

  $ ./sysenter_step
  Segmentation fault (core dumped)

The program is expected to crash, and the #DB handler will issue a warning.

Kernel log:

  WARNING: CPU: 27 PID: 7000 at arch/x86/kernel/traps.c:1009 exc_debug_kernel+0xd2/0x160
  ...
  RIP: 0010:exc_debug_kernel+0xd2/0x160
  ...
  Call Trace:
  <#DB>
   ? show_regs+0x68/0x80
   ? __warn+0x8c/0x140
   ? exc_debug_kernel+0xd2/0x160
   ? report_bug+0x175/0x1a0
   ? handle_bug+0x44/0x90
   ? exc_invalid_op+0x1c/0x70
   ? asm_exc_invalid_op+0x1f/0x30
   ? exc_debug_kernel+0xd2/0x160
   exc_debug+0x43/0x50
   asm_exc_debug+0x1e/0x40
  RIP: 0010:clear_bhb_loop+0x0/0xb0
  ...
  </#DB>
  <TASK>
   ? entry_SYSENTER_compat_after_hwframe+0x6e/0x8d
  </TASK>

  [ bp: Massage commit message. ]

Fixes: 7390db8aea0d ("x86/bhi: Add support for clearing branch history at syscall entry")
Reported-by: Suman Maity <suman.m.maity@oracle.com>
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Reviewed-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://lore.kernel.org/r/20240524070459.3674025-1-alexandre.chartre@oracle.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-07-18 13:21:27 +02:00
..
boot x86/boot: Don't add the EFI stub to targets, again 2024-06-21 14:38:37 +02:00
coco x86/coco: Require seeding RNG with RDRAND on CoCo systems 2024-04-10 16:36:03 +02:00
configs - The first, cleanup part of the microcode loader reorg tglx has been 2023-08-28 15:55:20 -07:00
crypto crypto: x86/sha512-avx2 - add missing vzeroupper 2024-06-12 11:11:32 +02:00
entry x86/bhi: Avoid warning in #DB handler due to BHI mitigation 2024-07-18 13:21:27 +02:00
events perf/x86: Fix out of range data 2024-04-17 11:19:36 +02:00
hyperv x86/hyperv: Use per cpu initial stack for vtl context 2024-03-26 18:20:06 -04:00
ia32
include x86/entry: Rename ignore_sysret() 2024-07-18 13:21:26 +02:00
kernel x86/entry: Rename ignore_sysret() 2024-07-18 13:21:26 +02:00
kvm KVM: x86: Always sync PIR to IRR prior to scanning I/O APIC routes 2024-06-27 13:49:11 +02:00
lib x86/uaccess: Fix missed zeroing of ia32 u64 get_user() range checking 2024-06-21 14:38:34 +02:00
math-emu x86/fpu: Include asm/fpu/regset.h 2023-05-18 11:56:18 -07:00
mm mm: fix race between __split_huge_pmd_locked() and GUP-fast 2024-06-16 13:47:40 +02:00
net Revert "bpf: Take return from set_memory_rox() into account with bpf_jit_binary_lock_ro()" 2024-07-09 11:44:29 +02:00
pci x86/pci: Skip early E820 check for ECAM region 2024-06-12 11:13:01 +02:00
platform efi/x86: Free EFI memory map only when installing a new one. 2024-06-27 13:49:13 +02:00
power mm/treewide: replace pud_large() with pud_leaf() 2024-04-10 16:35:46 +02:00
purgatory x86/purgatory: Switch to the position-independent small code model 2024-06-12 11:11:43 +02:00
ras
realmode x86/realmode: Make stack lock work in trampoline_compat() 2023-05-30 14:11:47 +02:00
tools x86/boot: Ignore relocations in .notes sections in walk_relocs() too 2024-06-12 11:11:36 +02:00
um um: Fix the -Wmissing-prototypes warning for get_thread_reg 2024-06-12 11:12:42 +02:00
video Merge drm/drm-next into drm-misc-next 2023-07-24 15:44:47 +02:00
virt/vmx/tdx
xen xen/x86: add extra pages to unpopulated-alloc if available 2024-06-12 11:12:46 +02:00
.gitignore
Kbuild
Kconfig cpu: Ignore "mitigations" kernel parameter if CPU_MITIGATIONS=n 2024-06-12 11:11:24 +02:00
Kconfig.assembler x86/shstk: Add Kconfig option for shadow stack 2023-07-11 14:12:18 -07:00
Kconfig.cpu x86/Kconfig: Transmeta Crusoe is CPU family 5, not 6 2024-02-23 09:25:10 +01:00
Kconfig.debug x86/kconfig: Select ARCH_WANT_FRAME_POINTERS again when UNWINDER_FRAME_POINTER=y 2024-06-12 11:12:46 +02:00
Makefile kbuild: unify vdso_install rules 2024-06-12 11:12:32 +02:00
Makefile.postlink x86/build: Avoid relocation information in final vmlinux 2023-06-14 19:54:40 +02:00
Makefile.um um: Only disable SSE on clang to work around old GCC bugs 2023-04-04 09:57:05 +02:00
Makefile_32.cpu