Article View: linux.kernel.netdev
Article #11614Re: [PATCH net 1/2] tcp: avoid false bind exhaustion with odd-sized port ranges
From: Eric Dumazet
Date: Thu, 05 Nov 2026 11:17
Date: Thu, 05 Nov 2026 11:17
76 lines
12046 bytes
12046 bytes
Le jeu. 5 nov. 2026 ร 12:04, Florin Badita-Nistor
<baditaflorin@gmail.com> a รฉcrit :
>
> inet_csk_find_open_port() rounds the range length down to an even
> number but keeps the original exclusive upper bound for wrapping.
> For an odd-sized range, the two scans can therefore miss a valid port
> and return EADDRINUSE while an eligible port remains free.
>
> For example, restrict a TCP socket to IP_LOCAL_PORT_RANGE [40000, 40002]
> and hold explicit binds on 40000 and 40001. bind(..., 0) always fails,
> although an explicit bind to 40002 succeeds. Both IPv4 and IPv6 TCP and
> MPTCP are affected. A namespace-wide odd-sized ip_local_port_range can
> also trigger the failure without a per-socket range setting.
>
> Keep the full length for the scan bound and wrapping. The two scans
> then cover every candidate in an odd-sized range, with at most one
> repeated candidate when exhausted. Even-sized candidate sequences
> remain unchanged.
>
Please mention the side effect: with an odd @remaining, the wrap
(port -= remaining) flips parity, so the first scan is no longer
restricted to odd offsets. For odd-sized ranges, bind() will now pick
ports of the parity __inet_hash_connect() prefers.
I think this is fine: same-parity netns ranges already trigger
"ip_local_port_range: prefer different parity for start/end values",
and __inet_hash_connect() ignores parity (step == 1) for per-socket
IP_LOCAL_PORT_RANGE. But the changelog should say so.
Also note that __inet_hash_connect() has the same rounding for
netns-wide ranges, so connect() still misses a port there. This is
fine since the sysctl already warns about this setup, but the
changelog should not suggest netns-wide odd ranges are now fully
handled.
> The issue was triggered while developing port-range selftests with
> Codex assistance, then confirmed using userspace reproducers on
> unmodified kernels. No kernel instrumentation or fault injection was
> needed. Booted x86-64 KVM kernels were tested against the regression
> selftest, the full ip_local_port_range suite, and a Go net.Listen
> reproducer. The Go reproducer fails 100/100 times per IP version before
> the fix and 0/100 afterwards with a three-port namespace range and two
> listeners occupying its first two ports.
>
> Fixes: ea8add2b1903 ("tcp/dccp: better use of ephemeral ports in bind()")
> Cc: stable@vger.kernel.org
This has been there since 2016 and needs an odd-sized range, I would
target net-next and drop the stable Cc.
> Signed-off-by: Florin Badita-Nistor <baditaflorin@gmail.com>
> ---
> net/ipv4/inet_connection_sock.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
> index e56beec43..755fcea35 100644
> --- a/net/ipv4/inet_connection_sock.c
> +++ b/net/ipv4/inet_connection_sock.c
> @@ -343,8 +343,6 @@ inet_csk_find_open_port(const struct sock *sk,
> struct inet_bind_bucket **tb_ret,
Both patches are mangled by your mailer (wrapped hunk header here,
wrapped diff --git line in 2/2), they do not apply. Please use
git send-email for v2.
Also, please trim the cover letter to the problem and the test
results.
The code change itself looks good to me.
pw-bot:cr
Technical Details
Message-ID:
<CAL4WiirS2n23vb9qHUHX+xBWqjiiM2KzCoFR2dysEzdXrcFQpg@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357246-linux-kernel-netdev=dewy.ruReferences:
<CADnh+D0zSzAyYCLo5cXU56o9X-P3RG3N2ix7ARPrP95d8sBXmg@mail.gmail.com> <CADnh+D3nz5aehxjvurK+Fv7gF6n4csMm-dFatvdMmg1fWdGSQg@mail.gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357246-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/2] tcp: avoid false bind exhaustion with odd-sized
port ranges
Date: Thu, 5 Nov 2026 12:17:56 +0100
Organization: Usenet Network
Message-ID: <CAL4WiirS2n23vb9qHUHX+xBWqjiiM2KzCoFR2dysEzdXrcFQpg@mail.gmail.com>
References: <CADnh+D0zSzAyYCLo5cXU56o9X-P3RG3N2ix7ARPrP95d8sBXmg@mail.gmail.com>
<CADnh+D3nz5aehxjvurK+Fv7gF6n4csMm-dFatvdMmg1fWdGSQg@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="3622109"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:9inceaB+XeNSwUNYw8Nbftk7q9A= sha256:uhOEfa04DwcbsusR1siXTlSc3BbkWvAK/KomGUBbAXA=
sha1:3JgDWGBnTBDfO6MHRD/oJl5euLE= sha256:CzyV33xXgAYbO1wKN2qEUkPDvtBGzW9J9JFyOEx/OWc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id A28DF112F30; Thu, 5 Nov 2026 14:24:45 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id XVcBaZSRlHFI;
Thu, 5 Nov 2026 14:24:42 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-357246-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 58D5A112F26; Thu, 5 Nov 2026 14:24:32 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 8CF912ACAF; Thu, 5 Nov 2026 11:18:12 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793877489;
b=uz5+hFWTiwLoWC1K3kxWdQWXwAL7z68oecmWjK1PFcN/NGR8dcjrWS2GX6zJPHRxKxZJ
jlZ1hkM3OqpFTHvt80GGB+oS29rkKaDBXJob1EtkSLq/gvktpmU4Jplc2Vschn2vEQ/MK
QVTb79aUV39ijCtrTk6hz5Bl25aDjy1RCG20wCPxbSWiiZAjx/BLMdU0JkDza2AEbGtvn
6CdjWYuaIv6MKsAzcwBtYH5DZYQRVH8/NR17/fRdDbvn4/kcBSL9M9pCivjWs4ZC3Qn7O
9W3G1HvaAwEdiB9Xg1D8gXO8rBDQyXg0Vun8QfXlTbLNvyl8nr949OSW1HgW1u/aSDg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793877489;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Gm-Message-State:X-Received:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=wszJKqQ7vFshINTrVXEK5rc9+i0D30W3f9krG8OLLZ8=;
b=rwj76206Y8fUf4uiTuFExzaxxGLqvdJFTS+3nGLgA4CU5epwXWiThO1+jYyexFoVg6KU
6u4NwdlRdtKIBiyqRv6M2POY9zUcdUG8UUqCLavPto8mxzQPPhZrEEk/53vZfJnMYt1fE
T3FUX9ZmUGIRBaGsHsugYis/qlFc7hpZouOOJsnHwgtmsqqnxAd2vXtKW4xSqtd0xDW5Y
VFXHhQJyBNZnzekyBYE9XZ9D7IJyqdxhdO0WLYenaJ9YNH1PKwRDK1lKDDScNH6X1fKV6
2koQPR0T0JNYmIZPQpp9dT/r6Abg5kOxhlbMX25Z2hMzHwhbwQBvonsC3tf0duMVfng==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k3bwezQM;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id D2ED7606A337;
Thu, 5 Nov 2026 11:18:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k3bwezQM
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793877489;
b=M1yz2dc6zGTbTmhb5/DKxHToxZxClnyv7/GV4/gr4jDvusWJXJuCegXXD6QsR/XEHxWD
hHA3K+O3LVvijfuvnO+qjyfCsmHBCet3bGE20S+pb3w9oeth4X26i+CSDd659TLkjiPAl
oVDt6yvKljTs6wZfIdx+9LBA9oj1o8g6BREqIWNDmxPLI1vjFYoq3F/5THusowbY/zBya
Wb7Pd5wzOVKGAX36mI9F725xbUtPOzf2D2IsMSQB7Q02k7OiqOqwjEPZLAJ/auWH5jUf2
8/PQr3rdu4mT0rtaWVKGTxZbZHio9M56oyZNB27NCb8ZeX6YaFr3aDkbpvjTbvrarZg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793877489;
h=Received:DKIM-Signature:Received:X-Gm-Message-State:X-Received:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=wszJKqQ7vFshINTrVXEK5rc9+i0D30W3f9krG8OLLZ8=;
b=J9e7+rG+XkrtB6Jzb+nkl79vupaTrDknxsSLqUt242S1snD3e312W+HCnTdoC03rekp7
Nq+tqXBhTL0fxYYb4dRvxTGgSZCA7dztqUyHNncfLop9CzH6WHF6bBAD2Ge1eGbdJ1GzH
OPY0Ypmpn7dhqsYizacIa2XuF4uCj3iFnDc7U6llGy4iZzkUysxA0pR2Oj+nESxKRYbaJ
d8LyUsIBX+qAE9j8O1o2VowPGY33YNSvBXhjebAZNSPWjiirY7yzcWk2Sj2GY1HWtZjIf
iI6VZFuXMlBOvSzS/viwX+RiJCwconv4CXIPdUgV0CeUN36yq52Sf0o8YMT/W9JVQ2Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k3bwezQM;
arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C187606A31B
for <netdev@vger.kernel.org>; Thu, 5 Nov 2026 11:18:08 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFEAA1F00A18
for <netdev@vger.kernel.org>; Thu, 5 Nov 2026 11:18:07 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1793877487;
bh=wszJKqQ7vFshINTrVXEK5rc9+i0D30W3f9krG8OLLZ8=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=k3bwezQMNaSzhCkfe518wQKTSVDtdVSK8lB4OiM1oxu0EGtFXv81SqswjCWBukLzd
F8I8K+tNYrXlm8+qr5tIDj3gpamtq3/CWbdcpXtOXhqvGOxjyr9gfbdyEHyeCocAGx
ZrHPt8I8Xvvj+drcbpb9a27ZdFB1O2HVqn4/dE6lCzFvvK2jigkrXqtAbMkI7/nVqL
k7QmTF+mxBE636I0THJrhyn3yl+DWZK371Aca42DoKZGq7z4BVTzXiuIHixRi3D0Xd
ip27noYF3/V47i14SuIphmgx5R8IlSRGwzOB63UFOiw1emlNfFO49tOJyjRvvXRlt8
A4pUcuteC82Lg==
X-Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-48e9476e26aso678537fac.3
for <netdev@vger.kernel.org>; Thu, 05 Nov 2026 03:18:07 -0800 (PST)
X-Gm-Message-State: APuU4Z8FyRe2cDJ4hfFG5R6uf0ZLDJoRJ+hUyswXFzvseRd5ocW5jWbk
ma6rXfIOVd1yP7uJFyl/aUNuXWIVRBjhQwkYtX018DykJoLC379A3lRDGZGyECeapjxcTD33gOW
fOtsqXPprVO2pqo0yJBbnxVAt1axjsoA=
X-Received: by 2002:a05:6870:8092:b0:48f:e0e5:a1df with SMTP id
586e51a60fabf-4a907749896mr12947836fac.52.1793877487117; Thu, 05 Nov 2026
03:18:07 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <CADnh+D3nz5aehxjvurK+Fv7gF6n4csMm-dFatvdMmg1fWdGSQg@mail.gmail.com>
X-Gmail-Original-Message-ID: <CAL4WiirS2n23vb9qHUHX+xBWqjiiM2KzCoFR2dysEzdXrcFQpg@mail.gmail.com>
X-Gm-Features: AclHuK-pvn0m-9uS9aQ6FNIbKhQl35Phni9k8v6IFOqKapHq_20UkmcmQL-t-8A
X-Cc: netdev@vger.kernel.org, ncardwell@google.com, kuniyu@google.com,
davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
shuah@kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org