Skip to content

Conversation

@akerouanton
Copy link
Member

@akerouanton akerouanton commented Aug 8, 2025

- What I did

The userland proxy uses unconnected UDP sockets to receive packets from anywhere, so enabling SO_REUSEADDR means that multiple sockets can bind the same port. This defeats the purpose of the portallocator, which is supposed to ensure that the port is free and not already in use (either by us, or by another process). So, do not enable SO_REUSEADDR for UDP sockets.

- How to verify it

A new unit test is added to make sure that the same UDP port can't be bound more than once.

- Human readable description for the release notes

- Fix a bug that could cause the Engine and another host process to bind the same UDP port

Copy link

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 bug where the Docker Engine's port allocator could allow multiple UDP sockets to bind to the same port by preventing SO_REUSEADDR from being set on UDP sockets.

  • Modified bindTCPOrUDP function to only set SO_REUSEADDR for TCP sockets
  • Added a unit test to verify that duplicate UDP port binds are properly rejected
  • Ensures port allocator correctly detects conflicts for UDP ports

Reviewed Changes

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

File Description
daemon/libnetwork/portallocator/osallocator_linux.go Conditionally sets SO_REUSEADDR only for TCP protocol
daemon/libnetwork/portallocator/osallocator_linux_test.go Adds test to verify UDP port binding exclusivity

The userland proxy uses unconnected UDP sockets to receive packets from
anywhere, so enabling SO_REUSEADDR means that multiple sockets can bind
the same port. This defeats the purpose of the portallocator, which is
supposed to ensure that the port is free and not already in use (either
by us, or by another process). So, do not enable SO_REUSEADDR for UDP
sockets.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
@akerouanton akerouanton force-pushed the dont-reuseaddr-for-UDP branch from b05df88 to c6be4ad Compare August 8, 2025 11:46
@akerouanton akerouanton added this to the 29.0.0 milestone Aug 8, 2025
@akerouanton
Copy link
Member Author

There's one buildkit job failing on Windows:

=== FAIL: frontend/dockerfile  (0.00s)
panic: test timed out after 1h30m0s
	running tests:
		TestIntegration (1h30m0s)
		TestIntegration/slice=3-12/TestQuotedMetaArgs/worker=dockerd-containerd/frontend=builtin (1h27m12s)

But this PR only touches *_linux.go files, so let me merge it.

@akerouanton akerouanton merged commit 5cb7e19 into moby:master Aug 8, 2025
281 of 284 checks passed
@akerouanton akerouanton deleted the dont-reuseaddr-for-UDP branch August 8, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants