Skip to content

Deny guest binds to host ephemeral port range in mirrored mode#40597

Merged
FetoiuCatalin merged 2 commits into
masterfrom
user/cfetoiu/deny_host_ephemeral_range
May 22, 2026
Merged

Deny guest binds to host ephemeral port range in mirrored mode#40597
FetoiuCatalin merged 2 commits into
masterfrom
user/cfetoiu/deny_host_ephemeral_range

Conversation

@FetoiuCatalin
Copy link
Copy Markdown
Contributor

@FetoiuCatalin FetoiuCatalin commented May 19, 2026

Summary of the Pull Request

In mirrored mode, we pre-reserve a range for the guest to be used as guest ephemeral port range, but we don't prevent the guest from explicitly binding to the host ephemeral range
Update the wsl service to query the host ephemeral range and deny guest binds to that range

Validation Steps Performed

Manual testing of binds to non-ephemeral ports, host ephemeral port range and guest ephemeral port range.
Added new automated tests to cover the fixed scenario
Ran existing Network Tests, which include multiple port tracker/bind tests

Copilot AI review requested due to automatic review settings May 19, 2026 18:47
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

Note

Copilot was unable to run its full agentic suite in this review.

Adds enforcement in mirrored networking mode to deny guest binds to ports within the host's TCP/UDP ephemeral port ranges (except when those ports also fall in the guest's own reserved ephemeral range), preventing port conflicts with host applications.

Changes:

  • Query host TCP/UDP dynamic (ephemeral) port ranges from WMI when creating the guest network service and store them on the service instance.
  • Reject guest port allocation requests for ports that lie in the host ephemeral range but outside the guest's reserved range.
  • Add two new mirrored-mode tests verifying that TCP and UDP binds to host-ephemeral-range ports are denied.

Reviewed changes

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

File Description
src/windows/service/exe/WslCoreGuestNetworkService.h Declares new helpers and members for storing host ephemeral port ranges.
src/windows/service/exe/WslCoreGuestNetworkService.cpp Implements WMI-based ephemeral range lookup and new denial logic in OnPortAllocationRequest.
test/windows/NetworkTests.cpp Adds two mirrored-mode tests for TCP and UDP host-ephemeral-port denial.

Comment thread src/windows/service/exe/WslCoreGuestNetworkService.cpp Outdated
Comment thread src/windows/service/exe/WslCoreGuestNetworkService.cpp Outdated
Comment thread src/windows/service/exe/WslCoreGuestNetworkService.h
Comment thread test/windows/NetworkTests.cpp Outdated
Comment thread src/windows/service/exe/WslCoreGuestNetworkService.cpp
@FetoiuCatalin FetoiuCatalin marked this pull request as ready for review May 19, 2026 21:09
@FetoiuCatalin FetoiuCatalin requested a review from a team as a code owner May 19, 2026 21:09
Comment thread src/windows/service/exe/WslCoreGuestNetworkService.cpp Outdated
Comment thread src/windows/service/exe/WslCoreGuestNetworkService.cpp
Comment thread src/windows/service/exe/WslCoreGuestNetworkService.h
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 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/exe/WslCoreGuestNetworkService.cpp
@FetoiuCatalin FetoiuCatalin merged commit d193661 into master May 22, 2026
12 checks passed
@FetoiuCatalin FetoiuCatalin deleted the user/cfetoiu/deny_host_ephemeral_range branch May 22, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants