linux/arch
Alexandre Chartre 08518d48e5 x86/bhi: Avoid warning in #DB handler due to BHI mitigation
[ Upstream commit ac8b270b61 ]

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: 7390db8aea ("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:22:55 +02:00
..
alpha Kbuild updates for v6.9 2024-03-21 14:41:00 -07:00
arc ARC: [plat-hsdk]: Remove misplaced interrupt-cells property 2024-04-16 10:45:57 -07:00
arm ARM: davinci: Convert comma to semicolon 2024-07-18 13:22:43 +02:00
arm64 arm64: dts: qcom: x1e80100-crd: fix DAI used for headset recording 2024-07-18 13:22:49 +02:00
csky csky, hexagon: fix broken sys_sync_file_range 2024-07-05 09:38:13 +02:00
hexagon hexagon: fix fadvise64_64 calling conventions 2024-07-05 09:38:13 +02:00
loongarch bpf: Take return from set_memory_rox() into account with bpf_jit_binary_lock_ro() 2024-07-05 09:37:57 +02:00
m68k m68k: Move ARCH_HAS_CPU_CACHE_ALIASING 2024-05-30 09:44:34 +02:00
microblaze microblaze: Remove early printk call from cpuinfo-static.c 2024-06-12 11:39:14 +02:00
mips syscalls: fix compat_sys_io_pgetevents_time64 usage 2024-07-05 09:38:16 +02:00
nios2 nios2: Only use built-in devicetree blob if configured to do so 2024-04-03 14:35:53 -05:00
openrisc openrisc: traps: Don't send signals to kernel mode threads 2024-05-30 09:44:21 +02:00
parisc parisc: use generic sys_fanotify_mark implementation 2024-07-05 09:38:04 +02:00
powerpc powerpc/64s: Fix unnecessary copy to 0 when kernel is booted at address 0 2024-07-11 12:51:18 +02:00
riscv riscv: kexec: Avoid deadlock in kexec crash path 2024-07-11 12:51:12 +02:00
s390 s390/mm: Add NULL pointer check to crst_table_free() base_crst_free() 2024-07-18 13:22:47 +02:00
sh sh: rework sync_file_range ABI 2024-07-05 09:38:13 +02:00
sparc syscalls: fix compat_sys_io_pgetevents_time64 usage 2024-07-05 09:38:16 +02:00
um um: Fix the declaration of kasan_map_memory 2024-06-12 11:39:32 +02:00
x86 x86/bhi: Avoid warning in #DB handler due to BHI mitigation 2024-07-18 13:22:55 +02:00
xtensa Xtensa fixes for v6.9: 2024-05-02 10:41:28 -07:00
.gitignore
Kconfig Revert "mm: mmap: allow for the maximum number of bits for randomizing mmap_base by default" 2024-06-27 13:52:32 +02:00