From a2efa4b6c0e9191afe4b3d164941db8fa7b1f337 Mon Sep 17 00:00:00 2001 From: Parallel Xenoexcite Date: Fri, 3 Aug 2018 08:45:52 +0200 Subject: [PATCH 1/2] Remove unnecessary VM_EXIT_ACK_INTR_ON_EXIT flag Setting VM_EXIT_ACK_INTR_ON_EXIT makes sense only when PIN_BASED_EXT_INTR is set (see Intel Manual Vol3C[24.7.1(VM-Exit Controls)]). --- shvvmx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/shvvmx.c b/shvvmx.c index 06d5303..d7e9958 100644 --- a/shvvmx.c +++ b/shvvmx.c @@ -361,12 +361,10 @@ ShvVmxSetupVmcsForVp ( CPU_BASED_ACTIVATE_SECONDARY_CONTROLS)); // - // If any interrupts were pending upon entering the hypervisor, acknowledge - // them when we're done. And make sure to enter us in x64 mode at all times + // Make sure to enter us in x64 mode at all times. // __vmx_vmwrite(VM_EXIT_CONTROLS, ShvUtilAdjustMsr(VpData->MsrData[15], - VM_EXIT_ACK_INTR_ON_EXIT | VM_EXIT_IA32E_MODE)); // From 3581425b5bed4905db4460cd3ee1f4897d0d5cad Mon Sep 17 00:00:00 2001 From: Petr Benes Date: Sat, 4 Aug 2018 16:32:18 +0200 Subject: [PATCH 2/2] Fix BSOD on shutdown when DriverEntry fails The registered power callback needs to be unregistered when ShvLoad happens to fail, as DriverUnload is not called when DriverEntry does not succeed. Code before patch allowed to create a situation, where ShvLoad in DriverEntry failed, which resulted in the leak of PowerCallback, which - on machine shutdown/reboot - resulted in critical pagefault in the area of the unloaded driver and the system went blue. --- nt/shvos.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nt/shvos.c b/nt/shvos.c index 532fcf0..4017525 100644 --- a/nt/shvos.c +++ b/nt/shvos.c @@ -418,6 +418,17 @@ DriverEntry ( // // Load the hypervisor // - return ShvOsErrorToError(ShvLoad()); + status = ShvOsErrorToError(ShvLoad()); + + // + // If load of the hypervisor happened to fail, unregister previously registered + // power callback, otherwise we would get BSOD on shutdown. + // + if (!NT_SUCCESS(status)) + { + ExUnregisterCallback(g_PowerCallbackRegistration); + } + + return status; }