KVM: SVM: Fix fault-rip on vmsave/vmload emulation
PATCH 1/1 KVM: SVM: Fix fault-rip on vmsave/vmload emulation
When the emulation of vmload or vmsave fails because the guest passed an unsupported physical address it gets an #GP with rip pointing to the instruction after vmsave/vmload. This is a bug and fixed by this patch.
--- arch/x86/kvm/svm.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +6 -6
@@ -2407,13 +2407,13 @@ static int vmload_interception(struct vcpu_svm *svm)if (nested_svm_check_permissions (svm))return 1 ; - svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; -skip_emulated_instruction (&svm->vcpu); - nested_vmcb =nested_svm_map (svm, svm->vmcb->save.rax, &page);if (!nested_vmcb)return 1 ; + svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); +nested_svm_vmloadsave (nested_vmcb, svm->vmcb);nested_svm_unmap (page);
@@ -2428,13 +2428,13 @@ static int vmsave_interception(struct vcpu_svm *svm)if (nested_svm_check_permissions (svm))return 1 ; - svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; -skip_emulated_instruction (&svm->vcpu); - nested_vmcb =nested_svm_map (svm, svm->vmcb->save.rax, &page);if (!nested_vmcb)return 1 ; + svm->next_rip =kvm_rip_read (&svm->vcpu) +3 ; +skip_emulated_instruction (&svm->vcpu); +nested_svm_vmloadsave (svm->vmcb, nested_vmcb);nested_svm_unmap (page);
Signature · 1 line
1.7.1
Avi Kivity
AppliedQuoted 5 lines · Joerg Roedel
When the emulation of vmload or vmsave fails because the guest passed an unsupported physical address it gets an #GP with rip pointing to the instruction after vmsave/vmload. This is a bug and fixed by this patch.
Applied, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Joerg Roedel
When the emulation of vmload or vmsave fails because the guest passed an unsupported physical address it gets an #GP with rip pointing to the instruction after vmsave/vmload. This is a bug and fixed by this patch.
Applied, thanks.
btw, I think the actual address check is incorrect, need to check MAXPHYADDR and not hardcoded 0xffff000000000000.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 5 lines · Joerg Roedel
When the emulation of vmload or vmsave fails because the guest passed an unsupported physical address it gets an #GP with rip pointing to the instruction after vmsave/vmload. This is a bug and fixed by this patch.
Quoted 5 lines
Quoted 2 lines
Applied, thanks.
btw, I think the actual address check is incorrect, need to check MAXPHYADDR and not hardcoded
0xffff000000000000.
There is a difference. MAX_PHYSADDR_BITS is the maximum Linux can support while the mask above is the current limit the hardware supports.
It is the same on real hardware, when rax is >= (1<<48) there is a #GP (and no intercept if in guest-mode). Here is btw. a difference between nested-svm and hardware-svm, if rax contains a physical address which is supported but not backed by RAM the machine will just freeze on real hardware where as in nested-svm it causes a #GP (should be fine because the behavior in this case is undefined).
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
Quoted 12 lines · Joerg
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Joerg Roedel
When the emulation of vmload or vmsave fails because the guest passed an unsupported physical address it gets an #GP with rip pointing to the instruction after vmsave/vmload. This is a bug and fixed by this patch.
Applied, thanks.
Quoted 6 lines
Quoted 2 lines
btw, I think the actual address check is incorrect, need to check MAXPHYADDR and not hardcoded
0xffff000000000000.There is a difference.
MAX_PHYSADDR_BITSis the maximum Linux can support while the mask above is the current limit the hardware supports.
I'm talking about MAXPHYADDR, the result of cpuid(0x80000008).eax[0:7].
(IIRC with the current page table format the absolute limit is 53 bits while the current limit is 48 bits).
Quoted 7 lines
It is the same on real hardware, when rax is>= (1<<48) there is a #GP (and no intercept if in guest-mode). Here is btw. a difference between nested-svm and hardware-svm, if rax contains a physical address which is supported but not backed by RAM the machine will just freeze on real hardware where as in nested-svm it causes a #GP (should be fine because the behavior in this case is undefined).
In this case the behaviour before the patch was correct too :)
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 16 lines · Avi Kivity
Quoted 15 lines · Joerg
Quoted 13 lines · Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Joerg Roedel
When the emulation of vmload or vmsave fails because the guest passed an unsupported physical address it gets an #GP with rip pointing to the instruction after vmsave/vmload. This is a bug and fixed by this patch.
Applied, thanks.
btw, I think the actual address check is incorrect, need to check MAXPHYADDR and not hardcoded
0xffff000000000000.
Quoted 8 lines
Quoted 3 lines
There is a difference.
MAX_PHYSADDR_BITSis the maximum Linux can support while the mask above is the current limit the hardware supports.I'm talking about MAXPHYADDR, the result of cpuid(0x80000008).eax[0:7].
(IIRC with the current page table format the absolute limit is 53 bits while the current limit is 48 bits).
Architectural limit is 52 bits, hardware implementation limit is 48 currently on most AMD processors (was 40 on K8 and is 36 on Ontario). And yes, this is the correct limit to check against.
Quoted 9 lines
Quoted 7 lines
It is the same on real hardware, when rax is>= (1<<48) there is a #GP (and no intercept if in guest-mode). Here is btw. a difference between nested-svm and hardware-svm, if rax contains a physical address which is supported but not backed by RAM the machine will just freeze on real hardware where as in nested-svm it causes a #GP (should be fine because the behavior in this case is undefined).
In this case the behaviour before the patch was correct too :)
Well ... true :-)
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632