public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: x86: Don't report guest userspace emulation error to userspace in kvm_task_switch()
@ 2025-04-16 13:43 Chen Yufeng
  2025-04-16 14:12 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Yufeng @ 2025-04-16 13:43 UTC (permalink / raw)
  To: seanjc; +Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm, chenyufeng

This patch prevents that emulation failures which result from emulating
task switch for an L2-Guest results in being reported to userspace.

Without this patch a malicious L2-Guest would be able to kill the L1 by 
triggering a race-condition between an vmexit and the task switch emulator.

This patch is smiliar to commit fc3a9157d314 ("KVM: X86: Don't report L2 
emulation failures to user-space")

Fixes: 1051778f6e1e ("KVM: x86: Handle emulation failure directly in kvm_task_switch()")

Signed-off-by: Chen Yufeng <chenyufeng@iie.ac.cn>
---
 arch/x86/kvm/x86.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 3712dde0bf9d..b22be88196ed 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11874,9 +11874,11 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index,
 	 */
 	if (ret || vcpu->mmio_needed) {
 		vcpu->mmio_needed = false;
-		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
-		vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
-		vcpu->run->internal.ndata = 0;
+		if (!is_guest_mode(vcpu)) {
+			vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+			vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
+			vcpu->run->internal.ndata = 0;
+		}
 		return 0;
 	}
 
-- 
2.34.1


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

end of thread, other threads:[~2025-04-17  4:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 13:43 [PATCH] kvm: x86: Don't report guest userspace emulation error to userspace in kvm_task_switch() Chen Yufeng
2025-04-16 14:12 ` Sean Christopherson
2025-04-17  3:55   ` Chen Yufeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox