Skip to contentSkip to conversation

KVM: nSVM: Check reserved bits in DR6, DR7 and EFER on vmrun of nested guests

PATCH Applied Krish Sadhukhan 2 participants 8 messages May 22, 2020 – Jul 3, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover KVM: nSVM: Check reserved bits in DR6, DR7 and EFER on vmrun of nested guests

Patch# 1: Moves the check for upper 32 reserved bits of DR6 to a new function. Patch# 2: Adds the KVM checks for DR6[63:32] and DR7[64:32] reserved bits Patch# 3: Adds kvm-unit-tests for DR6[63:32] and DR7[64:32] reserved bits and
reserved bits in EFER
Patch# 4: Removes the duplicate definition of 'vmcb' that sneaked via one of
my previous patches.

[PATCH 1/4] KVM: x86: Move the check for upper 32 reserved bits of [PATCH 2/4] KVM: nSVM: Check that DR6[63:32] and DR7[64:32] are not [PATCH 3/4] kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] [PATCH 4/4] kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

 arch/x86/kvm/svm/nested.c | 3 +++
 arch/x86/kvm/x86.c        | 2 +-
 arch/x86/kvm/x86.h        | 5 +++++
 3 files changed, 9 insertions(+), 1 deletion(-)

Krish Sadhukhan (2):
KVM: x86: Move the check for upper 32 reserved bits of DR6 to separate fun
KVM: nVMX: Check that DR6[63:32] and DR7[64:32] are not set on vmrun of ne

 x86/svm.c       |  1 -
 x86/svm.h       |  3 +++
 x86/svm_tests.c | 59 ++++++++++++++++++++++++++++++++++++++-------------------
 3 files changed, 42 insertions(+), 21 deletions(-)

Krish Sadhukhan (2):
kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] and EFER reserved b
kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

#1 lore raw

PATCH 1/4 KVM: x86: Move the check for upper 32 reserved bits of DR6 to separate function

---
 arch/x86/kvm/x86.c | 2 +-
 arch/x86/kvm/x86.h | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/x86.c +1 -1
index c17e6eb..4746ec1 100644
@@ -1096,7 +1096,7 @@ static int __kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val)
 	case 4:
 		/* fall through */
 	case 6:
-		if (val & 0xffffffff00000000ULL)
+		if (!kvm_dr6_valid(val))
 			return -1; /* #GP */
 		vcpu->arch.dr6 = (val & DR6_VOLATILE) | kvm_dr6_fixed(vcpu);
 		break;
arch/x86/kvm/x86.h +5 -0
index b968acc..5043108 100644
@@ -354,6 +354,11 @@ static inline bool kvm_dr7_valid(u64 data)
 	/* Bits [63:32] are reserved */
 	return !(data >> 32);
 }
+static inline bool kvm_dr6_valid(u64 data)
+{
+	/* Bits [63:32] are reserved */
+	return !(data >> 32);
+}
 
 void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu);
 void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu);
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/4 KVM: nSVM: Check that DR6[63:32] and DR7[64:32] are not set on vmrun of nested guests

In reply to Krish Sadhukhan

According to section "Canonicalization and Consistency Checks" in APM vol. 2 the following guest state is illegal:

    "DR6[63:32] are not zero."
    "DR7[63:32] are not zero."
    "Any MBZ bit of EFER is set."
---
 arch/x86/kvm/svm/nested.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kvm/svm/nested.c +3 -0
index 9a2a62e..2fec51d 100644
@@ -208,6 +208,9 @@ static bool nested_vmcb_checks(struct vmcb *vmcb)
 	if ((vmcb->save.efer & EFER_SVME) == 0)
 		return false;
 
+	if (!kvm_dr6_valid(vmcb->save.dr6) || !kvm_dr7_valid(vmcb->save.dr7))
+		return false;
+
 	if ((vmcb->control.intercept & (1ULL << INTERCEPT_VMRUN)) == 0)
 		return false;
 
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/4 kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] and EFER reserved bits are not set on vmrun of nested guests

In reply to Krish Sadhukhan

According to section "Canonicalization and Consistency Checks" in APM vol. 2 the following guest state is illegal:

    "DR6[63:32] are not zero."
    "DR7[63:32] are not zero."
    "Any MBZ bit of EFER is set."
---
 x86/svm.h       |  3 +++
 x86/svm_tests.c | 59 ++++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 42 insertions(+), 20 deletions(-)
x86/svm.h +3 -0
index 3d5b79c..14418ef 100644
@@ -329,6 +329,9 @@ struct __attribute__ ((__packed__)) vmcb {
 #define	SVM_CR3_LONG_RESERVED_MASK		0xfff0000000000fe7U
 #define	SVM_CR4_LEGACY_RESERVED_MASK		0xffbaf000U
 #define	SVM_CR4_RESERVED_MASK			0xffffffffffbaf000U
+#define	SVM_DR6_RESERVED_MASK			0xffffffffffff1ff0U
+#define	SVM_DR7_RESERVED_MASK			0xffffffff0000cc00U
+#define	SVM_EFER_RESERVED_MASK			0xffffffffffff0200U
 
 #define MSR_BITMAP_SIZE 8192
 
x86/svm_tests.c +39 -20

108 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/4 kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

In reply to Krish Sadhukhan
---
 x86/svm.c | 1 -
 1 file changed, 1 deletion(-)
x86/svm.c +0 -1
index 41685bf..f984a60 100644
@@ -201,7 +201,6 @@ struct regs get_regs(void)
 #define LOAD_GPR_C      SAVE_GPR_C
 
 struct svm_test *v2_test;
-struct vmcb *vmcb;
 
 #define ASM_VMRUN_CMD                           \
                 "vmload %%rax\n\t"              \
Signature · 1 line
1.8.3.1
maintainer Applied
#5 lore raw
In reply to Krish Sadhukhan
Quoted 21 lines · Krish Sadhukhan

Patch# 1: Moves the check for upper 32 reserved bits of DR6 to a new function. Patch# 2: Adds the KVM checks for DR6[63:32] and DR7[64:32] reserved bits Patch# 3: Adds kvm-unit-tests for DR6[63:32] and DR7[64:32] reserved bits and
reserved bits in EFER
Patch# 4: Removes the duplicate definition of 'vmcb' that sneaked via one of
my previous patches.

[PATCH 1/4] KVM: x86: Move the check for upper 32 reserved bits of [PATCH 2/4] KVM: nSVM: Check that DR6[63:32] and DR7[64:32] are not [PATCH 3/4] kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] [PATCH 4/4] kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

 arch/x86/kvm/svm/nested.c | 3 +++
 arch/x86/kvm/x86.c        | 2 +-
 arch/x86/kvm/x86.h        | 5 +++++
 3 files changed, 9 insertions(+), 1 deletion(-)

Krish Sadhukhan (2):
KVM: x86: Move the check for upper 32 reserved bits of DR6 to separate fun
KVM: nVMX: Check that DR6[63:32] and DR7[64:32] are not set on vmrun of ne

Quoted 9 lines
 x86/svm.c       |  1 -
 x86/svm.h       |  3 +++
 x86/svm_tests.c | 59 ++++++++++++++++++++++++++++++++++++++-------------------
 3 files changed, 42 insertions(+), 21 deletions(-)

Krish Sadhukhan (2):
kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] and EFER reserved b
kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

Queued, thanks.

Paolo

#6 lore raw
In reply to Krish Sadhukhan

Ping.

Quoted 30 lines · Krish Sadhukhan

Patch# 1: Moves the check for upper 32 reserved bits of DR6 to a new function. Patch# 2: Adds the KVM checks for DR6[63:32] and DR7[64:32] reserved bits Patch# 3: Adds kvm-unit-tests for DR6[63:32] and DR7[64:32] reserved bits and
reserved bits in EFER
Patch# 4: Removes the duplicate definition of 'vmcb' that sneaked via one of
my previous patches.

[PATCH 1/4] KVM: x86: Move the check for upper 32 reserved bits of [PATCH 2/4] KVM: nSVM: Check that DR6[63:32] and DR7[64:32] are not [PATCH 3/4] kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] [PATCH 4/4] kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

  arch/x86/kvm/svm/nested.c | 3 +++
  arch/x86/kvm/x86.c        | 2 +-
  arch/x86/kvm/x86.h        | 5 +++++
  3 files changed, 9 insertions(+), 1 deletion(-)

Krish Sadhukhan (2):
KVM: x86: Move the check for upper 32 reserved bits of DR6 to separate fun
KVM: nVMX: Check that DR6[63:32] and DR7[64:32] are not set on vmrun of ne

  x86/svm.c       |  1 -
  x86/svm.h       |  3 +++
  x86/svm_tests.c | 59 ++++++++++++++++++++++++++++++++++++++-------------------
  3 files changed, 42 insertions(+), 21 deletions(-)

Krish Sadhukhan (2):
kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] and EFER reserved b
kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

maintainer Applied
#7 lore raw
Quoted 41 lines · Krish Sadhukhan

Ping.

Quoted 37 lines · Krish Sadhukhan

Patch# 1: Moves the check for upper 32 reserved bits of DR6 to a new function.
Patch# 2: Adds the KVM checks for DR6[63:32] and DR7[64:32] reserved bits Patch# 3: Adds kvm-unit-tests for DR6[63:32] and DR7[64:32] reserved bits and
      reserved bits in EFER
Patch# 4: Removes the duplicate definition of 'vmcb' that sneaked via one of
      my previous patches.

[PATCH 1/4] KVM: x86: Move the check for upper 32 reserved bits of [PATCH 2/4] KVM: nSVM: Check that DR6[63:32] and DR7[64:32] are not [PATCH 3/4] kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] [PATCH 4/4] kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

  arch/x86/kvm/svm/nested.c | 3 +++
  arch/x86/kvm/x86.c        | 2 +-
  arch/x86/kvm/x86.h        | 5 +++++

  3 files changed, 9 insertions(+), 1 deletion(-)

Krish Sadhukhan (2):
       KVM: x86: Move the check for upper 32 reserved bits of DR6 to separate fun
       KVM: nVMX: Check that DR6[63:32] and DR7[64:32] are not set on vmrun of ne
  x86/svm.c       |  1 -
  x86/svm.h       |  3 +++
  x86/svm_tests.c | 59
++++++++++++++++++++++++++++++++++++++-------------------

  3 files changed, 42 insertions(+), 21 deletions(-)

Krish Sadhukhan (2):
       kvm-unit-tests: nSVM: Test that DR6[63:32], DR7[63:32] and EFER reserved b
       kvm-unit-tests: x86: Remove duplicate instance of 'vmcb'

Queued, thanks.

Paolo