Netdev List
 help / color / mirror / Atom feed
* [PATCH net] selftests/net: Fix flaky bind_wildcard due to ephemeral port race
@ 2026-09-01 11:31 Ricardo B. Marlière (SUSE)
  2026-09-05  1:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Ricardo B. Marlière (SUSE) @ 2026-09-01 11:31 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Shuah Khan
  Cc: netdev, linux-kselftest, linux-kernel,
	Ricardo B. Marlière (SUSE)

bind_wildcard picks an ephemeral port by binding fd[0] with port 0, reads
it back with getsockname(), and then reuses that exact port number for the
other addresses/families in fd[1..7]. This all happens in the default
network namespace, so unrelated processes on the same host are drawing from
the very same ephemeral port range (net.ipv4.ip_local_port_range) at the
same time.

Such a process can independently get assigned that exact port number on a
different, non-conflicting address in the short window between fd[0]'s
bind() and fd[1]'s, making fd[1]'s bind() fail with EADDRINUSE for reasons
that have nothing to do with the wildcard-bind behavior under test, e.g.:

  # bind_wildcard.c:775:plain:Expected ret (-1) == 0 (0)
  # plain: Test terminated by assertion
  not ok N bind_wildcard.v6_local_v4_local.plain

Fix it the same way so_incoming_cpu.c, tcp_port_share.c and
reuseport_dualstack.c already do: unshare into a fresh network namespace
and bring lo up, so there is nobody else to race with for the port.

Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
---
 tools/testing/selftests/net/bind_wildcard.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/net/bind_wildcard.c b/tools/testing/selftests/net/bind_wildcard.c
index 7d11548b2c61..be3298c791b2 100644
--- a/tools/testing/selftests/net/bind_wildcard.c
+++ b/tools/testing/selftests/net/bind_wildcard.c
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright Amazon.com Inc. or its affiliates. */
 
+#define _GNU_SOURCE
+#include <sched.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 
@@ -716,6 +718,9 @@ static void setup_addr(FIXTURE_DATA(bind_wildcard) *self, int i,
 
 FIXTURE_SETUP(bind_wildcard)
 {
+	ASSERT_EQ(unshare(CLONE_NEWNET), 0);
+	ASSERT_EQ(system("ip link set lo up"), 0);
+
 	setup_addr(self, 0, variant->family[0], variant->addr[0]);
 	setup_addr(self, 1, variant->family[1], variant->addr[1]);
 

---
base-commit: 1376afc7660bad2a1a5ee0876898312a486cf8bd
change-id: 20260901-selftests-net-bind_wildcard_race-c0067a2dc308

Best regards,
--  
Ricardo B. Marlière (SUSE) <ricardo@marliere.net>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] selftests/net: Fix flaky bind_wildcard due to ephemeral port race
  2026-09-01 11:31 [PATCH net] selftests/net: Fix flaky bind_wildcard due to ephemeral port race Ricardo B. Marlière (SUSE)
@ 2026-09-05  1:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-05  1:50 UTC (permalink / raw)
  To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_=28SUSE=29_=3Cricardo=40marliere=2Enet?=,
	=?utf-8?q?=3E?=
  Cc: davem, edumazet, kuba, pabeni, horms, shuah, netdev,
	linux-kselftest, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 01 Sep 2026 08:31:58 -0300 you wrote:
> bind_wildcard picks an ephemeral port by binding fd[0] with port 0, reads
> it back with getsockname(), and then reuses that exact port number for the
> other addresses/families in fd[1..7]. This all happens in the default
> network namespace, so unrelated processes on the same host are drawing from
> the very same ephemeral port range (net.ipv4.ip_local_port_range) at the
> same time.
> 
> [...]

Here is the summary with links:
  - [net] selftests/net: Fix flaky bind_wildcard due to ephemeral port race
    https://git.kernel.org/netdev/net-next/c/b910d4220d42

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-05  1:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-01 11:31 [PATCH net] selftests/net: Fix flaky bind_wildcard due to ephemeral port race Ricardo B. Marlière (SUSE)
2026-09-05  1:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox