Skip to content

Fix mirrored networking loopback endpoint creation failure#14081

Open
benm-dev wants to merge 6 commits intomicrosoft:masterfrom
benm-dev:fix/mirrored-loopback-endpoint-firewall-policy
Open

Fix mirrored networking loopback endpoint creation failure#14081
benm-dev wants to merge 6 commits intomicrosoft:masterfrom
benm-dev:fix/mirrored-loopback-endpoint-firewall-policy

Conversation

@benm-dev
Copy link
Copy Markdown

@benm-dev benm-dev commented Jan 18, 2026

Summary of the Pull Request

Fix loopback endpoint creation failure in mirrored networking mode after KB5074109.

PR Checklist

Detailed Description

After KB5074109, HNS loopback networks reject firewall policies when creating endpoints, returning error 0x803B001B. This fix detects loopback networks via IsLoopback property and uses simplified endpoint settings without policies.

Validation Steps Performed

  1. Direct HCN API testing confirmed:
    • Endpoint WITH firewall policy → 0x803B001B (FAIL)
    • Endpoint with HostComputeNetwork only → 0x00000000 (SUCCESS)
  2. WSL localhost TCP connectivity verified working with correct endpoint settings
  3. Tested on Windows Build 26220.7535

@benm-dev
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in mirrored networking mode where loopback endpoint creation fails after Windows update KB5074109. The fix detects loopback networks and uses simplified endpoint settings without firewall policies to avoid HCN error 0x803B001B.

Changes:

  • Added loopback network detection logic to skip firewall policy application
  • Created separate endpoint configuration path for loopback networks using HostComputeNetwork
  • Extended HNSNetwork schema to include IsLoopback property for network type detection

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/windows/service/exe/MirroredNetworking.cpp Added conditional logic to detect loopback networks and configure endpoints without firewall policies, using HostComputeNetwork instead of VirtualNetwork
src/shared/inc/hns_schema.h Added IsLoopback boolean field to HNSNetwork struct with JSON serialization support

@offsechq
Copy link
Copy Markdown

lgtm

@ikifar2012
Copy link
Copy Markdown

Is this the same as issue #13454

@offsechq
Copy link
Copy Markdown

Doesn't look like it, that is more generic and solvable by resetting the adapter as the reply here

@benhillis
Copy link
Copy Markdown
Member

@keith-horton - does this look reasonable to you? Do you have any context on the Windows change that recently broke this?

@keith-horton
Copy link
Copy Markdown
Member

@keith-horton - does this look reasonable to you? Do you have any context on the Windows change that recently broke this?

The fix referred to in that KB article was not in WSL - it was in other parts of the TCPIP / vswitch stack - where we addressed a perf issue, but the NBL (kernel structure representing one or more packets) could have fields that some VPN vendors did not expect (though was perfectly legal) -- which was exercised in the WSL path. So we had to revert that and fix it in a way that did not break some VPNs.

So I don't know what would have changed that would have affected the above.

The author of this PR is correct: Hyper-V Firewall rules do not affect the loopback path.

Copy link
Copy Markdown
Member

@keith-horton keith-horton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this investigation and testing.

WSL supports older versions of Windows that does not support Hyper-V Firewall. This looks correct to me - minus the change I noted below.

Comment thread src/windows/service/exe/MirroredNetworking.cpp Outdated
@benm-dev benm-dev requested a review from keith-horton January 27, 2026 05:13
// Loopback networks require HostComputeNetwork (not VirtualNetwork) and don't support policies
hns::HostComputeEndpoint hnsEndpoint{};
hnsEndpoint.HostComputeNetwork = NetworkId;
hnsEndpoint.SchemaVersion.Major = 2;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: assuming these version numbers are hardcoded elsewhere too. Would be good to declare named constant that can be repeatedly used

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I worry a little bit about this schema version, do we know everywhere that supports mirrored networking supports 2.16?

Comment thread src/windows/service/exe/MirroredNetworking.cpp Outdated
@benm-dev
Copy link
Copy Markdown
Author

Hi @keith-horton , I updated this in commit c61ba69 - the condition now reads:

else if (m_config.FirewallConfig.Enabled() && isLoopbackNetwork)

The diff you're viewing is marked "Outdated" which shows the old code. Let me know if there's anything else needed!

@benm-dev benm-dev requested a review from keith-horton January 28, 2026 23:46
keith-horton
keith-horton previously approved these changes Jan 29, 2026
Copy link
Copy Markdown
Member

@keith-horton keith-horton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks for doing this!

Comment thread src/windows/service/exe/MirroredNetworking.cpp
@benhillis benhillis force-pushed the fix/mirrored-loopback-endpoint-firewall-policy branch from 65c96d9 to 94ac6f9 Compare February 11, 2026 16:22
@offsechq
Copy link
Copy Markdown

Can't wait till it find the way to production soon! thanks a lot

@kmj251
Copy link
Copy Markdown

kmj251 commented Feb 19, 2026

Is there an update on when this PR will be merged and a new release created?

Copilot AI review requested due to automatic review settings March 12, 2026 19:04
@benm-dev benm-dev requested a review from benhillis March 18, 2026 23:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/windows/service/exe/MirroredNetworking.cpp:501

  • Loopback networks are only handled specially when Hyper-V Firewall is enabled. If properties.IsLoopback is true and m_config.FirewallConfig.Enabled() is false, the code still builds endpoint settings with HNSEndpoint::VirtualNetwork = NetworkId, but the comment/PR description states loopback endpoints require HostComputeNetwork and fail when created with the other schema. Consider moving the loopback handling outside the firewall-enabled branch so loopback endpoints always use HostComputeEndpoint (without policies) regardless of firewall configuration.
        else if (m_config.FirewallConfig.Enabled() && isLoopbackNetwork)
        {
            // Loopback networks require HostComputeNetwork (not VirtualNetwork) and don't support policies
            hns::HostComputeEndpoint hnsEndpoint{};
            hnsEndpoint.HostComputeNetwork = NetworkId;
            hnsEndpoint.SchemaVersion.Major = 2;
            hnsEndpoint.SchemaVersion.Minor = 16;
            endpointSettings = ToJsonW(hnsEndpoint);
        }
        else
        {
            // If Hyper-V Firewall is not supported for this scenario, only configure the basic HNS endpoint object
            wsl::shared::hns::HNSEndpoint settings{};
            settings.VirtualNetwork = NetworkId;
            endpointSettings = ToJsonW(settings);
        }

Comment thread src/windows/service/exe/MirroredNetworking.cpp Outdated
Copilot AI review requested due to automatic review settings March 18, 2026 23:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +443 to +448
// Loopback networks don't support firewall policies - creating an endpoint with firewall
// policies on a loopback network will fail with HCN error 0x803B001B ("Invalid JSON document
// string"). This behavior changed in KB5074109. Additionally, loopback networks require
// HostComputeNetwork instead of VirtualNetwork in the endpoint settings.
// See: https://github.com/microsoft/WSL/issues/14080
const bool isLoopbackNetwork = properties.IsLoopback;
@benhillis benhillis force-pushed the fix/mirrored-loopback-endpoint-firewall-policy branch from 9d6818f to e57f5cf Compare March 19, 2026 19:49
@benm-dev benm-dev requested a review from Copilot March 19, 2026 21:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/windows/service/exe/MirroredNetworking.cpp
Comment thread src/windows/service/exe/MirroredNetworking.cpp Outdated
benm-dev and others added 3 commits March 27, 2026 12:35
## Problem
After installing KB5074109 (January 2026), WSL mirrored networking fails to
create the loopback endpoint, causing localhost (127.0.0.1) TCP/UDP connections
to fail. Users see the loopback0 interface in state DOWN with NO-CARRIER.

## Root Cause Analysis
HNS loopback networks no longer accept firewall policies when creating
endpoints. Direct HCN API testing confirms:

- Test 1: Endpoint WITH firewall policy -> 0x803B001B (FAIL)
  Error: 'Invalid JSON document string. {{Policies.VmCreatorId,UnknownField}}'

- Test 2: Endpoint with VirtualNetwork field -> 0x803B001B (FAIL)
  Error: 'Invalid JSON document string. {{VirtualNetwork,UnknownField}}'

- Test 3: Endpoint with HostComputeNetwork only -> 0x00000000 (SUCCESS)

The current code in MirroredNetworking::AddNetworkEndpoint() creates all
endpoints with firewall policies when m_config.FirewallConfig.Enabled() is
true (the default), causing loopback endpoint creation to fail silently.

## Solution
- Add IsLoopback field to HNSNetwork struct to detect loopback networks
- Skip firewall policies when creating endpoints on loopback networks
- Use HostComputeNetwork instead of VirtualNetwork for loopback endpoints

## Testing
Verified on Windows Build 26220.7535:
1. HCN API tests confirm endpoint creation succeeds without firewall policies
2. WSL localhost TCP connectivity works when loopback0 is properly configured

Fixes microsoft#14080
Related: microsoft#14063
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 27, 2026 19:35
@benhillis benhillis force-pushed the fix/mirrored-loopback-endpoint-firewall-policy branch from fa21b2b to 1004388 Compare March 27, 2026 19:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/exe/MirroredNetworking.cpp
@benhillis
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@benhillis
Copy link
Copy Markdown
Member

@benm-dev - sorry this one slipped through the cracks, taking a look now.

@azure-pipelines
Copy link
Copy Markdown

Commenter does not have sufficient privileges for PR 14081 in repo microsoft/WSL

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 15, 2026 20:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/windows/service/exe/MirroredNetworking.cpp
bool IsLoopback{};

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(HNSNetwork, ID, Name, SourceMac, DNSSuffix, DNSServerList, DNSDomain, Subnets, Flags, InterfaceConstraint);
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(HNSNetwork, ID, Name, SourceMac, DNSSuffix, DNSServerList, DNSDomain, Subnets, Flags, InterfaceConstraint, IsLoopback);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding IsLoopback to NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT changes both deserialization and serialization for HNSNetwork. If HNSNetwork is ever serialized for outbound HNS/HCN requests, this will now emit an IsLoopback field (default false), which could be rejected as an unexpected property. Consider either (1) making IsLoopback response-only via a custom to_json/from_json that omits it on serialization, or (2) splitting request vs response DTOs so response-only properties don’t get sent back to the platform.

Suggested change
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(HNSNetwork, ID, Name, SourceMac, DNSSuffix, DNSServerList, DNSDomain, Subnets, Flags, InterfaceConstraint, IsLoopback);
friend void to_json(nlohmann::json& Json, const HNSNetwork& Network)
{
Json = nlohmann::json{
{"ID", Network.ID},
{"Name", Network.Name},
{"SourceMac", Network.SourceMac},
{"DNSSuffix", Network.DNSSuffix},
{"DNSServerList", Network.DNSServerList},
{"DNSDomain", Network.DNSDomain},
{"Subnets", Network.Subnets},
{"Flags", Network.Flags},
{"InterfaceConstraint", Network.InterfaceConstraint},
};
}
friend void from_json(const nlohmann::json& Json, HNSNetwork& Network)
{
Network = HNSNetwork{};
if (const auto Entry = Json.find("ID"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.ID);
}
if (const auto Entry = Json.find("Name"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.Name);
}
if (const auto Entry = Json.find("SourceMac"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.SourceMac);
}
if (const auto Entry = Json.find("DNSSuffix"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.DNSSuffix);
}
if (const auto Entry = Json.find("DNSServerList"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.DNSServerList);
}
if (const auto Entry = Json.find("DNSDomain"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.DNSDomain);
}
if (const auto Entry = Json.find("Subnets"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.Subnets);
}
if (const auto Entry = Json.find("Flags"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.Flags);
}
if (const auto Entry = Json.find("InterfaceConstraint"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.InterfaceConstraint);
}
if (const auto Entry = Json.find("IsLoopback"); Entry != Json.end() && !Entry->is_null())
{
Entry->get_to(Network.IsLoopback);
}
}

Copilot uses AI. Check for mistakes.
@benhillis
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@benhillis
Copy link
Copy Markdown
Member

@benm-dev — latest CI is failing on formatting checks. Please rebase on master and run .\FormatSource.ps1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants