The VMCB12 is stored in guest memory and can be mangled while in SMM; it is then reloaded by svm_leave_smm(), but it is not checked again for validity. Move the cached vmcb12 control and save consistency checks out of svm_set_nested_state() and into a helper, and reuse it in svm_leave_smm().
Unified · Split
| @@ -418,6 +418,15 @@ static bool nested_vmcb_check_controls(struct kvm_vcpu *vcpu) · 417 unmodified lines | |||
| 418 | return __nested_vmcb_check_controls(vcpu, ctl); | 418 | return __nested_vmcb_check_controls(vcpu, ctl); |
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | int nested_svm_check_cached_vmcb12(struct kvm_vcpu *vcpu) | ||
| 422 | { | ||
| 423 | if (!nested_vmcb_check_save(vcpu) || | ||
| 424 | !nested_vmcb_check_controls(vcpu)) | ||
| 425 | return -EINVAL; | ||
| 426 | |||
| 427 | return 0; | ||
| 428 | } | ||
| 429 | |||
| 421 | /* | 430 | /* |
| 422 | * If a feature is not advertised to L1, clear the corresponding vmcb12 | 431 | * If a feature is not advertised to L1, clear the corresponding vmcb12 |
| 423 | * intercept. | 432 | * intercept. |
| @@ -1028,8 +1037,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu) · 604 unmodified lines | |||
| 1028 | nested_copy_vmcb_control_to_cache(svm, &vmcb12->control); | 1037 | nested_copy_vmcb_control_to_cache(svm, &vmcb12->control); |
| 1029 | nested_copy_vmcb_save_to_cache(svm, &vmcb12->save); | 1038 | nested_copy_vmcb_save_to_cache(svm, &vmcb12->save); |
| 1030 | 1039 | ||
| 1031 | if (!nested_vmcb_check_save(vcpu) || | 1040 | if (nested_svm_check_cached_vmcb12(vcpu) < 0) { |
| 1032 | !nested_vmcb_check_controls(vcpu)) { | ||
| 1033 | vmcb12->control.exit_code = SVM_EXIT_ERR; | 1041 | vmcb12->control.exit_code = SVM_EXIT_ERR; |
| 1034 | vmcb12->control.exit_info_1 = 0; | 1042 | vmcb12->control.exit_info_1 = 0; |
| 1035 | vmcb12->control.exit_info_2 = 0; | 1043 | vmcb12->control.exit_info_2 = 0; |
| @@ -4880,6 +4880,10 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram) · 4879 unmodified lines | |||
| 4880 | vmcb12 = map.hva; | 4880 | vmcb12 = map.hva; |
| 4881 | nested_copy_vmcb_control_to_cache(svm, &vmcb12->control); | 4881 | nested_copy_vmcb_control_to_cache(svm, &vmcb12->control); |
| 4882 | nested_copy_vmcb_save_to_cache(svm, &vmcb12->save); | 4882 | nested_copy_vmcb_save_to_cache(svm, &vmcb12->save); |
| 4883 | |||
| 4884 | if (nested_svm_check_cached_vmcb12(vcpu) < 0) | ||
| 4885 | goto unmap_save; | ||
| 4886 | |||
| 4883 | ret = enter_svm_guest_mode(vcpu, smram64->svm_guest_vmcb_gpa, vmcb12, false); | 4887 | ret = enter_svm_guest_mode(vcpu, smram64->svm_guest_vmcb_gpa, vmcb12, false); |
| 4884 | 4888 | ||
| 4885 | if (ret) | 4889 | if (ret) |
| @@ -797,6 +797,7 @@ static inline int nested_svm_simple_vmexit(struct vcpu_svm *svm, u32 exit_code) · 796 unmodified lines | |||
| 797 | 797 | ||
| 798 | int nested_svm_exit_handled(struct vcpu_svm *svm); | 798 | int nested_svm_exit_handled(struct vcpu_svm *svm); |
| 799 | int nested_svm_check_permissions(struct kvm_vcpu *vcpu); | 799 | int nested_svm_check_permissions(struct kvm_vcpu *vcpu); |
| 800 | int nested_svm_check_cached_vmcb12(struct kvm_vcpu *vcpu); | ||
| 800 | int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, | 801 | int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, |
| 801 | bool has_error_code, u32 error_code); | 802 | bool has_error_code, u32 error_code); |
| 802 | int nested_svm_exit_special(struct vcpu_svm *svm); | 803 | int nested_svm_exit_special(struct vcpu_svm *svm); |