diff options
author | Alex Ionescu <aionescu@gmail.com> | 2017-03-25 19:51:56 +0300 |
---|---|---|
committer | Alex Ionescu <aionescu@gmail.com> | 2017-03-25 19:51:56 +0300 |
commit | 348c552266f89ac5ad2bbf0bf1f8bc449d7b207d (patch) | |
tree | 0cc350af30ee3b84b096a10a55e62e15d8826999 | |
parent | 64f9ae2254c10bdc984e52a34c74af7b65d662b0 (diff) |
Fix bug on unload when no hypervisor loaded. CPUID still returns valid data when leaf is invalid!
To address this, return a magic value in RCX so we can be sure that
RAX:RBX are trustworthy and contain VP_DATA.
-rw-r--r-- | shvvmxhv.c | 4 | ||||
-rw-r--r-- | shvvp.c | 9 |
2 files changed, 8 insertions, 5 deletions
@@ -270,14 +270,16 @@ ShvVmxEntryHandler ( // Did we hit the magic exit sequence, or should we resume back to the VM // context? // - if (guestContext.ExitVm) + if (guestContext.ExitVm != FALSE) { // // Return the VP Data structure in RAX:RBX which is going to be part of // the CPUID response that the caller (ShvVpUninitialize) expects back. + // Return confirmation in RCX that we are loaded // Context->Rax = (uintptr_t)vpData >> 32; Context->Rbx = (uintptr_t)vpData & 0xFFFFFFFF; + Context->Rcx = 0x43434343; // // Perform any OS-specific CPU uninitialization work @@ -172,12 +172,13 @@ ShvVpUnloadCallback ( __cpuidex(cpuInfo, 0x41414141, 0x42424242); // - // If SimpleVisor is disabled for some reason, CPUID won't return anything - // so don't free any memory. It will unfortunately end up leaked. + // If SimpleVisor is disabled for some reason, CPUID will return the values + // of the highest valid CPUID. We use a magic value to make sure we really + // are loaded and returned something valid. // - vpData = (PSHV_VP_DATA)((UINT64)cpuInfo[0] << 32 | (UINT32)cpuInfo[1]); - if (vpData != NULL) + if (cpuInfo[2] == 0x43434343) { + vpData = (PSHV_VP_DATA)((UINT64)cpuInfo[0] << 32 | (UINT32)cpuInfo[1]); ShvOsFreeContiguousAlignedMemory(vpData, sizeof(*vpData)); } } |