From 1efbd14c2c65c75d147512e2953966a5de7b81bb Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 10 May 2021 11:02:31 +0200 Subject: [PATCH] api: check that GUID is valid before assuming it's in use ROOT/NET/000X could have been claimed by a different driver, so we want to double check. Link: https://lists.zx2c4.com/pipermail/wireguard/2021-May/006716.html Reported-by: Piotr Sobczak Signed-off-by: Jason A. Donenfeld --- api/adapter.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/adapter.c b/api/adapter.c index ba4467c..ec14d99 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -1452,8 +1452,13 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter( if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegPath, 0, KEY_QUERY_VALUE, &Key) == ERROR_SUCCESS) { RegCloseKey(Key); - SetLastError(LOG_ERROR(ERROR_ALREADY_EXISTS, L"Requested GUID is already in use: %s", RequestedGUIDStr)); - return NULL; + NET_LUID Luid; + if (ConvertInterfaceGuidToLuid(RequestedGUID, &Luid) == NO_ERROR) + { + SetLastError( + LOG_ERROR(ERROR_ALREADY_EXISTS, L"Requested GUID is already in use: %s", RequestedGUIDStr)); + return NULL; + } } LOG(WINTUN_LOG_WARN, L"Requested GUID %s has leftover residue", RequestedGUIDStr); HANDLE OriginalToken;