All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: nSVM: skip eax alignment check for non-SVM instructions
@ 2022-01-22 20:13 Denis Valeev
  2022-01-22 21:21 ` Maxim Levitsky
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Valeev @ 2022-01-22 20:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm

The bug occurs on #GP triggered by VMware backdoor when eax value is
unaligned. eax alignment check should not be applied to non-SVM
instructions because it leads to incorrect omission of the instructions
emulation.
Apply the alignment check only to SVM instructions to fix.

Fixes: d1cba6c92237 ("KVM: x86: nSVM: test eax for 4K alignment for GP errata workaround")

Signed-off-by: Denis Valeev <lemniscattaden@gmail.com>
---
This bug breaks nyx-fuzz (https://nyx-fuzz.com) that uses VMware backdoor
as an alternative way for hypercall from guest user-mode. With this bug
a hypercall interpreted as a GP and leads to process termination.

 arch/x86/kvm/svm/svm.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index e64f16237b60..b5e4731080ef 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -2233,10 +2233,6 @@ static int gp_interception(struct kvm_vcpu *vcpu)
 	if (error_code)
 		goto reinject;
 
-	/* All SVM instructions expect page aligned RAX */
-	if (svm->vmcb->save.rax & ~PAGE_MASK)
-		goto reinject;
-
 	/* Decode the instruction for usage later */
 	if (x86_decode_emulated_instruction(vcpu, 0, NULL, 0) != EMULATION_OK)
 		goto reinject;
@@ -2254,8 +2250,13 @@ static int gp_interception(struct kvm_vcpu *vcpu)
 		if (!is_guest_mode(vcpu))
 			return kvm_emulate_instruction(vcpu,
 				EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE);
-	} else
+	} else {
+		/* All SVM instructions expect page aligned RAX */
+		if (svm->vmcb->save.rax & ~PAGE_MASK)
+			goto reinject;
+
 		return emulate_svm_instr(vcpu, opcode);
+	}
 
 reinject:
 	kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: x86: nSVM: skip eax alignment check for non-SVM instructions
  2022-01-22 20:13 [PATCH] KVM: x86: nSVM: skip eax alignment check for non-SVM instructions Denis Valeev
@ 2022-01-22 21:21 ` Maxim Levitsky
  0 siblings, 0 replies; 2+ messages in thread
From: Maxim Levitsky @ 2022-01-22 21:21 UTC (permalink / raw)
  To: Denis Valeev, Paolo Bonzini; +Cc: kvm

On Sat, 2022-01-22 at 23:13 +0300, Denis Valeev wrote:
> The bug occurs on #GP triggered by VMware backdoor when eax value is
> unaligned. eax alignment check should not be applied to non-SVM
> instructions because it leads to incorrect omission of the instructions
> emulation.
> Apply the alignment check only to SVM instructions to fix.
> 
> Fixes: d1cba6c92237 ("KVM: x86: nSVM: test eax for 4K alignment for GP errata workaround")
> 
> Signed-off-by: Denis Valeev <lemniscattaden@gmail.com>
> ---
> This bug breaks nyx-fuzz (https://nyx-fuzz.com) that uses VMware backdoor
> as an alternative way for hypercall from guest user-mode. With this bug
> a hypercall interpreted as a GP and leads to process termination.
> 
>  arch/x86/kvm/svm/svm.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index e64f16237b60..b5e4731080ef 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -2233,10 +2233,6 @@ static int gp_interception(struct kvm_vcpu *vcpu)
>  	if (error_code)
>  		goto reinject;
>  
> -	/* All SVM instructions expect page aligned RAX */
> -	if (svm->vmcb->save.rax & ~PAGE_MASK)
> -		goto reinject;
> -
>  	/* Decode the instruction for usage later */
>  	if (x86_decode_emulated_instruction(vcpu, 0, NULL, 0) != EMULATION_OK)
>  		goto reinject;
> @@ -2254,8 +2250,13 @@ static int gp_interception(struct kvm_vcpu *vcpu)
>  		if (!is_guest_mode(vcpu))
>  			return kvm_emulate_instruction(vcpu,
>  				EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE);
> -	} else
> +	} else {
> +		/* All SVM instructions expect page aligned RAX */
> +		if (svm->vmcb->save.rax & ~PAGE_MASK)
> +			goto reinject;
> +
>  		return emulate_svm_instr(vcpu, opcode);
> +	}
>  
>  reinject:
>  	kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);


Oops.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>


Thanks,
Best regards,
	Maxim Levitsky


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-22 21:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-22 20:13 [PATCH] KVM: x86: nSVM: skip eax alignment check for non-SVM instructions Denis Valeev
2022-01-22 21:21 ` Maxim Levitsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.