aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* driver: use partial MDL for slicing ring, rather than NB's DataOffsetJason A. Donenfeld2020-12-131-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Providing the DataOffset member of the NBL allocation function or setting that member in the NB header indicates to NDIS not only that the data starts at that offset, but that there's that amount of space *available for it to use as it wants* before that offset. This meant that NDIS was allowed to scribble data before the packet. This was bounded by the size of the ring, so there was never any risk of memory corruption, and since the ring is shared by userspace as well as the rest of the kernel, we've always taken care of reading from it closely, checking all values, and erroring out on corruption of the ring. So, if NDIS wrote before the first packet, this would wind up corrupting the RingTail and Alertable fields of the ring. The receiver thread would then notice this, error out, and set the RingHead to MAXULONG on its way out the door, so that userspace can detect it. And indeed wintun.dll then started returning EOF from its write function. Mostly this was not an issue, because we're not expecting for data to be pushed on the head of a packet on ingress. But WSL2's Hyper-V driver is actually pushing an ethernet header onto the front of the packet before passing it off to Linux. Practically speaking, this manifested itself in the RingTail and Alertable fields having Linux's MAC address! And then the adapter would be EOF'd. This was reported as happening after WSL2 sends the *first* packet, but not others, which makes sense, because it has to be at the beginning in order to corrupt those fields. This fixes the problem by simply using a new MDL for the span we want, instead of using the misunderstood DataOffset field. In order to not need to keep track of memory allocations, we allocate the MDL as part of the NBL's context area. And in order to avoid additional mappings, we use IoBuildPartialMdl, which returns an MDL_PARTIAL, which does not have an additional mapping that needs to be freed or unmapped. After making this change, WSL2 no longer appears to halt the adapter, and all works well. Fixes: be8d2cb ("Avoid allocating second MDL") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* driver: use localtime in inf2catStefan Rinkes2020-12-021-0/+1
| | | | | | | Otherwise the build fails at odd hours of the day. Signed-off-by: Stefan Rinkes <stefan.rinkes@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: delay load remaining dlls to work around forwarder gotchas0.9.2Jason A. Donenfeld2020-11-271-2/+2
| | | | | | | | | RtlGenRandom forwards to cryptbase.dll, which is not in KnownDlls. Therefore it's not a good idea to link to advapi32.dll at link time. How many other gotchas of unusual forwarded functions are there? I don't really want to find out. Therefore, delay load everything else. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: skip notifying driver when there are no receive packets yetSimon Rozman2020-11-271-3/+5
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: allow header to be mitJason A. Donenfeld2020-11-271-1/+1
| | | | | | | This doesn't change much, but it does make it mildly more convenient plop this into mixed-use codebases. 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: remove useless lineJason A. Donenfeld2020-11-171-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove return value from logger functionJason A. Donenfeld2020-11-104-14/+6
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* driver: do not allow compiler to reload PacketSizeJason A. Donenfeld2020-11-091-1/+1
| | | | | | | | In theory, the compiler could reload PacketSize after the bounds check but before it's passed to NdisAllocateNetBufferAndNetBufferList. In practice, it's not actually doing that, but better safe than sorry. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* version: bump0.9Jason A. Donenfeld2020-11-091-2/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* 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-092-13/+5
| | | | | | | 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: manipulate process token if thread token didn't require impersonationJason A. Donenfeld2020-11-071-8/+11
| | | | | | Otherwise rundll32.exe fails if we're already SYSTEM. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: fix Function and Prefix logging orderSimon Rozman2020-11-071-1/+1
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: fix LastError overrideSimon Rozman2020-11-071-3/+4
| | | | | | | | | The LastError was overridden by the stdout reader thread exit code masking the true reason why ExecuteRunDll32() failed and even worse: as the thread exited gracefully, the true reason was overridden by ERROR_SUCCESS and returning TRUE (success). Signed-off-by: Simon Rozman <simon@rozman.si>
* proj: use less scary caps for zip license fileJason A. Donenfeld2020-11-061-1/+1
| | | | 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>
* driver: move to subfolderSimon Rozman2020-11-0610-27/+24
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: include arm64 in amd64Jason A. Donenfeld2020-11-053-3/+4
| | | | | | ARM64 will still run AMD64 apps. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove WintunOpenAdapterDeviceObjectJason A. Donenfeld2020-11-057-37/+14
| | | | | | | 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>
* example: raise to 4MiBJason A. Donenfeld2020-11-052-2/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rearrange wintun.h to have better grouping and improve docsJason A. Donenfeld2020-11-052-44/+45
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rename WintunGetAdapter to WintunOpenAdapterJason A. Donenfeld2020-11-055-22/+22
| | | | | | "Create" and "Open" natural names for these. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rename ReceiveRelease to ReleaseReceivePacketJason A. Donenfeld2020-11-055-17/+16
| | | | | | | | This makes the API parallel: Wintun*Allocate*SendPacket -> WintunSendPacket WintunReceivePacket -> Wintun*Release*ReceivePacket Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* README: improve code exampleJason A. Donenfeld2020-11-051-2/+37
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: move InititalizeWintun to top to be easier to findJason A. Donenfeld2020-11-051-33/+32
| | | | | | It's the primary function we want people copy and pasting. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: add cfgmgr32.dll to delayed load listJason A. Donenfeld2020-11-051-2/+2
| | | | | | It's in the registry but not in the NT object key. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* wintun: simplify vcxprojJason A. Donenfeld2020-11-051-86/+10
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* vs: cause example to be default selected run projectJason A. Donenfeld2020-11-051-2/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* .gitignore: simplify build dir matchJason A. Donenfeld2020-11-051-8/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: fix typo in ring-management function prototype declarationsSimon Rozman2020-11-052-10/+10
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* README: add reference and describe infoJason A. Donenfeld2020-11-041-96/+343
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: document enum argument properlyJason A. Donenfeld2020-11-041-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: document log enumJason A. Donenfeld2020-11-041-3/+6
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove enum name for logger levelJason A. Donenfeld2020-11-041-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: document adapter handle return value properlyJason A. Donenfeld2020-11-041-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: CALLBACK_FUNC -> CALLBACKJason A. Donenfeld2020-11-044-9/+9
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: upgrade nci.lib and wintun-inf.h buildingSimon Rozman2020-11-043-15/+15
| | | | | | | The additional build steps performed are now attached to the build process using BeforeTargets/AfterTargets. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: rename GetVersion to GetRunningDriverVersionJason A. Donenfeld2020-11-045-8/+9
| | | | | | | 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>
* example: account for buffer being drained too slowlyJason A. Donenfeld2020-11-041-3/+6
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: use a logging alloc functionJason A. Donenfeld2020-11-048-131/+96
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: concatenate function name at runtimeJason A. Donenfeld2020-11-043-18/+29
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: include the rundll32 helpers the MSVC-typical waySimon Rozman2020-11-044-6/+8
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: translate NTSTATUS to Win32 error codesSimon Rozman2020-11-043-13/+15
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: use GetLastError() to report failures like standard Win32Simon Rozman2020-11-0418-1017/+1317
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* example: account for adapter reuseJason A. Donenfeld2020-11-031-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* wintun: upset everybody by doing multiplication via string concatenationJason A. Donenfeld2020-11-031-1/+1
| | | | | | Because we can. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>