0292-x86-svm-Set-IBRS-value-on-VM-entry-and-exit.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Tom Lendacky <[email protected]>
  3. Date: Wed, 20 Dec 2017 10:55:47 +0000
  4. Subject: [PATCH] x86/svm: Set IBRS value on VM entry and exit
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5753
  9. CVE-2017-5715
  10. Set/restore the guests IBRS value on VM entry. On VM exit back to the
  11. kernel save the guest IBRS value and then set IBRS to 1.
  12. Signed-off-by: Paolo Bonzini <[email protected]>
  13. Signed-off-by: Tom Lendacky <[email protected]>
  14. Signed-off-by: Andy Whitcroft <[email protected]>
  15. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  16. (cherry picked from commit 72f71e6826fac9a656c3994fb6f979cd65a14c64)
  17. Signed-off-by: Fabian Grünbichler <[email protected]>
  18. ---
  19. arch/x86/kvm/svm.c | 17 +++++++++++++++++
  20. 1 file changed, 17 insertions(+)
  21. diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
  22. index 94adf6becc2e..a1b19e810c49 100644
  23. --- a/arch/x86/kvm/svm.c
  24. +++ b/arch/x86/kvm/svm.c
  25. @@ -175,6 +175,8 @@ struct vcpu_svm {
  26. u64 next_rip;
  27. + u64 spec_ctrl;
  28. +
  29. u64 host_user_msrs[NR_HOST_SAVE_USER_MSRS];
  30. struct {
  31. u16 fs;
  32. @@ -3547,6 +3549,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
  33. case MSR_VM_CR:
  34. msr_info->data = svm->nested.vm_cr_msr;
  35. break;
  36. + case MSR_IA32_SPEC_CTRL:
  37. + msr_info->data = svm->spec_ctrl;
  38. + break;
  39. case MSR_IA32_UCODE_REV:
  40. msr_info->data = 0x01000065;
  41. break;
  42. @@ -3702,6 +3707,9 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
  43. case MSR_VM_IGNNE:
  44. vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data);
  45. break;
  46. + case MSR_IA32_SPEC_CTRL:
  47. + svm->spec_ctrl = data;
  48. + break;
  49. case MSR_IA32_APICBASE:
  50. if (kvm_vcpu_apicv_active(vcpu))
  51. avic_update_vapic_bar(to_svm(vcpu), data);
  52. @@ -4883,6 +4891,9 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
  53. local_irq_enable();
  54. + if (ibrs_inuse && (svm->spec_ctrl != FEATURE_ENABLE_IBRS))
  55. + wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
  56. +
  57. asm volatile (
  58. "push %%" _ASM_BP "; \n\t"
  59. "mov %c[rbx](%[svm]), %%" _ASM_BX " \n\t"
  60. @@ -4975,6 +4986,12 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
  61. #endif
  62. );
  63. + if (ibrs_inuse) {
  64. + rdmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
  65. + if (svm->spec_ctrl != FEATURE_ENABLE_IBRS)
  66. + wrmsrl(MSR_IA32_SPEC_CTRL, FEATURE_ENABLE_IBRS);
  67. + }
  68. +
  69. #ifdef CONFIG_X86_64
  70. wrmsrl(MSR_GS_BASE, svm->host.gs_base);
  71. #else
  72. --
  73. 2.14.2