๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24977

Re: [PATCH net v2 3/3] selftests: net: Add UDP bind conflict tests

#24977
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 05:29
118 lines
12158 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new selftest tools/testing/selftests/net/udp_bind_conflict.c
  does not run several kernel paths added by the two fixes it is meantโ€ฆ

--

selftests: net: Add UDP bind conflict tests

This adds a new kselftest, udp_bind_conflict, that checks how bind()
handles UDP conflicts in three cases: SO_REUSEPORT sockets, disconnect
via connect(AF_UNSPEC), and devices set by connect(). It also adds the
test to the net selftests Makefile and .gitignore.

> diff --git a/tools/testing/selftests/net/udp_bind_conflict.c b/tools/testing/selftests/net/udp_bind_conflict.c
> new file mode 100644
> index 0000000000000..9a67f58c348ab
> --- /dev/null
> +++ b/tools/testing/selftests/net/udp_bind_conflict.c
> @@ -0,0 +1,228 @@

[ ... ]

> +/* A device that connect() set used to count in the conflict check, so a
> + * socket on another device could bind next to [::]:PORT and overlap it
> + * once it disconnected.
> + */
> +TEST_F(udp_bind_conflict, connect_device_ignored)
> +{
> +	int fd;
> +
> +	fd = udp_bind(self, "::", 0, false);
> +	ASSERT_LE(0, fd);
> +	ASSERT_EQ(0, connect_link_local(fd, self->d0));
> +	ASSERT_EQ(-EADDRINUSE, udp_bind(self, "::", self->lo, false));
> +}

[Severity: Low]
This isn't a bug, but does this test reach the secondary hash half of
the connect() device fix?

Both sockets are bound to the wildcard "::", and there are only two
sockets on the port. inet_use_hash2_on_bind() returns false for
in6addr_any, and hslot->count stays well below 10. That means
udp_lib_get_port() only goes through udp_lib_lport_inuse():

net/ipv4/udp.c:udp_lib_get_port() {
    ...
	if (inet_use_hash2_on_bind(sk) && hslot->count > 10) {
    ...
}

So no socket whose device was set by connect() ever reaches the
udp_bound_dev_if() call in udp_lib_lport_inuse2(). The same goes for
the dif2 comparison in udp_sk_reuseport_match() on that path.
reuseport_scan_hash2 does scan hash2, but its devices are all set
through SO_BINDTOIFINDEX.

The clearing of SOCK_CONNECT_DEV in sock_bindtoindex_locked() doesn't
seem to be covered either:

net/core/sock.c:sock_bindtoindex_locked() {
    ...
	WRITE_ONCE(sk->sk_userlocks, sk->sk_userlocks & ~SOCK_CONNECT_DEV);
    ...
}

The series' disconnect commit describes this as "SO_BINDTODEVICE and
SO_BINDTOIFINDEX drop the record". The only sequence that runs it is
connect() to a link-local peer, then SO_BINDTOIFINDEX, then disconnect.
None of the tests does that:

- disconnect_keeps_device uses an IPv4 socket that never connects, so
  it never has SOCK_CONNECT_DEV set.
- disconnect_keeps_scoped_device gets its device from bind().
- disconnect_clears_connect_device and connect_device_ignored never
  call SO_BINDTOIFINDEX after connect_link_local().

If the line above were removed, wouldn't every test here still pass?

Two branches in __ip6_datagram_connect() are also not reached. The
first is the rollback when ip6_datagram_dst_update() fails:

	err = ip6_datagram_dst_update(sk, true);
	if (err) {
		...
		WRITE_ONCE(sk->sk_bound_dev_if, old_bound_dev_if);
		if (!old_bound_dev_if) {
			...
			WRITE_ONCE(sk->sk_userlocks,
				   sk->sk_userlocks & ~SOCK_CONNECT_DEV);
		}

The second is the multicast branch that takes the device from
mcast_oif:

		if (!sk->sk_bound_dev_if && (addr_type & IPV6_ADDR_MULTICAST))
			ip6_datagram_connect_dev(sk, old_bound_dev_if,
						 READ_ONCE(np->mcast_oif));

The commit message says these tests cover "the two bind conflict fixes
in this series". Could the test add cases for these paths? For example:

- a specific address with more than 10 sockets on the port, where one
  socket's device was set by connect()
- connect(), then SO_BINDTOIFINDEX, then disconnect
- a connect() that fails
- a connect() to a multicast peer

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130050729.893-1-juanagusnicco%40gmail.com
Technical Details
Message-ID: <179610295503.3146.6369544656734538361@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374710-linux-kernel-netdev=dewy.ru
References: <20261130050729.893-4-juanagusnicco@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374710-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 3/3] selftests: net: Add UDP bind conflict tests
Date: Tue, 01 Dec 2026 05:29:15 +0000
Organization: Usenet Network
Message-ID: <179610295503.3146.6369544656734538361@kernel.org>
References: <20261130050729.893-4-juanagusnicco@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1624849"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:W6xarAyzxsxi5N/thIfjE6ZPlH0= sha256:+JXQLDaK1tVP7Y25r/+eA+99Czh2t39pwToiGQZvoKs=
	sha1:Y+JlBN85imb+B0wFS/iMMSSqhqY= sha256:3Cu17dUBD6TrZgnTZrjUa2DyePOAF30252p3Whquku4=
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 9CB23117244; Tue,  1 Dec 2026 08:29:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 UlF59KSNr9OF;
	Tue,  1 Dec 2026 08:29:34 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374710-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id F234C117245; Tue,  1 Dec 2026 08:29:25 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 108D926036; Tue,  1 Dec 2026 05:29:20 +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=1796102958;
	b=nm0DRfgin9FawHV1QZakoWHTbtJPCgiJXRq5KAkygkBD8gFB0iz3379HKX3Rxq05lwHi
	 2ENj+sbpJY1TzbQdyrH0UyEAXir7beqCO0mReebR+Xihj6dzKBuIZ+JBg6986E7E8Hn/g
	 SaMdOD88+jSLfXTL/LlatlGU+Nueivcfu1FpFf2ccRLqMmX3OUSmrbXqLFVdf2PNb5WJV
	 eKSk9wTALMMSqppYmRl8XP7FPll4YZq+Td+f5eF97ZDOhxN/YtlTskQlptYH+/hLIj1bV
	 Li/zW/ktS4piDRdhK2u+Wc2aTqOTAdZj6eYoi3D7OJ76qRs9CK4Wg4Hm3H8seFbBsPw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796102958;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=3pDCnCyIGXt1LgTnVlqS7jIh+YxmZuh3C7+vVW7hBKo=;
	b=V1K7ufvbLv54CTW8sgnhSz0EzTTyYpCjwqgCNXoP/L2l/4M25MqBT0WDEgihHDAGJQwD
	 jtEqtvvFs0fICeZDXziBJ/kgyV7ca8lSmIR9xNYFyIludQUeZFiVA8DWlGOpVznMhhb00
	 pgGi74EPcbYUYIxetButZI+HU+jWRX6K7Z150j9753PQg16x3m4ilSVF9xPS38s6W/U3a
	 x9lLUR0LMRF7ep8RPP2mXN+kDp8RP8k9hB+ZsKdcFdeT0Sbf8kZtMb/7Qs8d8E4W00qFR
	 A5aJZ26VnxCsI2X2Q4HqnhCigbZW3+s/QWGQpLs10qF5BWzBWce1R8u/XloZM9JEzOg==
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=UnXXB7r1;
	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 2460A606A685;
	Tue,  1 Dec 2026 05:29:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UnXXB7r1
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=1796102957;
	b=eUENHkt/AFdInK0XBXSJe7U6Eond5opLWQnRmxJ9pqmooHoW3ER6ofJRjypIBwWuROby
	 H6x3YmulFZuUm6nHLWAKL4L+EEO4a2lHl3GyN9prWLvZ/Tu2cU2E2EMKtS8RD4flzelqk
	 +1xKyeE+VECDu0FzrFtvPdLdUkhIDHqBNNBht1BH+gkCtQ55yER9ppUrrdWh+rX7D2iYC
	 795Jhv1k9eGry/mZ8i3Sv0zifEWePhPe5YjAT2o4NNU/4eZ/kamgrgtrK5MC4NLPL5qTd
	 PAG+3TxXknSXd7AoixVa6Citmw8Q+PRL7rYWKhEPC0bZB5r9rMpySmPj6jlfRI63jHw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796102957;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=3pDCnCyIGXt1LgTnVlqS7jIh+YxmZuh3C7+vVW7hBKo=;
	b=ZY3ar3/gx6+l5m8rehK9nxu8gx2BnfEzsID4T+y7h1Tv7GC8xNOo9Jc6iLT5QG61U7RQ
	 pfGoP2BTw4wg18rO7ZaplEWb0D4HxuimbBW0EMmy2j+WmyT3PKS0Owjo/2xBmNEXV+wYE
	 uB4FK38nfOnpJv+NPzF+6XEQLc/InRQMXeODT73c3/oPzWPHqjp1CdgzYFvSxQc7R9q1U
	 kmhpHl5r9Rn52pxr6X2kNuCXMNv/e7QCeWBNtEh5DF3fL75wPOJH9Hq+4cbH4ZlVpsGJN
	 nqbn/UWK6ceAXJkbiX3vB8Q1z+XfcAITwNS50oTQdgEx4+e0rGqgv6bhmldvBiX7Szg==
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=UnXXB7r1;
	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 41369606A320;
	Tue,  1 Dec 2026 05:29:16 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 834711F000C1;
	Tue,  1 Dec 2026 05:29:15 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796102956;
	bh=3pDCnCyIGXt1LgTnVlqS7jIh+YxmZuh3C7+vVW7hBKo=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=UnXXB7r1B7qap/MZzGOIXdqmXx4GLslhj6vDBbnNh17sH8eexQVwJZp+LJOIFtBis
	 wFbTdzqds1JJiAAVfNhdHV19K9Ss/zzKp99stsInaUB0mCNqs74Vbz5ekah2zh1y9M
	 Jb8VuSP+6UiTwG7c79+KRjFAWmWbSbfUdZNf+zYYA2DfXKZxiPtrWIU0GntAMWgFsj
	 KGH5s8zENrz36pu2WFVNROrzYnMfPZ85uqCsYsmL1/5Ttj5mCB7N13Y4iEY6Eiieoh
	 3eAYh30UU0DT3eoxahkJM8QQz6WKzbYTjPcD5NKQctNm0EqH3alhdno2UvY7G+c+zJ
	 9W3L6zah8SzwA==
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, horms@kernel.org, kuniyu@google.com, willemb@google.com,
 willemdebruijn.kernel@gmail.com, dsahern@kernel.org, idosch@nvidia.com,
 shuah@kernel.org, tpluszz77@gmail.com, brauner@kernel.org,
 alice.kernel@fastmail.im, kylebot@openai.com, joe@dama.to, leitao@debian.org,
 xudu@redhat.com, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261130050729.893-4-juanagusnicco@gmail.com>
X-sashiko-severity: Low
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