Skip to content

Commit ec791c3

Browse files
committed
fix segment limits
They are supposed to be 32-bits not 16-bits, this was really stupid I am not even sure if I confused them with selectors or what happened but this caused a MAJOR HAVOC!!! Now it's stable... I shall be deported and deprecated for this. Signed-off-by: Ahmed Samy <[email protected]>
1 parent 7b62c23 commit ec791c3

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

exit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,9 @@ static inline bool nested_handles_exception(const struct nested_vcpu *nested)
27212721
u32 except_bitmap = __nested_vmcs_read32(nested->vmcs, EXCEPTION_BITMAP);
27222722
u32 intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
27232723
u32 vector = intr_info & INTR_INFO_VECTOR_MASK;
2724+
if (__EXCEPTION_BITMAP & (1 << vector))
2725+
return false;
2726+
27242727
return except_bitmap & (1 << vector);
27252728
}
27262729

mm.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ extern uintptr_t pte_base;
107107
#define __pte_idx(addr) (((addr) >> PTI_SHIFT) & PTX_MASK)
108108

109109
#ifndef __linux__
110-
#define __pa(va) MmGetPhysicalAddress((void *)(va)).QuadPart
111-
#define __va(pa) (uintptr_t *)MmGetVirtualForPhysical((PHYSICAL_ADDRESS) { .QuadPart = (pa) })
110+
#define __pa(va) \
111+
MmGetPhysicalAddress((void *)(va)).QuadPart
112+
#define __va(pa) \
113+
(uintptr_t *)MmGetVirtualForPhysical((PHYSICAL_ADDRESS) { .QuadPart = (uintptr_t)(pa) })
112114
#endif
113115

114116
#define page_align(addr) ((uintptr_t)(addr) & ~(PAGE_SIZE - 1))
@@ -430,7 +432,7 @@ static inline void *mm_alloc_page(void)
430432
#ifndef __linux__
431433
void *v = ExAllocatePool(NonPagedPool, PAGE_SIZE);
432434
if (v)
433-
__stosq(v, 00, PAGE_SIZE >> 3);
435+
__stosq(v, 0, PAGE_SIZE >> 3);
434436

435437
return v;
436438
#else

vcpu.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ bool ept_handle_violation(struct vcpu *vcpu)
400400
if (eptp_switch != eptp)
401401
vcpu_switch_root_eptp(vcpu, eptp_switch);
402402

403-
__invept_all();
404403
return true;
405404
}
406405

@@ -475,7 +474,6 @@ static u8 setup_vmcs(struct vcpu *vcpu, uintptr_t gsp, uintptr_t gip)
475474
struct ept *ept = &vcpu->ept;
476475

477476
u64 vmx = __readmsr(MSR_IA32_VMX_BASIC);
478-
u32 verr;
479477
u16 es = __reades();
480478
u16 cs = __readcs();
481479
u16 ss = __readss();
@@ -484,6 +482,7 @@ static u8 setup_vmcs(struct vcpu *vcpu, uintptr_t gsp, uintptr_t gip)
484482
u16 gs = __readgs();
485483
u16 ldt = __sldt();
486484
u16 tr = __str();
485+
u32 verr;
487486
u8 err = 0;
488487

489488
uintptr_t cr0 = __readcr0();
@@ -564,7 +563,9 @@ static u8 setup_vmcs(struct vcpu *vcpu, uintptr_t gsp, uintptr_t gip)
564563
| SECONDARY_EXEC_ENABLE_VMFUNC
565564
#endif
566565
| SECONDARY_EXEC_ENABLE_VE
566+
#if 0
567567
| /* apic virtualization */ apicv
568+
#endif
568569
#if defined(_WIN32_WINNT) && _WIN32_WINNT == 0x0A00 /* w10 required features */
569570
| SECONDARY_EXEC_RDTSCP
570571
#endif
@@ -584,8 +585,10 @@ static u8 setup_vmcs(struct vcpu *vcpu, uintptr_t gsp, uintptr_t gip)
584585

585586
u32 vm_cpuctl = CPU_BASED_ACTIVATE_SECONDARY_CONTROLS | CPU_BASED_USE_MSR_BITMAPS |
586587
CPU_BASED_USE_IO_BITMAPS;
588+
#if 0
587589
if (vm_2ndctl & apicv)
588590
vm_cpuctl |= CPU_BASED_TPR_SHADOW;
591+
#endif
589592
adjust_ctl_val(MSR_IA32_VMX_PROCBASED_CTLS + msr_off, &vm_cpuctl);
590593
vcpu->cpu_ctl = vm_cpuctl;
591594

@@ -620,7 +623,6 @@ static u8 setup_vmcs(struct vcpu *vcpu, uintptr_t gsp, uintptr_t gip)
620623
err |= vmcs_write16(POSTED_INTR_NV, 0);
621624
err |= vmcs_write64(POSTED_INTR_DESC_ADDR, __pa(&vcpu->pi_desc));
622625
}
623-
#endif
624626

625627
/* Full APIC virtualization if any available. */
626628
if (vm_2ndctl & apicv) {
@@ -641,6 +643,7 @@ static u8 setup_vmcs(struct vcpu *vcpu, uintptr_t gsp, uintptr_t gip)
641643
__readmsr(MSR_IA32_APICBASE_BASE) & MSR_IA32_APICBASE_BASE);
642644
}
643645
}
646+
#endif
644647

645648
/* CR0/CR4 controls */
646649
err |= vmcs_write(CR0_GUEST_HOST_MASK, vcpu->cr0_guest_host_mask);
@@ -654,7 +657,7 @@ static u8 setup_vmcs(struct vcpu *vcpu, uintptr_t gsp, uintptr_t gip)
654657

655658
/* See if we need to emulate VMFUNC via a VMCALL */
656659
if (vm_2ndctl & SECONDARY_EXEC_ENABLE_VMFUNC) {
657-
err |= vmcs_write(VM_FUNCTION_CTRL, VM_FUNCTION_CTL_EPTP_SWITCHING);
660+
err |= vmcs_write64(VM_FUNCTION_CTRL, VM_FUNCTION_CTL_EPTP_SWITCHING);
658661
err |= vmcs_write64(EPTP_LIST_ADDRESS, __pa(ept->ptr_list));
659662
} else {
660663
/* Enable emulation for VMFUNC */
@@ -695,16 +698,16 @@ static u8 setup_vmcs(struct vcpu *vcpu, uintptr_t gsp, uintptr_t gip)
695698
err |= vmcs_write16(GUEST_GS_SELECTOR, gs);
696699
err |= vmcs_write16(GUEST_LDTR_SELECTOR, ldt);
697700
err |= vmcs_write16(GUEST_TR_SELECTOR, tr);
698-
err |= vmcs_write16(GUEST_ES_LIMIT, __segmentlimit(es));
699-
err |= vmcs_write16(GUEST_CS_LIMIT, __segmentlimit(cs));
700-
err |= vmcs_write16(GUEST_SS_LIMIT, __segmentlimit(ss));
701-
err |= vmcs_write16(GUEST_DS_LIMIT, __segmentlimit(ds));
702-
err |= vmcs_write16(GUEST_FS_LIMIT, __segmentlimit(fs));
703-
err |= vmcs_write16(GUEST_GS_LIMIT, __segmentlimit(gs));
704-
err |= vmcs_write16(GUEST_LDTR_LIMIT, __segmentlimit(ldt));
705-
err |= vmcs_write16(GUEST_TR_LIMIT, __segmentlimit(tr));
706-
err |= vmcs_write16(GUEST_GDTR_LIMIT, gdtr.limit);
707-
err |= vmcs_write16(GUEST_IDTR_LIMIT, idtr->limit);
701+
err |= vmcs_write32(GUEST_ES_LIMIT, __segmentlimit(es));
702+
err |= vmcs_write32(GUEST_CS_LIMIT, __segmentlimit(cs));
703+
err |= vmcs_write32(GUEST_SS_LIMIT, __segmentlimit(ss));
704+
err |= vmcs_write32(GUEST_DS_LIMIT, __segmentlimit(ds));
705+
err |= vmcs_write32(GUEST_FS_LIMIT, __segmentlimit(fs));
706+
err |= vmcs_write32(GUEST_GS_LIMIT, __segmentlimit(gs));
707+
err |= vmcs_write32(GUEST_LDTR_LIMIT, __segmentlimit(ldt));
708+
err |= vmcs_write32(GUEST_TR_LIMIT, __segmentlimit(tr));
709+
err |= vmcs_write32(GUEST_GDTR_LIMIT, gdtr.limit);
710+
err |= vmcs_write32(GUEST_IDTR_LIMIT, idtr->limit);
708711
err |= vmcs_write32(GUEST_ES_AR_BYTES, __accessright(es));
709712
err |= vmcs_write32(GUEST_CS_AR_BYTES, __accessright(cs));
710713
err |= vmcs_write32(GUEST_SS_AR_BYTES, __accessright(ss));

0 commit comments

Comments
 (0)