Fix CreateInstance failure when Windows hosts file exceeds message size cap (#40718)
On Windows 10 where DNS tunneling is unavailable, the hosts file content is embedded in the configuration message sent to the guest init. If the hosts file exceeds the message size safety check (added in 2.7.x), the guest rejects it causing E_UNEXPECTED. Fix by: - Skipping the hosts file content if it exceeds 8MB, with a user warning - Bumping the message size cap from 4MB to 16MB as additional headroom Fixes #40696 Fixes #40700 Fixes #40699 Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Ben Hillis committed
Jun 5, 2026 at 15:05 UTC
9ab38e95e769a0b2a370d7c77800d6cb8df7353f
4 files changed
+12
-2
localization/strings/en-US/Resources.resw
+4
@@ -918,6 +918,10 @@ Falling back to NAT networking.</value>
918
<value>DNS Tunneling is not supported</value>
919
<comment>{Locked="DNS"}"DNS" (Domain Name System) should not be translated.</comment>
920
</data>
921
+ <data name="MessageHostsFileTooLarge" xml:space="preserve">
922
+ <value>The Windows hosts file is too large and will not be reflected inside WSL. Consider reducing the size of %SystemRoot%\System32\drivers\etc\hosts</value>
923
+ <comment>{Locked="%SystemRoot%\System32\drivers\etc\hosts"}{Locked="WSL"}</comment>
924
+ </data>
925
<data name="MessageLocalhostForwardingNotSupportedMirroredMode" xml:space="preserve">
926
<value>The wsl2.localhostForwarding setting has no effect when using mirrored networking mode</value>
927
</data>
src/shared/inc/socketshared.h
+1
-1
@@ -64,7 +64,7 @@ try
64
#endif
65
}
66
67
- if (MessageSize > 4 * 1024 * 1024) // 4 MiB
67
+ if (MessageSize > 16 * 1024 * 1024) // 16 MiB
68
{
69
#if defined(_MSC_VER)
70
THROW_HR_MSG(E_UNEXPECTED, "Message size too large: %llu", MessageSize);
src/windows/common/HandleIO.cpp
+1
-1
@@ -656,7 +656,7 @@ bool ReadSocketMessageHandle::ProcessChunk()
656
if (ReadingHeader)
657
{
658
THROW_HR_IF_MSG(E_UNEXPECTED, messageSize < sizeof(MESSAGE_HEADER), "Unexpected message size: %u", messageSize);
659
- THROW_HR_IF_MSG(E_UNEXPECTED, messageSize > 4 * 1024 * 1024, "Message size too large: %u", messageSize);
659
+ THROW_HR_IF_MSG(E_UNEXPECTED, messageSize > 16 * 1024 * 1024, "Message size too large: %u", messageSize);
660
661
if (Buffer.size() < messageSize)
662
{
src/windows/common/filesystem.cpp
+6
@@ -930,6 +930,12 @@ std::string wsl::windows::common::filesystem::GetWindowsHosts(const std::filesys
930
WindowsHosts.append(CurrentEntry);
931
}
932
}
933
+
934
+ if (WindowsHosts.size() > 8 * _1MB)
935
+ {
936
+ EMIT_USER_WARNING(wsl::shared::Localization::MessageHostsFileTooLarge());
937
+ return {};
938
+ }
939
}
940
941
WI_ASSERT(Stream.eof());