Windows managed DNS writes malformed REG_MULTI_SZ and produces phantom NRPT namespaces
This bug was found by Codex, but I reproduced its findings by hand to make sure it's not a bogus report. :)
Before filing a Bug Report
Using these will ensure you get quicker support, and make this space available for code-related issues. Thank you!
- Docs Site => Troubleshooting, quickstarts, and more advanced topics.
- Discuss Forum => Our discussion forum for users and support to mutually resolve issues & suggest ideas.
- Reddit => Our subreddit, which we monitor regularly and is fairly active.
- Knowledge Base => Older wiki.
If you are having a connection issue, it's much easier to diagnose through the discussion forum or the ticket system.
If you still want to file a Bug Report
Please let us know
What you expect to be happening
When managed DNS is enabled for a network, the Windows client should write a valid REG_MULTI_SZ value for the NRPT namespace.
For a single namespace such as .KDG.local, the registry data should contain the string terminator followed by the additional terminator marking the end of the multi-string:
.KDG.local<NUL><NUL>Windows should consequently expose exactly one NRPT namespace.
What is actually happening?
ZeroTier creates this value:
HKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsPolicyConfig\{GUID}
Name REG_MULTI_SZThe raw data contains only one terminating NUL:
Size : 22
Hex : 2E 00 4B 00 44 00 47 00 2E 00 6C 00 6F 00 63 00 61 00 6C 00 00 00
Unicode : .KDG.local<NUL>A valid one-element REG_MULTI_SZ for this value requires 24 bytes:
.KDG.local<NUL><NUL>Because the multi-string is not terminated correctly, the Windows NRPT provider reads beyond the intended value and exposes additional, apparently random namespaces. Across repeated boots we observed phantom values including:
U+0001
WSL)
gFor example, Get-DnsClientNrptPolicy returned:
Namespace : g
NameServers: 192.168.194.3
Namespace : .KDG.local
NameServers: 192.168.194.3The phantom namespace changed after the ZeroTier service recreated the rule.
Rewriting Name through the Windows registry API as a proper MultiString immediately removed the phantom entries:
$key.SetValue(
'Name',
[string[]]@('.KDG.local'),
[Microsoft.Win32.RegistryValueKind]::MultiString
)Afterward, both Get-DnsClientNrptPolicy and netsh namespace show policy displayed only .KDG.local. After restarting/rebooting and allowing ZeroTier to recreate the rule, the malformed value and phantom namespace returned.
This appears to originate here:
https://github.com/zerotier/ZeroTierOne/blob/1.16.2/osdep/WinDNSHelper.cpp#L300
RegSetKeyValueA(
dnsKey,
NULL,
"Name",
REG_MULTI_SZ,
d.data(),
d.length()
);The supplied byte count excludes the required REG_MULTI_SZ terminators.
Steps to reproduce the error
On a Windows client, join a ZeroTier network and permit managed DNS:
zerotier-cli set <network-id> allowDNS=1In ZeroTier Central, configure managed DNS with:
Search domain: KDG.local DNS server: 192.168.194.3Confirm that the client received the configuration:
zerotier-cli -j listnetworksLocate the generated registry key under:
HKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsPolicyConfigZeroTier identifies its key through the
Commentvalue containing the network ID.Read the raw bytes and size of the
Namevalue withRegQueryValueEx. Observe that.KDG.localoccupies 22 bytes and ends with only one UTF-16 NUL.Reboot Windows or restart ZeroTier, then inspect the parsed namespaces:
Get-DnsClientNrptPolicy netsh namespace show policyObserve one or more phantom namespaces in addition to
.KDG.local.Rewrite
Nameas a correctly formedREG_MULTI_SZ. The phantom entries disappear immediately.
For comparison, an NRPT rule created with Microsoft’s Add-DnsClientNrptRule was correctly double-terminated.
No GPO-backed NRPT configuration was present during this reproduction:
HKLM\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient\DnsPolicyConfigwas absent. This therefore appears independent of the GPO precedence behavior discussed in #1627.
Relevant console output or screenshots
ZeroTier-created value:
Type : 7
Size : 22
Hex : 2E 00 4B 00 44 00 47 00 2E 00 6C 00 6F 00 63 00 61 00 6C 00 00 00
Unicode : .KDG.local<NUL>Rule as reported by Windows:
Name : {GUID}
Namespace : {.KDG.local}
NameServers : 192.168.194.3
Comment : <network-id>
ConfigOptions : 8Example phantom policy output after reboot:
Namespace : g
NameServers : 192.168.194.3
Namespace : .KDG.local
NameServers : 192.168.194.3Output after correcting the registry value:
Namespace : .KDG.local
NameServers : 192.168.194.3Operating system and ZeroTier version
Operating system: Windows 10 Pro 22H2
OS build: 19045.6456
Architecture: x64
ZeroTier version: 1.16.2
allowDNS: trueZeroTier 1.16.2 was the latest stable release at the time of testing.
Source: zerotier/ZeroTierOne