linux-stable/arch
Alexandre Chartre a765679def 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:18:44 +02:00
..
alpha rtc: Add support for configuring the UIP timeout for RTC reads 2024-01-31 16:17:01 -08:00
arc ARC: [plat-hsdk]: Remove misplaced interrupt-cells property 2024-05-02 16:29:23 +02:00
arm ARM: davinci: Convert comma to semicolon 2024-07-18 13:18:36 +02:00
arm64 arm64: dts: rockchip: Fix the DCDC_REG2 minimum voltage on Quartz64 Model B 2024-07-11 12:47:16 +02:00
csky csky, hexagon: fix broken sys_sync_file_range 2024-07-05 09:31:57 +02:00
hexagon hexagon: fix fadvise64_64 calling conventions 2024-07-05 09:31:57 +02:00
ia64 ia64/cpu: Switch to arch_cpu_finalize_init() 2023-08-08 20:03:46 +02:00
loongarch LoongArch: Fix callchain parse error with kernel tracepoint events again 2024-06-12 11:03:43 +02:00
m68k m68k: mac: Fix reboot hang on Mac IIci 2024-06-12 11:03:17 +02:00
microblaze microblaze: Remove early printk call from cpuinfo-static.c 2024-06-12 11:03:39 +02:00
mips syscalls: fix compat_sys_io_pgetevents_time64 usage 2024-07-05 09:31:59 +02:00
nios2
openrisc mm: always expand the stack with the mmap write lock held 2023-07-01 13:16:25 +02:00
parisc parisc: use generic sys_fanotify_mark implementation 2024-07-05 09:31:51 +02:00
powerpc powerpc/pseries: Fix scv instruction crash with kexec 2024-07-11 12:47:15 +02:00
riscv riscv: kexec: Avoid deadlock in kexec crash path 2024-07-11 12:47:12 +02:00
s390 s390: Mark psw in __load_psw_mask() as __unitialized 2024-07-18 13:18:35 +02:00
sh sh: rework sync_file_range ABI 2024-07-05 09:31:57 +02:00
sparc syscalls: fix compat_sys_io_pgetevents_time64 usage 2024-07-05 09:31:59 +02:00
um um: Fix the declaration of kasan_map_memory 2024-06-12 11:03:48 +02:00
x86 x86/bhi: Avoid warning in #DB handler due to BHI mitigation 2024-07-18 13:18:44 +02:00
xtensa xtensa: fix MAKE_PC_FROM_RA second argument 2024-06-21 14:35:39 +02:00
.gitignore
Kconfig Revert "mm: mmap: allow for the maximum number of bits for randomizing mmap_base by default" 2024-06-27 13:46:24 +02:00