Skip to content

Commit

Permalink
deadlock fixes for loaderlock
Browse files Browse the repository at this point in the history
  • Loading branch information
tarterp committed Nov 17, 2023
1 parent e0a329e commit bdc3de4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions C/STrace/PluginData.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ class PluginData {

// don't use isLoaded() here because of locking
if (loaded) {
return STATUS_ALREADY_INITIALIZED;
status = STATUS_ALREADY_INITIALIZED;
goto exit;
}

status = ZwLoadDriver(&pluginServiceName);
if (!NT_SUCCESS(status)) {
LOG_ERROR("ZwLoadDriver Failed with: 0x%08X", status);
LOG_ERROR("ZwLoadDriver Failed with: 0x%08X\r\n", status);
goto exit;
}
InterlockedIncrement(&loaded);

status = setPluginBaseAddress();
if (!NT_SUCCESS(status)){
LOG_ERROR("setPluginBaseAddress failed to find plugin");
LOG_ERROR("setPluginBaseAddress failed to find plugin\n");
goto exit;
}

Expand All @@ -72,7 +73,7 @@ class PluginData {
pDtEtwpEventCallback = (tDtEtwpEventCallback)getExport("DtEtwpEventCallback");

if((pCallbackEntry && pCallbackReturn && pIsTarget) == 0){
LOG_ERROR("Failed to acquire plugin exports");
LOG_ERROR("Failed to acquire plugin exports\r\n");
status = STATUS_PROCEDURE_NOT_FOUND;
goto exit;
}
Expand All @@ -95,21 +96,22 @@ class PluginData {
if(!locked) lock();
if (!loaded){
status = STATUS_ALREADY_COMPLETE;
goto exit;
}

status = ZwUnloadDriver(&pluginServiceName);
if (!NT_SUCCESS(status)){
// If driver doesn't unload, then it is still loaded and we should
// return the plugin to a loaded state and return an error
LOG_INFO("[!] Failed to unload plugin driver");
LOG_INFO("[!] Failed to unload plugin driver\r\n");
goto exit;
}
InterlockedDecrement(&loaded);
zero();

status = STATUS_SUCCESS;
exit:
if(locked)unlock();
if(!locked)unlock();
return status;

}
Expand Down

0 comments on commit bdc3de4

Please sign in to comment.