aboutsummaryrefslogtreecommitdiffstats
path: root/api/adapter.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* api: use proper instance id boundsJason A. Donenfeld2021-10-141-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: adapter: handle cases explicitly in dev query callbackJason A. Donenfeld2021-10-141-5/+10
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* driver: automatically close long-lived handleJason A. Donenfeld2021-10-121-43/+0
| | | | | | | | | | | | | There's only one handle that's likely to be open in a long lived way: the tun registration handle. So we can force that closed automatically when the device is about to close, if it's been improperly left open. Other handles will indeed hold up closing, but if those exist, they're a sign of a larger bug elsewhere that should be addressed. On the other hand, tun registration handles might legitimately be open during driver upgrades. This also saves us the trouble of dereferencing a freed FileObject as in the general case. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rewrite based on SwDeviceJason A. Donenfeld2021-10-121-1563/+662
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: adapter: cleanup wintrust shim if install failsJason A. Donenfeld2021-09-281-6/+6
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: incorporate new win7 code signing techniqueJason A. Donenfeld2021-08-021-0/+65
| | | | | | https://git.zx2c4.com/downlevel-driver-enabler/about/ Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove authenticode supportJason A. Donenfeld2021-08-021-92/+2
| | | | | | Certificates are no longer valid. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: upgradeSimon Rozman2021-07-281-624/+505
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* vs: move shared configuration to wintun.props and upgradeSimon Rozman2021-07-281-8/+16
| | | | | | | Remember to rename wintun.vcxproj.user file in your local working folder to wintun.props.user manually. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: build with WDKJason A. Donenfeld2021-07-231-2/+3
| | | | | | | Makes builds more reproducable, as we can do our next release using the EWDK, an all-in-one ISO of build tools from Microsoft. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: use SuggestedInstanceId instead of NetSetupAnticipatedInstanceIdJason A. Donenfeld2021-07-091-65/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All was well with NetSetupAnticipatedInstanceId, until a bug crept into recent Windows builds that caused old GUIDs not to be properly removed, resulting in subsequent adapter creations to fail, because NetSetup AnticipatedInstanceId considers it fatal when the target GUID already exists, even if in diminished form. The initial solution was to detect cruft, and then steal a TrustedInstaller token and sleuth around the registry cleaning things up. The horror! Uncomfortable with this, I reopened IDA and had a look around with fresh eyes, three years after the original discovery of NetSetupAnticipated InstanceId. There, I found some interesting behavior in NetSetupSvcDeviceManager::InstallNetworkInterfaces, which amounts to something like: if (IsSet("RetiredNetCfgInstanceId") { if (IsSet("NetSetupAnticipatedInstanceId") DeleteAdapter(GetValue("RetiredNetCfgInstanceId")); else Set("NetSetupAnticipatedInstanceId", GetValue("RetiredNetCfgInstanceId")); Delete("RetiredNetCfgInstanceId"); } CreateAdapter = TRUE; if (IsSet("NetSetupAnticipatedInstanceId")) { Guid = GetValue("NetSetupAnticipatedInstanceId"); if (AdapterAlreadyExists(Guid)) CreateAdapter = FALSE; else SetGuidOfNewAdapter(Guid); Delete("NetSetupAnticipatedInstanceId"); } else if (IsSet("SuggestedInstanceId")) { Guid = GetValue("SuggestedInstanceId"); if (!AdapterAlreadyExists(Guid)) SetGuidOfNewAdapter(Guid); Delete("SuggestedInstanceId"); } Thus, one appealing strategy would be to set both NetSetupAnticipated InstanceId and RetiredInstanceId to the same value, and let the service handle deleting the old one for us before creating the new one. However, the cleanup of the old adapter winds up being quasi- asynchronous, and thus we still wind up in the CreateAdapter = FALSE case. So, the remaining strategy is to simply use SuggestedInstanceId instead. This has the behavior that if there's an adapter already in use, it'll use a new random GUID. The result is that adapter creation won't fail. That's not great, but the docs have always made it clear that "requested" is a best-effort sort of thing. Plus, hopefully the creation of the new adapter will help nudge the bug a bit and cleanup the old cruft. In some ways, transitioning from our old strategy of "cudgel the registry until we get the GUID we want" to "ask politely and accept no for an answer" is a disappointing regression in functionality. But it also means we don't need to keep crazy token stealing code around, or fish around in the registry dangerously. This probably also increases the likelihood that an adapter will be created during edge cases, which means fewer errors for users, which could be a good thing. On the downside, we have the perpetual tensions caused by a system that now "fails open" instead of "fails closed". But so it goes in Windows land. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: log instance id when object file name is emptyJason A. Donenfeld2021-07-081-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: print correct last error when failingJason A. Donenfeld2021-07-081-1/+1
| | | | | | | Prior to the conversion, LastError is ERROR_SUCCESS, so move the logging to be after the conversion. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: don't auto-elevateJason A. Donenfeld2021-06-251-44/+13
| | | | | | | There's no longer a need to do this for every API call. This only exists now for the pnp guid reuse workaround hack. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: only mark GUID as in-use if Status != NotPresentJason A. Donenfeld2021-05-111-13/+16
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: use simpler problem status checkingJason A. Donenfeld2021-05-101-12/+13
| | | | | | | | This reworks commit e51b49604b5d00a641b698e7c40d4d46a06644c9. Link: https://www.reddit.com/r/WireGuard/comments/n6yocf/unable_to_create_wintun_on_windows_7_laptop_with/ Reported-by: Alirz Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: check that GUID is valid before assuming it's in useJason A. Donenfeld2021-05-101-2/+7
| | | | | | | | | 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 <piotrs@glosol.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: skip requested GUID if !win10Jason A. Donenfeld2021-05-051-5/+12
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: clean up NetSetup2 GUIDsJason A. Donenfeld2021-05-051-0/+50
| | | | | | | | Recent versions of Windows fail to tidy up, causing issues when reusing GUIDs. Check to see if a GUID might be orphaned, and forcibly clear out the registry state if so. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: don't return ERROR_SUCCESS if adapter doesn't come upJason A. Donenfeld2021-05-041-4/+23
| | | | | | | | Otherwise we fail to remove the zombie adapter, and then the problem repeats itself. Note that this is part of a larger issue of clearing out bad GUIDs in NetSetup2 on recent Windows builds Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: log Windows error message too when creating folder or file failsSimon Rozman2021-04-131-2/+2
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: elevate to SYSTEM in WintunEnumAdapters()Simon Rozman2021-03-081-3/+10
| | | | | | | | | | | | | | The WintunEnumAdapters() requires namespace mutex. However, NamespaceTakePoolMutex() works as SYSTEM user only. WireGuard is using the WintunEnumAdapters() in its manager service to cleanup stale adapters. As the WireGuard manager service is running as SYSTEM, this requirement was not apparent before. This commit also extends the example project to list its existing adapters at start. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: upgrade logging0.10.2Simon Rozman2021-02-161-112/+173
| | | | | | | Log runtime information to quickly check whether the values are sane when analyzing error logs sent in by users. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: tighten function parameter code analysis annotationsSimon Rozman2021-02-041-6/+5
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: unify NetCfgInstanceId registry retrievalSimon Rozman2021-02-041-26/+22
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: ensure that device object exists before returning from open/create0.10.1Jason A. Donenfeld2021-02-031-13/+62
| | | | | | | | | | | | | | | | | Some users are seeing errors like this after rebooting from Windows Update: 2021-01-28 18:39:45.220197: [TUN] Creating Wintun interface 2021-01-28 18:39:49.420116: [TUN] [Wintun] CreateAdapter: Creating adapter 2021-01-28 18:39:53.704007: [TUN] [Wintun] OpenDeviceObject: Failed to connect to adapter: The system cannot find the path specified. (Code 0x00000003) 2021-01-28 18:39:53.704007: [TUN] [Wintun] WintunStartSession: Failed to open adapter device object 2021-01-28 18:39:54.097037: [TUN] Unable to create Wintun interface: Error starting session: The system cannot find the path specified. It appears that creation of the device object file might happen asynchronously, so this commit polls for it. Reported-by: Artem Kuroptev <artem@kuroptev.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: bump copyrightJason A. Donenfeld2021-01-301-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: use custom devpkey for poolJason A. Donenfeld2021-01-301-2/+28
| | | | | | | | | | It seems like the friendly name is still getting reset sometimes. Rather than swimming upstream, it turns out we can just use a custom devpkey that, according to msdn, is respected. https://docs.microsoft.com/en-us/windows-hardware/drivers/install/creating-custom-device-properties Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: do not make dead gateway detection failures fatal0.9.1Jason A. Donenfeld2020-11-171-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: retry on ERROR_TRANSACTION_NOT_ACTIVE when disabling dead GW detectSimon Rozman2020-11-171-18/+27
| | | | | | | | There seems to be a race in the TCP/IP adapter registry key. Sometimes, the adapter TCP/IP key is created, but setting the value EnableDeadGWDetect fails with ERROR_TRANSACTION_NOT_ACTIVE. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: relax IsPoolMember estimationJason A. Donenfeld2020-11-091-27/+14
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: do not call UpdateDriverForPlugAndPlayDevicesWJason A. Donenfeld2020-11-091-10/+2
| | | | | | | This seems to reset a number of device properties, and our update flow seems to update old adapters without needing to call this. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: take pool mutex when deletingJason A. Donenfeld2020-11-091-1/+10
| | | | | | | 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>
* api: account for adapter disappearing during deletionJason A. Donenfeld2020-11-091-4/+6
| | | | | | This makes the race less fatal. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: avoid loading version.dll if not usedJason A. Donenfeld2020-11-061-3/+14
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove WintunOpenAdapterDeviceObjectJason A. Donenfeld2020-11-051-1/+1
| | | | | | | Discourage use of kernel interface, which gives us more flexibility if we ever want to change it. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rename WintunGetAdapter to WintunOpenAdapterJason A. Donenfeld2020-11-051-1/+1
| | | | | | "Create" and "Open" natural names for these. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: CALLBACK_FUNC -> CALLBACKJason A. Donenfeld2020-11-041-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rename GetVersion to GetRunningDriverVersionJason A. Donenfeld2020-11-041-2/+2
| | | | | | | This makes our intentions a lot more clear, and in case we ever add other version functions, makes the forward path simpler. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: use a logging alloc functionJason A. Donenfeld2020-11-041-66/+37
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: include the rundll32 helpers the MSVC-typical waySimon Rozman2020-11-041-1/+1
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: translate NTSTATUS to Win32 error codesSimon Rozman2020-11-041-1/+1
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: use GetLastError() to report failures like standard Win32Simon Rozman2020-11-041-538/+641
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* wintun: extract inf driverver at compile time into C headerJason A. Donenfeld2020-11-031-111/+4
| | | | | | | | | | | | This requires us to make some insane conversions between INF date, JavaScript time, and finally Windows file time. The point is to mimic SystemTimeToFileTime, which is what SpInf.dll's pSetupStringToDriverDate does on the YYYY-MM-DD from the INF. The result is that we no longer have to parse an ancient text format in C at runtime. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: move undocumented ntdll symbols to ntdll.hJason A. Donenfeld2020-11-031-12/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: constify pool argumentJason A. Donenfeld2020-11-031-2/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove guid getterJason A. Donenfeld2020-11-031-6/+0
| | | | | | | | | The iphlpapi takes both LUIDs and GUIDs but prefers LUIDs, so exposing the NET_LUID makes sense. However, we were previously exposing the configuration GUID, rather than the net GUID, which is confusing, so just make it all go away. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: use 'open' name since caller must close handleJason A. Donenfeld2020-11-031-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: add pool/driver removal for uninstaller semanticsJason A. Donenfeld2020-11-031-8/+33
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: only return top two version nibblesJason A. Donenfeld2020-11-031-5/+5
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>