Skip to content

Commit 9b0971c

Browse files
committed
KVM: SEV-ES: fix another issue with string I/O VMGEXITs
If the guest requests string I/O from the hypervisor via VMGEXIT, SW_EXITINFO2 will contain the REP count. However, sev_es_string_io was incorrectly treating it as the size of the GHCB buffer in bytes. This fixes the "outsw" test in the experimental SEV tests of kvm-unit-tests. Cc: [email protected] Fixes: 7ed9abf ("KVM: SVM: Support string IO operations for an SEV-ES guest") Reported-by: Marc Orr <[email protected]> Tested-by: Marc Orr <[email protected]> Reviewed-by: Marc Orr <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0985dba commit 9b0971c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,11 +2579,20 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
25792579

25802580
int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in)
25812581
{
2582-
if (!setup_vmgexit_scratch(svm, in, svm->vmcb->control.exit_info_2))
2582+
int count;
2583+
int bytes;
2584+
2585+
if (svm->vmcb->control.exit_info_2 > INT_MAX)
2586+
return -EINVAL;
2587+
2588+
count = svm->vmcb->control.exit_info_2;
2589+
if (unlikely(check_mul_overflow(count, size, &bytes)))
2590+
return -EINVAL;
2591+
2592+
if (!setup_vmgexit_scratch(svm, in, bytes))
25832593
return -EINVAL;
25842594

2585-
return kvm_sev_es_string_io(&svm->vcpu, size, port,
2586-
svm->ghcb_sa, svm->ghcb_sa_len / size, in);
2595+
return kvm_sev_es_string_io(&svm->vcpu, size, port, svm->ghcb_sa, count, in);
25872596
}
25882597

25892598
void sev_es_init_vmcb(struct vcpu_svm *svm)

0 commit comments

Comments
 (0)