Commit Graph

259 Commits

Author SHA1 Message Date
Shawn Hoffman
9c39b2b567 Use standard volatile semantics
Make all archs are use the standardized concept of volatile.
This patch will cause the most changes to arm64 codegen.

Signed-off-by: Shawn Hoffman <godisgovernment@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-30 17:08:10 +01:00
Jason A. Donenfeld
b19c7abd41 Fix potential TunDispatchSecurityDescriptor leak
TunDispatchSecurityDescriptor will leak if RtlAbsoluteToSelfRelativeSD
fails. Add cleanup in error path.

Reported-by: Shawn Hoffman <godisgovernment@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-30 17:04:34 +01:00
Shawn Hoffman
cb1f62156e Use RtlSubAuthoritySid instead of directly poking SID
Signed-off-by: Shawn Hoffman <godisgovernment@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-30 17:00:20 +01:00
Simon Rozman
6d6e219080 Reschedule EvaluateWintun between InstallInitialize and InstallFinalize
WireGuard is always doing so-called "minor" upgrade. This makes it
enough to run EvaluateWintun only once - somewhere after CostFinalize.
The component state we bind our driver install/remove logic to will be a
singleton: either be installed,  left alone, or uninstalled. One single
action for install product session and RemoveExistingProducts session.

Other applications using Wintun might use the so-called "major" upgrade.
In this scenario the existing product is completely uninstalled first.
Including Wintun. The EvaluateWintun was called only once and it
determined that Wintun driver should be uninstalled. Since the MSI did
not execute EvaluateWintun again when installing the new product later,
the Wintun remained uninstalled.

In the case of major upgrades, the Wintun requires two separate action
logics: what to do with Wintun on uninstall of the old product, and what
to do with it when new product is installed.

Therefore, EvaluateWintun has been moved between InstallInitialize and
InstallFinalize to have MSI execute it in install and uninstall
sessions.

Reported-by: Dmitry Smirnov <dmitry.smirnov@netprotect.com>
Tested-by: Simon Rozman <simon@rozman.si>
Signed-off-by: Simon Rozman <simon@rozman.si>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-02-29 19:39:11 +08:00
Jason A. Donenfeld
27e4d334fc Version bump
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-12-10 14:54:10 +01:00
Jason A. Donenfeld
5f681022c9 Invert skipPacket condition so code matches
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-12-10 14:39:06 +01:00
Jason A. Donenfeld
96553f4217 Increment discarded packets properly
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-12-10 14:38:59 +01:00
Simon Rozman
6cc9786b47 Process send NBLs in batches
When using packet forwarding on Windows computer, adjacent NBLs may
represent packet fragments. Those NBLs must not be completed separately,
but in a single NdisMSendNetBufferListsComplete() call.

This fixes a bugcheck on Windows Server with RRAS role and IP forwarding
packets to Wintun adapter.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-12-10 14:22:50 +01:00
Simon Rozman
c4becc5b90 Remove excessive ASSERT
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-12-10 14:22:50 +01:00
Jason A. Donenfeld
a5cc2b2ed4 Version bump
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-10-06 13:28:31 +00:00
Jason A. Donenfeld
fd52a3a429 Ensure that buffers are unmapped on process exit and adapter deletion
Before duplicating a handle elsewhere and closing the original process
would result in disaster. Also, it turns out that TunHaltEx can be
called before the handles are all closed, so we need to unregister prior
to freeing the ctx, lest disaster occurs. Finally, now that we have a
few different things happening with registration and deregistration, we
serialize all accesses with an eresource, a bit heavy-weight but
sufficient.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-10-06 12:37:51 +00:00
Jason A. Donenfeld
53332cd078 installer: improve resource freeing flow
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-10-04 08:52:58 +00:00
Jason A. Donenfeld
736131960f msi-example: add instructions and sample code 2019-09-18 15:19:09 -06:00
Simon Rozman
af580a57af Stop timestamping test-signed binaries
WDK doesn't timestamp test-signed drivers. Neither should we.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-09-02 10:10:03 +02:00
Jason A. Donenfeld
c072f4f3c4 Explicitly opt-in to READ_ONCE/WRITE_ONCE semantics
We mark all atomic variables as volatile and have our atomic accessors
built around that. We probably, therefore, want Linux-style
READ/WRITE_ONCE semantics of implying memory barriers. /volatile:ms does
this automatically.

This was already the default on amd64 and x86 but not on ARM.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reported-by: Lev Stipakov <lstipakov@gmail.com>
2019-08-24 12:26:00 +00:00
Jason A. Donenfeld
e8e5a42e98 README: clarify spinning
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-22 11:27:57 +02:00
Simon Rozman
fa715c4863 Use WiX directly rather than via WiX's MSBuild
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-05 17:14:27 +02:00
Jason A. Donenfeld
03f356c492 Dynamically gather signtool full path
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-05 14:08:06 +02:00
Simon Rozman
810d2ac73a Unify XML empty-element spacing
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-05 09:45:52 +02:00
Jason A. Donenfeld
c9da443273 Version bump
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-04 15:29:48 +00:00
Jason A. Donenfeld
5b872e8cf9 Use performance counter for less spinning
Previously we had to spin for a minimum of 15ms because the tick
interval is 156250 on NT. On linux, usually trips to the high
performance timers are discouraged because if they don't hit the RDTSC
path (due to being unstable or the like), they hit more expensive
hardware. I assume that's probably the same on NT, but all of tcpip.sys
and ndis.sys uses the performance counters too, so what are we going to
do?

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-04 11:13:39 +00:00
Jason A. Donenfeld
85a8076d08 Spin less and more efficiently
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-04 07:06:50 +00:00
Jason A. Donenfeld
bc22e2dd25 GetCurrentProcessToken() is Win8+, so open our own token
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-03 08:46:21 +00:00
Jason A. Donenfeld
0e5c1a7a94 Shorten README
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 17:21:26 +02:00
Jason A. Donenfeld
fb68232f16 Free interface list when aborting in installer
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 13:24:21 +02:00
Jason A. Donenfeld
71afd84033 Document how to get file handle
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 13:22:35 +02:00
Simon Rozman
cd6fe285b4 Cleanup NBL reference counting
The Empty event state is now set according to
Ctx->Device.Receive.ActiveNbls.Head != NULL. But, we still have to clear
the Empty event inside the TransitionLock to prevent race with
TunPause().

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 12:25:22 +02:00
Simon Rozman
408665270f Skip packet on NBL allocation failure properly
Should NBL allocation persist to fail, the receive ring could eventually
fill up as there will be no TunReturnNetBufferLists() calls to advance
its head.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 12:04:02 +02:00
Jason A. Donenfeld
9d71da2d37 Version bump
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 11:57:30 +02:00
Jason A. Donenfeld
366aaf2820 Rearrange README and add additional MSM info
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 11:57:30 +02:00
Jason A. Donenfeld
47a2a980a8 Do not rebuild driver on installer library build
This commit is in many ways wrong, but when we're dealing with whql
imports, there's often a large gap in time, and it's useful to be able
to just restore everything exactly how it was prior and then build only
installer.dll and the msm.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Simon Rozman
799413a776 Use reference counter and KEVENT instead of remove locks
Driver verifier doesn't like re-initializing remove locks.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
9e9f1ac9b3 Rearrange comment to make clang-format happy
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
a2d46f3c00 Disable APC when taking rwlock
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Simon Rozman
ac3576a57e Unify driver input file list
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 09:43:32 +00:00
Simon Rozman
afdbc75bf9 Resolve SDV reported "defect"
NdisMGetDeviceProperty() should always return non-NULL
FunctionalDeviceObject according to _Outptr_opt_. An explicit
FunctionalDeviceObject NULL check has been added to keep the SDV happy
and not calling our driver "defective".

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 09:43:32 +00:00
Simon Rozman
b666f587d5 Add SDVView target
This invokes SDV GUI for easier review of SDV reported defects.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
28ba2d4600 Separate out atomic helpers
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
22e2da002d Rewrite installer logic in C
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-08-02 09:43:32 +00:00
Jason A. Donenfeld
18cfd522aa Use explicit running boolean and use set instead of exchange
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-31 13:59:54 +00:00
Simon Rozman
999a6744db Assert that adapter is always running when client is registering rings
By attaching to NDIS device instead of creating our own device for I/O,
the adapter is always running before client is able to connect and
register rings. NDIS also won't allow adapter to pause with connected
clients.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-31 13:59:54 +00:00
Simon Rozman
7f49a66494 Cleanup TUN_FLAGS_PRESENT
With no PnP notifications and custom surprise removal code we do not
need the TUN_FLAGS_PRESENT any more. The traffic is stopped when handle
is closed or adapter is somehow paused. Though by reusing the NDIS device
for our I/O, the adapter will not be able to pause with a client
connected.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-31 13:59:54 +00:00
Jason A. Donenfeld
5239d53db0 Add handle closing ioctl
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-31 13:59:54 +00:00
Simon Rozman
0d9b9b925a Reinitialize active NBL remove lock to allow adapter reuse
Before the TunProcessReceiveData() thread terminates or adapter is
paused, we wait for all receive NBLs to be returned. Unfortunately,
IoReleaseRemoveLockAndWait() leaves the remove lock in non reusable
state.

To be able to start receiving packets on existing adapter again, we
(re)initialize the remove lock on ring registration or adapter resume.
The former addresses TunProcessReceiveData()'s
IoReleaseRemoveLockAndWait() call, the later addresses the TunPause()'s.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-31 13:59:46 +00:00
Jason A. Donenfeld
f48b0b2883 Compile on 32-bit and arm64
No popcnt intrinsic on arm, no PopulationCount64 function on 32bit.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-19 10:28:02 +00:00
Jason A. Donenfeld
970e22d8e4 Use more specific IOCTL code
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-19 06:31:26 +00:00
Jason A. Donenfeld
6ebdbf77d2 Require the usual SDDL_DEVOBJ_SYS_ALL permissions
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18 19:35:41 +00:00
Simon Rozman
14e5532dc8 Make receiving NBLs asynchronous
This commit moves NBL post-processing (moving ring head, releasing NBL)
to MINIPORT_RETURN_NET_BUFFER_LISTS handler.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-18 15:27:18 +02:00
Simon Rozman
f5eadb50c4 Minimize TransitionLock when receiving packets
We do not need to share-lock the TransitionLock for the whole life of
receiver thread.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-18 14:53:38 +02:00
Jason A. Donenfeld
9bf25d873b Fix insane coding style
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18 12:49:32 +00:00