Fix IPv6 guest port reservation leak in VirtioProxy networking (#40803)
ModifyOpenPorts only sent the listen address to the device host when opening a port, not when closing it. The consomme port-forward table is keyed by (address family, port), so the device host must know the family to unbind the correct listener. With no address on close, the device host defaulted the family to IPv4, so IPv6 ports were never unbound and their host-side reservations leaked until process exit. IPv4 worked only because IPv4 is the default family. Always include the listen address in the port string so the family is available on both open and close. This fixes VirtioProxyTests::GuestPortIsReleasedV6. Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Ben Hillis committed
Jun 15, 2026 at 21:09 UTC
356c780736c20ffdc56c570df360ad77f68d19ea
1 file changed
+2
-9
src/windows/common/VirtioNetworking.cpp
+2
-9
@@ -156,15 +156,8 @@ int VirtioNetworking::ModifyOpenPorts(_In_ PCWSTR tag, _In_ const SOCKADDR_INET&
156
portString += L";udp";
157
}
158
159
- if (!isOpen)
160
- {
161
- portString += L";allocate=false";
162
- }
163
- else
164
- {
165
- const auto addrStr = wsl::windows::common::string::SockAddrInetToWstring(addr);
166
- portString += std::format(L";listen_addr={}", addrStr);
167
- }
159
+ const auto addrStr = wsl::windows::common::string::SockAddrInetToWstring(addr);
160
+ portString += std::format(L";listen_addr={};allocate={}", addrStr, isOpen ? L"true" : L"false");
161
162
LOG_IF_FAILED(server->AddShare(portString.c_str(), nullptr, 0));
163
}