Skip to content

Commit f58d6fb

Browse files
committed
x86/CPU/AMD: Fix the DIV(0) initial fix attempt
Initially, it was thought that doing an innocuous division in the #DE handler would take care to prevent any leaking of old data from the divider but by the time the fault is raised, the speculation has already advanced too far and such data could already have been used by younger operations. Therefore, do the innocuous division on every exit to userspace so that userspace doesn't see any potentially old data from integer divisions in kernel space. Do the same before VMRUN too, to protect host data from leaking into the guest too. Fixes: 77245f1 ("x86/CPU/AMD: Do not leak quotient data after a division by 0") Signed-off-by: Borislav Petkov (AMD) <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ba5ca5e commit f58d6fb

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

arch/x86/include/asm/entry-common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
9292
static __always_inline void arch_exit_to_user_mode(void)
9393
{
9494
mds_user_clear_cpu_buffers();
95+
amd_clear_divider();
9596
}
9697
#define arch_exit_to_user_mode arch_exit_to_user_mode
9798

arch/x86/kernel/cpu/amd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,3 +1329,4 @@ void noinstr amd_clear_divider(void)
13291329
asm volatile(ALTERNATIVE("", "div %2\n\t", X86_BUG_DIV0)
13301330
:: "a" (0), "d" (0), "r" (1));
13311331
}
1332+
EXPORT_SYMBOL_GPL(amd_clear_divider);

arch/x86/kernel/traps.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ DEFINE_IDTENTRY(exc_divide_error)
206206
{
207207
do_error_trap(regs, 0, "divide error", X86_TRAP_DE, SIGFPE,
208208
FPE_INTDIV, error_get_trap_addr(regs));
209-
210-
amd_clear_divider();
211209
}
212210

213211
DEFINE_IDTENTRY(exc_overflow)

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4006,6 +4006,8 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_in
40064006

40074007
guest_state_enter_irqoff();
40084008

4009+
amd_clear_divider();
4010+
40094011
if (sev_es_guest(vcpu->kvm))
40104012
__svm_sev_es_vcpu_run(svm, spec_ctrl_intercepted);
40114013
else

0 commit comments

Comments
 (0)