3 SEV fixes backport
v2 cover 3 SEV fixes backport
Hi Greg, hi Sasha,
Please consider to apply these 3 fixes failed to apply to stable-6.12, I've tested it on EPYC Turin/Milan with kvm-unit-tests and basic Confidential VM functional test.
Regards!
Jack Wang @ IONOS Cloud
v2->v1: fix the bugs noticed by Tom for first 2 patches
Sean Christopherson (3):
KVM: SEV: Ignore MMIO requests of length '0'
KVM: SEV: Reject MMIO requests larger than 8 bytes with GHCB v2+
KVM: SEV: Ignore Port I/O requests of length '0'
arch/x86/kvm/svm/sev.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Signature · 1 line
2.43.0
PATCH v2 1/3 KVM: SEV: Ignore MMIO requests of length '0'
From: Sean Christopherson <[email protected]>
commit 1aa8a6dc7dac8b83234b53518311bf78231f4fa5 upstream.
Explicitly ignore MMIO requests of length '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 special casing '0' in the future.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/kvm/svm/sev.c +6 -0
@@ -4347,6 +4347,9 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) exit_code =kvm_ghcb_get_sw_exit_code (control);switch (exit_code) {case SVM_VMGEXIT_MMIO_READ : +if (!control->exit_info_2) +return 1 ; + ret =setup_vmgexit_scratch (svm, true, control->exit_info_2);if (ret)break ;
@@ -4357,6 +4360,9 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) svm->sev_es.ghcb_sa);break ;case SVM_VMGEXIT_MMIO_WRITE : +if (!control->exit_info_2) +return 1 ; + ret =setup_vmgexit_scratch (svm, false, control->exit_info_2);if (ret)break ;
Signature · 1 line
2.43.0
Re: [stable-6.12 v2 1/3] KVM: SEV: Ignore MMIO requests of length '0'
Quoted 9 lines · Jack Wang
From: Sean Christopherson <[email protected]>
commit
1aa8a6dc7dac8b83234b53518311bf78231f4fa5upstream.Explicitly ignore MMIO requests of length '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 special casing '0' in the future.
Quoted 6 lines
Fixes 8f423a80d299 ("KVM: SVM: Support MMIO for an SEV-ES guest")Reviewed-by Tom Lendacky <[email protected]>Signed-off-by Sean Christopherson <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
When sending backports, please document what was changed. Doing so saves maintainer time and is very helpful in case there's a problem with the backport.
[Jack: Duplicate the fix to the split READ/WRITE paths]
Quoted 1 line
Signed-off-by Jack Wang <[email protected]>
Re: [stable-6.12 v2 1/3] KVM: SEV: Ignore MMIO requests of length '0'
Quoted 18 lines · Sean Christopherson
Quoted 9 lines · Jack Wang
From: Sean Christopherson <[email protected]>
commit
1aa8a6dc7dac8b83234b53518311bf78231f4fa5upstream.Explicitly ignore MMIO requests of length '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 special casing '0' in the future.
Quoted 6 lines
Fixes 8f423a80d299 ("KVM: SVM: Support MMIO for an SEV-ES guest")Reviewed-by Tom Lendacky <[email protected]>Signed-off-by Sean Christopherson <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
Quoted 8 lines
When sending backports, please document what was changed. Doing so saves maintainer time and is very helpful in case there's a problem with the backport.
[Jack: Duplicate the fix to the split READ/WRITE paths]
Quoted 1 line
Signed-off-by Jack Wang <[email protected]>
Hi Sean,
Understood, I'll make sure to document changes in future backports. Thanks for the heads up.
Thx!
PATCH v2 2/3 KVM: SEV: Reject MMIO requests larger than 8 bytes with GHCB v2+
In reply to Jack WangFrom: Sean Christopherson <[email protected]>
commit dcf1b2d4b0564a27e4ca7c654871aab4f9620046 upstream.
When using GHCB v2+, reject MMIO requests that are larger than 8 bytes. Per the GHCB spec:
SW_EXITINFO2 must be less than or equal to 0x7fffffff for version 1 and less than or equal to 0x8 for all other versions.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/x86/kvm/svm/sev.c +14 -0
@@ -4350,6 +4350,13 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)if (!control->exit_info_2)return 1 ; +if (to_kvm_sev_info (vcpu->kvm)->ghcb_version >=2 && + control->exit_info_2 >8 ) { +ghcb_set_sw_exit_info_1 (svm->sev_es.ghcb,2 ); +ghcb_set_sw_exit_info_2 (svm->sev_es.ghcb,GHCB_ERR_INVALID_INPUT ); +return 1 ; + } + ret =setup_vmgexit_scratch (svm, true, control->exit_info_2);if (ret)break ;
@@ -4363,6 +4370,13 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)if (!control->exit_info_2)return 1 ; +if (to_kvm_sev_info (vcpu->kvm)->ghcb_version >=2 && + control->exit_info_2 >8 ) { +ghcb_set_sw_exit_info_1 (svm->sev_es.ghcb,2 ); +ghcb_set_sw_exit_info_2 (svm->sev_es.ghcb,GHCB_ERR_INVALID_INPUT ); +return 1 ; + } + ret =setup_vmgexit_scratch (svm, false, control->exit_info_2);if (ret)break ;
Signature · 1 line
2.43.0
Re: [stable-6.12 v2 2/3] KVM: SEV: Reject MMIO requests larger than 8 bytes with GHCB v2+
Quoted 10 lines · Jack Wang
From: Sean Christopherson <[email protected]>
commit
dcf1b2d4b0564a27e4ca7c654871aab4f9620046upstream.When using GHCB v2+, reject MMIO requests that are larger than 8 bytes. Per the GHCB spec:
SW_EXITINFO2must be less than or equal to0x7ffffffffor version 1 and less than or equal to0x8for all other versions.
Quoted 6 lines
Fixes 4af663c2f64a ("KVM: SEV: Allow per-guest configuration of GHCB protocol version")Reviewed-by Tom Lendacky <[email protected]>Signed-off-by Sean Christopherson <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
Same comment about documentation the changes.
[Jack: Open code response as svm_vmgexit_bad_input() doesn't exist in 6.12,
nor does GHCB_HV_RESP_MALFORMED_INPUT (the literal '2'). Duplicate fix to split READ/WRITE paths. ]
Quoted 1 line
Signed-off-by Jack Wang <[email protected]>
PATCH v2 3/3 KVM: SEV: Ignore Port I/O requests of length '0'
In reply to Jack WangFrom: Sean Christopherson <[email protected]>
commit 3988bd2723de407ae90fa7a6f6029b4e60238c58 upstream.
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.
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/sev.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/kvm/svm/sev.c +8 -0
@@ -4459,6 +4459,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, exit_code); }
@@ -4479,6 +4484,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;
Signature · 1 line
2.43.0
Re: [stable-6.12 v2 3/3] KVM: SEV: Ignore Port I/O requests of length '0'
Quoted 9 lines · Jack Wang
From: Sean Christopherson <[email protected]>
commit
3988bd2723de407ae90fa7a6f6029b4e60238c58upstream.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.
Quoted 8 lines
Fixes 291bd20d5d88 ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT")Reviewed-by Tom Lendacky <[email protected]>Signed-off-by Sean Christopherson <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>Signed-off-by Jack Wang <[email protected]>---
Sasha Levin
maintainerQuoted 1 line · Jack Wang
[stable-6.12 v2 0/3] 3 SEV fixes backport
Queued the v2 series for 6.12.
Signature · 2 lines
Thanks, Sasha