Skip to content

Commit

Permalink
Fix BSOD on shutdown when DriverEntry fails
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wbenny committed Aug 4, 2018
1 parent a2efa4b commit 3c108e5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion nt/shvos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 3c108e5

Please sign in to comment.