npcap icon indicating copy to clipboard operation
npcap copied to clipboard

Fix network disruption during Npcap install on 802.1x authenticated networks

Open fyodor opened this issue 7 years ago • 10 comments

We have received reports from 2 users of 802.1q authenticated networks that their Wifi connection was disrupted during Npcap install until they re-authenticated to rejoin the network or just rebooted their system. We don't yet know if all 802.1q authenticated networks are similarly disrupted or if it was something specific to these particular networks/systems.

This issue is partially created as a call out for people to report if they are experiencing this issue or not. That will help us decide how to prioritize the issue and figure out what the cases might have in common besides 802.1q. Please let us know what version of Windows you are running too.

Obviously the best fix would be to prevent the network disruption in the first place, but that may be difficult if it is a bug/characteristic of how Windows handles the loading of WFP drivers. In the meantime, we are looking at creating a "/start_driver_now =no" install option that prevents the Npcap driver from loading until the next reboot. That means Npcap functionality won't be available until then either, but it may be better than risking even temporary network disruption on a running system.

fyodor avatar Jul 09 '19 22:07 fyodor

+1 to the addition of "/start_driver_now=no"

danvarga avatar Jul 10 '19 14:07 danvarga

This is a fundamentally difficult problem. In order to attach a filter driver NDIS pauses the driver stack, which can cause interruptions. With some drivers in particular, this breaks existing connections. We've seen this with 802.1x (#1631) and Hyper-V VmSwitch, and even the Windows Driver Samples example filter driver has reportedly been affected when security software and firewalls are installed.

dmiller-nmap avatar Jul 25 '19 21:07 dmiller-nmap

+1 for "/start_driver_now=no"

We've this same issue and while a reboot being required isn't ideal, it is better than having a remote laptop being dropped from the wireless network after installation of npcap. We've a client that is pretty upset with us right now due to the fact that it knocked quite a few Windows 10 laptops off the wireless network and required them to dispatch field resources to recover them. Any help here would be much appreciated.

dmabry avatar Aug 05 '19 12:08 dmabry

We cannot solve this with a "/start_driver_now=no" installer option, because the interruption happens with the installation of the filter, not the start of the driver service.

Copying some notes from nmap/nmap#1866:

This problem is not unique to Npcap; installing the demo NDIS 6 filter driver from Microsoft/Windows-driver-samples will do the same thing in certain situations. It appears to only affect newer releases of Windows 10 (e.g. Server 2019 Datacenter) and only in some situations like interfaces with QoS or 802.1X enabled. We've reached out on TechNet Forums and StackOverflow without getting any solid answers. It is really out of our hands, and the only workaround currently is to schedule installation for a time when the interruption will have the least impact, such as at the next boot.

dmiller-nmap avatar Jan 28 '20 05:01 dmiller-nmap

Tested this again with Npcap 0.9995 installer on Windows Server 2019 Datacenter, and the connection is still interrupted. We had hoped that upgrading to NDIS 6.50 would make the installation process more seamless, but that is not the case.

It's a long shot, but @jtippet do you know if there is any way around this behavior (installing NDIS LWF resets TCP connections)?

dmiller-nmap avatar Jul 13 '20 19:07 dmiller-nmap

If you set this registry value:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NDIS\Parameters]
"FilterBindLogicMode"=dword:00000001

then reboot the machine, then try a driver installation, does the disconnection still happen?

Obligatory disclaimer: The registry value is not supported by Microsoft, should only be used for diagnostics, and should never be used in production without specific instruction from Microsoft. The flag has some weird side effects that I won't detail here.

If the disconnect does not repro after setting the registry value, then this problem is known. The good news is that I hardened the OS to avoid the problem entirely, starting with Windows 10 version 2004 ("May 2020 Update"). The bad news is that it's not really possible to work around it in your LWF. It results from a system-wide interaction of all the running LWFs.

The situation is a little complicated to explain, so please forgive my inadequate attempt here.

When usermode adds/removes/updates a filter driver, NDIS plans out a set of transformations to update the running filter stack. For example, suppose usermode has updated Filter A to have a new FilterClass. The running filter stack is currently A-B-C, but with the new FilterClass, NDIS needs to transform it into B-A-C. There is more than one equivalent plan to get there:

  • Detach A, then attach A into the 2nd position
  • Detach B, then attach B into the 1st position
  • (other, longer sequences of operations are possible)

From Windows 8.1 through Windows 10 version 1909, NDIS selects an arbitrary plan of the shortest length. The first two plans above are each of length 2, so NDIS selects an arbitrary one.

However, LWFs can choose to mark themselves as UnbindOnAttach. If this flag is set (either directly in the INF, or indirectly by settings the Mandatory flag), then NDIS guarantees that it will unbind TCPIP when the LWF is attached. A LWF might do this if it makes a breaking change to the network stack -- e.g., a LWF that wants to inspect every SYN packet might want TCPIP to unbind, to force it to re-establish each socket with a brand new SYN handshake.

This means that some LWFs are more disruptive to attach than others. Suppose only Filter B is flagged as UnbindOnAttach: if NDIS selects the 1st plan, then TCPIP would not be unbound. If NDIS selects the 2nd plan, then TCPIP would be unbound.

As of Windows 10 version 2004, NDIS now takes into consideration the "cost" of any individual plan. NDIS now prefers any plan that can manage to avoid unbinding TCPIP (even if that plan has more steps than an equivalent plan that does unbind TCPIP).

Windows 10 versions 1709 through 1909 and Windows Server 2019 have a prototype of this algorithm. Because it's a prototype, it's disabled by default -- it's only enabled when setting the registry value I mentioned above. The prototype is known to be flawed: there is at least one case where the prototype algorithm selects a more costly plan than necessary. All known deficiencies were corrected by version 2004, so the new algorithm is unconditionally enabled in that release.

The symptoms of this problem are only sometimes visible. It first requires a fairly specific arrangement of LWFs, with just the right set of UnbindOnAttach/UnbindOnDetach flags. We didn't notice the problem internally for several years after Windows 8.1 shipped, so it was fairly subtle. (Also, arguably, it's not really a bug in NDIS -- it's just a missed optimization. So there's a decent chance that I classified a past bug report as "by design" without adequately questioning whether we could do better.)

jtippet avatar Jul 13 '20 21:07 jtippet

@jtippet Thank you so much for the answer! I will do that test just so we can close the loop on this. It's unfortunate that it seems there really is no way to work around it. I wonder why if this has always been NDIS behavior that we only have begun seeing issues with certain configurations (Windows Server 2019 Datacenter being the most commonly cited; I don't think we've seen a report from a non-Win10-based OS).

dmiller-nmap avatar Jul 13 '20 23:07 dmiller-nmap

Confirmed that this registry change solved the problem on an otherwise-unconfigured Azure instance of Windows Server 2019 Datacenter. I'm going to check whether there's a good way to determine ahead of time that this interruption will happen; I plan to investigate ways to enumerate all LWFs currently loaded and whether they are UnbindOnAttach or UnbindOnDetach. I do not think we will use this in our installer in any way, but if we can provide our licensees with a procedure to determine likelihood of interruption, they can choose whether to install Npcap at that point or postpone until a later time.

dmiller-nmap avatar Jul 14 '20 04:07 dmiller-nmap

I poked around a bit internally, and it looks like we're aiming to release a backport of this fix to Windows Server 2019 on August 18th, 2020. This would start out as an optional non-security quality update, and typically would eventually roll into a mandatory update the next month. I'd imagine that anyone savvy enough to be installing nmap is also well aware of the advantages of keeping up-to-date with OS patches, so hopefully within a couple months, you'll start seeing fewer people hit this issue.

Disclaimer: this is not a commitment - we may postpone or cancel the backport if any unexpected issues arise in testing.

Edit: use reference number 25929912 when communicating with Microsoft to identify the internal issue.

jtippet avatar Jul 14 '20 05:07 jtippet

Ok, here's where I'm leaving it. I have a notional procedure to get some sort of idea of whether Npcap installation might rebind TCPIP, though it depends on several things I haven't figured out. See jtippet's comment to get a more complete description. Here's the procedure:

  1. Get a list of enabled LWF bindings (Powershell: Get-NetAdapterBinding -AllBindings | ? {$_.Enabled -and $_.ComponentClassName -eq "Filter"} | select -Unique ElementName)
  2. Go through each network service registry entry in HKLM\SYSTEM\CurrentControlSet\Control\Network\{4d36e974-e325-11ce-bfc1-08002be10318} and find the corresponding subkey whose ComponentId value matches the binding name in the previous step.
  3. Check for any Mandatory filters ("FilterRunType"=1) or any with "UnbindOnAttach" or "UnbindOnDetach" set. These may be values of the Ndi subkey, or you may have to check the INF file directly (file name is in the "InfPath" value, directory is %SYSTEMROOT%\INF\). INF settings reference
  4. If you found any, it's possible installing Npcap will cause TCPIP to unbind and rebind.

Remaining questions whose answers may be helpful:

  • How does NDIS decide which filters need to be detached in order to insert a "compression" FilterClass LWF like Npcap? Is it everything above it on the stack? (See INF settings reference above)
  • Is there a better way than poking through the INF files to get these Ndi registry settings? They don't seem to be set in the actual registry for e.g. ms_pacer on my system, but they are for Npcap.

dmiller-nmap avatar Jul 14 '20 18:07 dmiller-nmap