diff options
author | Petr Benes <w.benny@outlook.com> | 2018-08-04 17:32:18 +0300 |
---|---|---|
committer | Petr Benes <w.benny@outlook.com> | 2018-08-05 13:45:52 +0300 |
commit | 3581425b5bed4905db4460cd3ee1f4897d0d5cad (patch) | |
tree | e62dc7ec35a5eccc87aeef4ccf6a9c60a652b8c1 | |
parent | a2efa4b6c0e9191afe4b3d164941db8fa7b1f337 (diff) |
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.
-rw-r--r-- | nt/shvos.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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; } |