[PATCH net 0/2] tcp: fix false exhaustion of odd-sized bind port ranges
From: Florin Badita-Nistor
Date: Thu Nov 05 2026 - 06:09:55 EST
TCP and MPTCP can reject an automatic bind with EADDRINUSE while an
eligible port is still free in an odd-sized local port range. For a
three-port range with its first two ports occupied, automatic binding
always fails although explicitly binding the final port succeeds.
Patch 1 keeps the complete range length in inet_csk_find_open_port().
Patch 2 adds regression coverage for each free-port position in three-
and five-port ranges, with both lower-bound parities and all existing
protocol/IP fixture variants.
The issue was triggered while extending port-range tests with Codex
assistance, then isolated using userspace reproducers on unmodified
kernels. No kernel instrumentation or fault injection was used.
Codex assisted with analysis, reproducers, patch/test code and commit
messages. The task was to find a small networking contribution relevant
to high-concurrency workloads; the missed-port case emerged during that
investigation. An independent model review found no correctness blocker.
Built and booted the exact net base below and that base with the fix in
separate x86-64 KVM guests using the same configuration and binaries:
New regression test: 4 failures before, 0 afterwards (8 cases).
Full port-range suite: 4 failures before, 0 afterwards (80 cases).
Two existing SCTP late_bind XPASS outcomes are unchanged.
Go net.Listen with a three-port namespace range and two listeners:
IPv4: 100/100 failures before, 0/100 afterwards.
IPv6: 100/100 failures before, 0/100 afterwards.
Explicitly listening on the free final port succeeds in both kernels.
Even-sized candidate sequences are unchanged. This is a correctness fix
for odd-sized ranges, without a general throughput claim.
The userspace selftests were compiled with -Wall. The boot-tested kernel
builds used W=1. The changed allocator object also compiled with W=1
under allyesconfig and allmodconfig (object builds, not full builds of
those two configurations). The baseline W=1 build emitted an existing
Synaptics input-driver format warning outside these changes; the changed
allocator object compiled without diagnostics. Both emails were sent
through a self-only transport test,
read back as raw messages and applied with git am, reproducing the exact
expected tree with preserved author identity and threading.
Florin Badita-Nistor (2):
tcp: avoid false bind exhaustion with odd-sized port ranges
selftests/net: cover odd-sized local port ranges with one free port
net/ipv4/inet_connection_sock.c | 2 -
.../selftests/net/ip_local_port_range.c | 67 ++++++++++++++++++-
2 files changed, 64 insertions(+), 5 deletions(-)
base-commit: c6b41de4dd9f2d6856d8d8d292348f7961034152
--
2.51.0