Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: juanagusnicco@gmail.com
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
Subject: Re: [PATCH net v2 3/3] selftests: net: Add UDP bind conflict tests
Date: Tue, 01 Dec 2026 05:29:15 +0000	[thread overview]
Message-ID: <179610295503.3146.6369544656734538361@kernel.org> (raw)
In-Reply-To: <20261130050729.893-4-juanagusnicco@gmail.com>

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

      reply	other threads:[~2026-12-01  5:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  5:07 [PATCH net v2 0/3] udp: Fix bind conflict check bypasses Juan Agustin Niccolini
2026-11-30  5:07 ` [PATCH net v2 1/3] udp: Keep the bound device on disconnect unless connect() set it Juan Agustin Niccolini
2026-12-01  5:29   ` netdev-bot+sashiko
2026-11-30  5:07 ` [PATCH net v2 2/3] udp: Ignore a connect()-set device in the bind conflict check Juan Agustin Niccolini
2026-12-01  5:29   ` netdev-bot+sashiko
2026-11-30  5:07 ` [PATCH net v2 3/3] selftests: net: Add UDP bind conflict tests Juan Agustin Niccolini
2026-12-01  5:29   ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179610295503.3146.6369544656734538361@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alice.kernel@fastmail.im \
    --cc=brauner@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=joe@dama.to \
    --cc=juanagusnicco@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=kylebot@openai.com \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=tpluszz77@gmail.com \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=xudu@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox