aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-09 13:10:16 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-09 13:15:57 +0100
commit8ec14e5f6d9063426394a53621e99b418b0d38e7 (patch)
tree42d55e4f5088e337fc0becdda15bd493726036e8
parentapi: account for adapter disappearing during deletion (diff)
downloadwintun-8ec14e5f6d9063426394a53621e99b418b0d38e7.tar.xz
wintun-8ec14e5f6d9063426394a53621e99b418b0d38e7.zip
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>
-rw-r--r--api/adapter.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 325a29e..f023ccd 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -1689,6 +1689,13 @@ _Return_type_success_(return != FALSE) BOOL WINAPI WintunDeleteAdapter(
goto cleanupToken;
}
+ HANDLE Mutex = NamespaceTakePoolMutex(Adapter->Pool);
+ if (!Mutex)
+ {
+ LastError = LOG(WINTUN_LOG_ERR, L"Failed to take pool mutex");
+ goto cleanupToken;
+ }
+
HDEVINFO DevInfo;
SP_DEVINFO_DATA DevInfoData;
if (!GetDevInfoData(&Adapter->CfgInstanceID, &DevInfo, &DevInfoData))
@@ -1697,7 +1704,7 @@ _Return_type_success_(return != FALSE) BOOL WINAPI WintunDeleteAdapter(
LastError = ERROR_SUCCESS;
else
LOG(WINTUN_LOG_ERR, L"Failed to get adapter info data");
- goto cleanupToken;
+ goto cleanupMutex;
}
if (ForceCloseSessions && !ForceCloseWintunAdapterHandle(DevInfo, &DevInfoData))
@@ -1718,6 +1725,8 @@ _Return_type_success_(return != FALSE) BOOL WINAPI WintunDeleteAdapter(
cleanupDevInfo:
*RebootRequired = *RebootRequired || CheckReboot(DevInfo, &DevInfoData);
SetupDiDestroyDeviceInfoList(DevInfo);
+cleanupMutex:
+ NamespaceReleaseMutex(Mutex);
cleanupToken:
RevertToSelf();
return RET_ERROR(TRUE, LastError);