Commit d0767beb authored by Borislav Petkov (AMD)'s avatar Borislav Petkov (AMD) Committed by Jialin Zhang
Browse files

x86/CPU/AMD: Fix the DIV(0) initial fix attempt

stable inclusion
from stable-v5.10.192
commit 69712baf249570a1419e75dc1a103a44e375b2cd
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I7WY4J
CVE: CVE-2023-20588

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=69712baf249570a1419e75dc1a103a44e375b2cd



--------------------------------

commit f58d6fbc upstream.

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: 77245f1c ("x86/CPU/AMD: Do not leak quotient data after a division by 0")
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20230811213824.10025-1-bp@alien8.de


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parent d3a5e492
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
static __always_inline void arch_exit_to_user_mode(void)
{
	mds_user_clear_cpu_buffers();
	amd_clear_divider();
}
#define arch_exit_to_user_mode arch_exit_to_user_mode

+1 −0
Original line number Diff line number Diff line
@@ -1304,3 +1304,4 @@ void noinstr amd_clear_divider(void)
	asm volatile(ALTERNATIVE("", "div %2\n\t", X86_BUG_DIV0)
		     :: "a" (0), "d" (0), "r" (1));
}
EXPORT_SYMBOL_GPL(amd_clear_divider);
+0 −2
Original line number Diff line number Diff line
@@ -207,8 +207,6 @@ DEFINE_IDTENTRY(exc_divide_error)
{
	do_error_trap(regs, 0, "divide error", X86_TRAP_DE, SIGFPE,
		      FPE_INTDIV, error_get_trap_addr(regs));

	amd_clear_divider();
}

DEFINE_IDTENTRY(exc_overflow)
+1 −0
Original line number Diff line number Diff line
@@ -3379,6 +3379,7 @@ static void svm_flush_tlb_gva(struct kvm_vcpu *vcpu, gva_t gva)

static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu)
{
	amd_clear_divider();
}

static inline void sync_cr8_to_lapic(struct kvm_vcpu *vcpu)