Skip to contentSkip to conversation

3 SEV fixes backport

PATCH In review Jack Wang 3 participants 9 messages Jun 26 – Jul 1 Stable branch

lore
Share & tools
lore

Jack Wang

author
#0 lore raw

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
author
#1 lore raw

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.

Fixes 8f423a80d299 ("KVM: SVM: Support MMIO for an SEV-ES guest")

Message-ID: <[email protected]>

---
 arch/x86/kvm/svm/sev.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/kvm/svm/sev.c +6 -0
index 115c59c86f44..0a01971e33f0 100644
@@ -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
Acked-by on v2 1/3
#2 lore raw

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 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.

Quoted 6 lines
Fixes 8f423a80d299 ("KVM: SVM: Support MMIO for an SEV-ES guest")

Message-ID: <[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
author
#3 lore raw

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 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.

Quoted 6 lines
Fixes 8f423a80d299 ("KVM: SVM: Support MMIO for an SEV-ES guest")

Message-ID: <[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

Hi Sean,

Understood, I'll make sure to document changes in future backports. Thanks for the heads up.

Thx!

author
#4 lore raw

PATCH v2 2/3 KVM: SEV: Reject MMIO requests larger than 8 bytes with GHCB v2+

In reply to Jack Wang

From: 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.

Fixes 4af663c2f64a ("KVM: SEV: Allow per-guest configuration of GHCB protocol version")

Message-ID: <[email protected]>

---
 arch/x86/kvm/svm/sev.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/x86/kvm/svm/sev.c +14 -0
index 0a01971e33f0..497a6e705135 100644
@@ -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
Acked-by on v2 2/3
#5 lore raw

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 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.

Quoted 6 lines
Fixes 4af663c2f64a ("KVM: SEV: Allow per-guest configuration of GHCB protocol version")

Message-ID: <[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
author
#6 lore raw

PATCH v2 3/3 KVM: SEV: Ignore Port I/O requests of length '0'

In reply to Jack Wang

From: 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.

Fixes 291bd20d5d88 ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT")

Message-ID: <[email protected]>

---
 arch/x86/kvm/svm/sev.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/kvm/svm/sev.c +8 -0
index 497a6e705135..73e493177351 100644
@@ -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
Acked-by on v2 3/3
#7 lore raw

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 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.

Quoted 8 lines
Fixes 291bd20d5d88 ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT")

Message-ID: <[email protected]>

---

maintainer
#8 lore raw
In reply to Jack Wang
Quoted 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