Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177782142
D61794.1795272398.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D61794.1795272398.diff
View Options
diff --git a/sys/amd64/vmm/intel/vmx_nested.c b/sys/amd64/vmm/intel/vmx_nested.c
--- a/sys/amd64/vmm/intel/vmx_nested.c
+++ b/sys/amd64/vmm/intel/vmx_nested.c
@@ -108,7 +108,9 @@
#define VMX_MISC_CR3_TARGETS(n) ((uint64_t)(n) << 16)
#define VMX_MISC_CR3_COUNT(m) (((m) >> 16) & 0x1ff)
+#define VMX_MISC_INJECT_LEN0 (1U << 30)
#define VMCS_ACTIVITY_HLT 1
+#define VMCS_INTR_RESERVED 0x7ffff000
/*
* The default1 controls, which the MSRs that are not the TRUE ones report as
@@ -174,6 +176,7 @@
/* Exit qualifications of a VM-entry failure with the guest state (SDM 27.8). */
#define EXIT_QUAL_ENTRY_NONE 0
#define EXIT_QUAL_ENTRY_PDPTE 2
+#define EXIT_QUAL_ENTRY_LINK 4
/* VMX-abort indicators (SDM 28.7). */
#define VMX_ABORT_MSR_STORE 1
@@ -879,10 +882,61 @@
return (true);
}
+/*
+ * The fields for the event to inject (SDM 27.2.1.3). The CPU checks them
+ * too when it enters vmcs02, but that is after the checks on L2's state
+ * that are made here, and these come first. L1 has no unrestricted guest,
+ * so L2 is in protected mode, and IA32_VMX_BASIC[56] is 0 for L1.
+ */
+static bool
+nested_event_valid(struct vmx_nested *nested)
+{
+ uint32_t info, len, vector;
+ bool errcode;
+
+ info = V12(nested, VMCS_ENTRY_INTR_INFO);
+ if ((info & VMCS_INTR_VALID) == 0)
+ return (true);
+ vector = info & 0xff;
+ errcode = false;
+ switch (info & VMCS_INTR_T_MASK) {
+ case VMCS_INTR_T_HWINTR:
+ break;
+ case VMCS_INTR_T_NMI:
+ if (vector != IDT_NMI)
+ return (false);
+ break;
+ case VMCS_INTR_T_HWEXCEPTION:
+ if (vector > 31)
+ return (false);
+ errcode = vector == IDT_DF || vector == IDT_TS ||
+ vector == IDT_NP || vector == IDT_SS ||
+ vector == IDT_GP || vector == IDT_PF || vector == IDT_AC;
+ break;
+ case VMCS_INTR_T_SWINTR:
+ case VMCS_INTR_T_PRIV_SWEXCEPTION:
+ case VMCS_INTR_T_SWEXCEPTION:
+ len = V12(nested, VMCS_ENTRY_INST_LENGTH);
+ if (len > 15 || (len == 0 &&
+ (NESTED_MSR(MSR_VMX_MISC) & VMX_MISC_INJECT_LEN0) == 0))
+ return (false);
+ break;
+ default:
+ /* Reserved, or "other event" without the monitor trap flag. */
+ return (false);
+ }
+ if (((info & VMCS_INTR_DEL_ERRCODE) != 0) != errcode ||
+ (info & VMCS_INTR_RESERVED) != 0)
+ return (false);
+ if (errcode && (V12(nested, VMCS_ENTRY_EXCEPTION_ERROR) &
+ 0xffff0000) != 0)
+ return (false);
+ return (true);
+}
+
/*
* The checks on the VMX controls (SDM 27.2.1), as far as the controls are
- * offered to L1. The fields for the event to inject are checked by the CPU
- * when it enters vmcs02. Returns 0 or a VM-instruction error.
+ * offered to L1. Returns 0 or a VM-instruction error.
*/
static int
nested_check_ctls(struct vmx_nested *nested)
@@ -927,6 +981,8 @@
!nested_msr_area_valid(V12(nested, VMCS_ENTRY_MSR_LOAD),
V12(nested, VMCS_ENTRY_MSR_LOAD_COUNT)))
return (VMXERR_ENTRY_CTLS);
+ if (!nested_event_valid(nested))
+ return (VMXERR_ENTRY_CTLS);
return (0);
}
@@ -982,8 +1038,38 @@
}
/*
- * Merge vmcs12 into vmcs02 for a VM entry. The CPU does the checks on L2's
- * state (SDM 27.3.1) when it enters vmcs02. Fails if the PDPTEs of an L2
+ * The checks on L2's state that the CPU cannot do when it enters vmcs02
+ * (SDM 27.3.1.1, 27.3.1.5). The host sets and clears the bits of CR0 and
+ * CR4 that are fixed, so the CPU never sees what L1 has put there, and
+ * vmcs02 has no VMCS link pointer. L1 has no VMCS shadowing: a VMCS that
+ * the link pointer points to must be an ordinary one. Returns false with
+ * the exit qualification of the failed VM entry.
+ */
+static bool
+nested_check_guest_state(struct vmx_vcpu *vcpu, uint64_t *qual)
+{
+ struct vmx_nested *nested = vcpu->nested;
+ uint64_t link;
+ uint32_t revision;
+
+ *qual = EXIT_QUAL_ENTRY_NONE;
+ if (!nested_cr0_valid(V12(nested, VMCS_GUEST_CR0)) ||
+ !nested_cr4_valid(V12(nested, VMCS_GUEST_CR4)))
+ return (false);
+ link = V12(nested, VMCS_LINK_POINTER);
+ if (link != ~0UL) {
+ *qual = EXIT_QUAL_ENTRY_LINK;
+ if (!nested_ptr_valid(link) || !nested_copy(vcpu, link,
+ &revision, sizeof(revision), false) ||
+ revision != VMCS12_REVISION)
+ return (false);
+ }
+ return (true);
+}
+
+/*
+ * Merge vmcs12 into vmcs02 for a VM entry. The CPU does the other checks on
+ * L2's state (SDM 27.3.1) when it enters vmcs02. Fails if the PDPTEs of an L2
* with PAE paging cannot be read.
*/
static int
@@ -1165,6 +1251,7 @@
nested_enter(struct vmx_vcpu *vcpu, bool launch)
{
struct vmx_nested *nested = vcpu->nested;
+ uint64_t qual;
u_int i;
int error;
@@ -1206,6 +1293,10 @@
EXIT_QUAL_ENTRY_NONE);
return;
}
+ if (!nested_check_guest_state(vcpu, &qual)) {
+ nested_entry_failure(vcpu, EXIT_REASON_INVAL_VMCS, qual);
+ return;
+ }
if (nested_vmcs02_load(vcpu) != 0) {
nested_entry_failure(vcpu, EXIT_REASON_INVAL_VMCS,
EXIT_QUAL_ENTRY_PDPTE);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 21, 2:46 PM (20 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41890787
Default Alt Text
D61794.1795272398.diff (4 KB)
Attached To
Mode
D61794: vmm: Add the checks on VM entry that the CPU cannot do for nested VMX
Attached
Detach File
Event Timeline