]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: SEV: Ignore Port I/O requests of length '0'
authorSean Christopherson <seanjc@google.com>
Fri, 1 May 2026 20:22:29 +0000 (13:22 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 29 May 2026 18:25:28 +0000 (20:25 +0200)
Explicitly ignore Port I/O requests of length '0' (or count '0'), so that
setting up the software scratch area (and other code) doesn't have to
worry about underflowing the length, and to allow for WARNing on trying
to configure the scratch area with len==0.

Fixes: 291bd20d5d88 ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT")
Cc: stable@vger.kernel.org
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20260501202250.2115252-5-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/sev.c

index e6579ca9f364fc144dda22369d63fb05861808b0..52703c9548568c54e268abd1a1979ff9f51d58be 100644 (file)
@@ -4585,6 +4585,11 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
                            control->exit_info_1, control->exit_info_2);
                ret = -EINVAL;
                break;
+       case SVM_EXIT_IOIO:
+               if (!((control->exit_info_1 & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT))
+                       return 1;
+
+               fallthrough;
        default:
                ret = svm_invoke_exit_handler(vcpu, control->exit_code);
        }
@@ -4605,6 +4610,9 @@ int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in)
        if (unlikely(check_mul_overflow(count, size, &bytes)))
                return -EINVAL;
 
+       if (!bytes)
+               return 1;
+
        r = setup_vmgexit_scratch(svm, in, bytes);
        if (r)
                return r;