api: take pool mutex when deleting
This prevents us from racing with driver deletion. Mutexes are recursive, so we shouldn't deadlock if called from Enum. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
7c5233a80e
commit
8ec14e5f6d
@ -1689,6 +1689,13 @@ _Return_type_success_(return != FALSE) BOOL WINAPI WintunDeleteAdapter(
|
|||||||
goto cleanupToken;
|
goto cleanupToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HANDLE Mutex = NamespaceTakePoolMutex(Adapter->Pool);
|
||||||
|
if (!Mutex)
|
||||||
|
{
|
||||||
|
LastError = LOG(WINTUN_LOG_ERR, L"Failed to take pool mutex");
|
||||||
|
goto cleanupToken;
|
||||||
|
}
|
||||||
|
|
||||||
HDEVINFO DevInfo;
|
HDEVINFO DevInfo;
|
||||||
SP_DEVINFO_DATA DevInfoData;
|
SP_DEVINFO_DATA DevInfoData;
|
||||||
if (!GetDevInfoData(&Adapter->CfgInstanceID, &DevInfo, &DevInfoData))
|
if (!GetDevInfoData(&Adapter->CfgInstanceID, &DevInfo, &DevInfoData))
|
||||||
@ -1697,7 +1704,7 @@ _Return_type_success_(return != FALSE) BOOL WINAPI WintunDeleteAdapter(
|
|||||||
LastError = ERROR_SUCCESS;
|
LastError = ERROR_SUCCESS;
|
||||||
else
|
else
|
||||||
LOG(WINTUN_LOG_ERR, L"Failed to get adapter info data");
|
LOG(WINTUN_LOG_ERR, L"Failed to get adapter info data");
|
||||||
goto cleanupToken;
|
goto cleanupMutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ForceCloseSessions && !ForceCloseWintunAdapterHandle(DevInfo, &DevInfoData))
|
if (ForceCloseSessions && !ForceCloseWintunAdapterHandle(DevInfo, &DevInfoData))
|
||||||
@ -1718,6 +1725,8 @@ _Return_type_success_(return != FALSE) BOOL WINAPI WintunDeleteAdapter(
|
|||||||
cleanupDevInfo:
|
cleanupDevInfo:
|
||||||
*RebootRequired = *RebootRequired || CheckReboot(DevInfo, &DevInfoData);
|
*RebootRequired = *RebootRequired || CheckReboot(DevInfo, &DevInfoData);
|
||||||
SetupDiDestroyDeviceInfoList(DevInfo);
|
SetupDiDestroyDeviceInfoList(DevInfo);
|
||||||
|
cleanupMutex:
|
||||||
|
NamespaceReleaseMutex(Mutex);
|
||||||
cleanupToken:
|
cleanupToken:
|
||||||
RevertToSelf();
|
RevertToSelf();
|
||||||
return RET_ERROR(TRUE, LastError);
|
return RET_ERROR(TRUE, LastError);
|
||||||
|
Loading…
Reference in New Issue
Block a user