x86/CPU/AMD: Fix the DIV(0) initial fix attempt
Borislav Petkov
maintainerPATCH 1/1 x86/CPU/AMD: Fix the DIV(0) initial fix attempt
From: "Borislav Petkov (AMD)" <[email protected]>
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.
--- arch/x86/include/asm/entry-common.h | 1 + arch/x86/kernel/cpu/amd.c | 1 + arch/x86/kernel/traps.c | 2 -- arch/x86/kvm/svm/svm.c | 2 ++ 4 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/entry-common.h +1 -0
@@ -92,6 +92,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
arch/x86/kernel/cpu/amd.c +1 -0
@@ -1328,3 +1328,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);
arch/x86/kernel/traps.c +0 -2
@@ -206,8 +206,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)
arch/x86/kvm/svm/svm.c +2 -0
@@ -4006,6 +4006,8 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_inguest_state_enter_irqoff (); +amd_clear_divider (); +if (sev_es_guest (vcpu->kvm))__svm_sev_es_vcpu_run (svm, spec_ctrl_intercepted);else
Signature · 1 line
2.42.0.rc0.25.ga82fb66fed25
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: f58d6fbcb7c848b7f2469be339bc571f2e9d245b Gitweb: https://git.kernel.org/tip/f58d6fbcb7c848b7f2469be339bc571f2e9d245b Author: Borislav Petkov (AMD) <[email protected]> AuthorDate: Fri, 11 Aug 2023 23:38:24 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Mon, 14 Aug 2023 11:02:50 +02:00
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.
--- arch/x86/include/asm/entry-common.h | 1 + arch/x86/kernel/cpu/amd.c | 1 + arch/x86/kernel/traps.c | 2 -- arch/x86/kvm/svm/svm.c | 2 ++ 4 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/entry-common.h +1 -0
@@ -92,6 +92,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
arch/x86/kernel/cpu/amd.c +1 -0
@@ -1329,3 +1329,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);
arch/x86/kernel/traps.c +0 -2
@@ -206,8 +206,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)
arch/x86/kvm/svm/svm.c +2 -0
@@ -4006,6 +4006,8 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_inguest_state_enter_irqoff (); +amd_clear_divider (); +if (sev_es_guest (vcpu->kvm))__svm_sev_es_vcpu_run (svm, spec_ctrl_intercepted);else