Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by netdev-bot+sashiko
Thu, 19 Nov 2026 09:57
Re: [PATCH net 2/2] selftests: net: cover connected UDP reuseport rescore
Author: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 09:57
Date: Thu, 19 Nov 2026 09:57
194 lines
15425 bytes
15425 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] This patch's parent commit in the series, "udp: fix reuseport
rescore fallback", changes the rescore branch in udp4_lib_lookup2()…
- [Medium] On the default CONFIG_BASE_SMALL=n kernel,
test_connected_reuseport_rescore() never has a BPF program select the…
- [Low] The comment on the second assertion in
test_connected_reuseport_rescore()…
--
selftests: net: cover connected UDP reuseport rescore
This adds a reuseport_bpf selftest in which a constant classic BPF
program selects a connected UDP socket in a reuseport group. A packet
from a different peer should go to the unconnected socket, and a packet
from the connected peer should still reach the connected socket. The
test runs for both IPv4 and IPv6.
> diff --git a/tools/testing/selftests/net/reuseport_bpf.c b/tools/testing/selftests/net/reuseport_bpf.c
> index 12e48b97b8625..fbfe73dce2111 100644
> --- a/tools/testing/selftests/net/reuseport_bpf.c
> +++ b/tools/testing/selftests/net/reuseport_bpf.c
> @@ -303,6 +303,154 @@ static void test_reuseport_cbpf(struct test_params p)
[ ... ]
> +static void test_connected_reuseport_rescore(int family)
> +{
[ ... ]
> + good_addr = new_loopback_sockaddr(family, 0);
> + if (bind(good_fd, good_addr, sockaddr_size()))
> + error(1, errno, "failed to bind good reuseport socket");
> + if (getsockname(good_fd, good_addr, (socklen_t []){ sockaddr_size() }))
> + error(1, errno, "failed to get reuseport port");
> + recv_port = get_sockaddr_port(good_addr);
> + if (bind(connected_fd, good_addr, sockaddr_size()))
> + error(1, errno, "failed to bind connected reuseport socket");
> +
> + match_src = new_loopback_sockaddr(family, 0);
[ ... ]
> + peer_addr = new_loopback_sockaddr(family, peer_port);
> + if (connect(connected_fd, peer_addr, sockaddr_size()))
> + error(1, errno, "failed to connect reuseport socket");
> +
> + /* Bind order makes good_fd index 0 and connected_fd index 1. */
> + attach_cbpf_index(good_fd, 1);
[Severity: Medium]
Is connected_fd still in the reuseport group at this point?
On a default CONFIG_BASE_SMALL=n kernel, connected_fd is bound to
127.0.0.1 or ::1. So udp_connect() calls udp4_hash4() (udpv6_connect()
calls udp6_hash4()), and udp_lib_hash4() detaches the socket:
net/ipv4/udp.c:udp_lib_hash4() {
...
spin_lock_bh(&hslot->lock);
if (rcu_access_pointer(sk->sk_reuseport_cb))
reuseport_detach_sock(sk);
...
}
That leaves good_fd as the only member (num_socks == 1), while has_conns
stays set from __ip4_datagram_connect(). The cBPF return value of 1 is
then out of range, and run_bpf_filter() rejects it:
net/core/sock_reuseport.c:run_bpf_filter() {
...
if (index >= socks)
return NULL;
...
}
reuseport_select_sock_by_hash() then picks good_fd.
As a result, the mismatch packet reaches good_fd on both the old and the
new code. A good_fd rescored to an equal score is kept either way. The
match packet is resolved by udp4_lib_lookup4() or udp6_lib_lookup4() in
__udp4_lib_lookup() or __udp6_lib_lookup(), before udp*_lib_lookup2()
runs.
The case the test is named after, a BPF-selected connected socket kept as
a stale result, only seems to reproduce on CONFIG_BASE_SMALL=y kernels.
There udp_lib_hash4() is a stub and connected_fd stays at index 1.
Could the setup keep a connected socket in the group on hash4 kernels?
One option is to bind and connect connected_fd before good_fd binds, so
that reuseport_add_sock() rebuilds the group around it, and then set
has_conns. Failing that, could the test at least check the group
membership it assumes, rather than passing silently?
[ ... ]
> + /* An unmatched BPF-selected socket must not replace the valid candidate. */
> + send_udp_packet(other_send_fd, dst, mismatch_payload);
> + expect_udp_socket(epfd, good_fd, connected_fd, good_fd,
> + mismatch_payload);
[Severity: High]
This is about the parent commit 33c2c891d6d7 ("udp: fix reuseport rescore
fallback"), but this test can't detect it. That commit changes the
rescore branch in udp4_lib_lookup2() and udp6_lib_lookup2() to:
if (need_rescore) {
if (score > badness)
badness = score;
else
result = sk;
continue;
}
Suppose the socket picked by the reuseport program or hash scores the
same as sk, the socket that set badness. Won't the pick then be dropped
and sk returned instead?
Before that change, an equal score left result unchanged, so the pick
was kept. Only a lower score, the stale connected socket case, seems to
need the fallback.
Unconnected sockets have sk_incoming_cpu == -1 unless SO_INCOMING_CPU is
set, and only connected sockets update it. So equal scores are the usual
case.
reuseport_has_conns_set() sets has_conns in __ip4_datagram_connect() and
__ip6_datagram_connect() when a member bound to a specific address
connects. The flag is never cleared, and it stays set after
udp_lib_hash4() detaches the connected socket.
For example, take unconnected A and B plus connected C, all bound to
127.0.0.1:X, with the BPF program or hash picking B. B rescores equal to
A, the else branch sets result = A, and A gets every packet from
unconnected peers.
Does this override hash load balancing and cBPF/eBPF steering in every
group with has_conns set? One such setup is a QUIC-style server with
several unconnected workers and per-connection connected sockets on the
same address and port.
The parent is tagged Cc: stable. Should it keep the pick unless
score < badness?
This test uses only one unconnected and one connected socket, so it
can't catch this. Could it add a second unconnected socket and have the
BPF program select that one?
> +
> + /* A matching selected socket must still win the positive rescore path. */
> + send_udp_packet(match_send_fd, dst, match_payload);
> + expect_udp_socket(epfd, good_fd, connected_fd, connected_fd,
> + match_payload);
[Severity: Low]
Is this comment accurate? On every config, the match packet seems to be
decided by something other than the positive rescore branch
(score > badness).
On default CONFIG_BASE_SMALL=n kernels, connected_fd is in the 4-tuple
hash. __udp4_lib_lookup() returns it from udp4_lib_lookup4() before
udp4_lib_lookup2() runs, and IPv6 does the same through
udp6_lib_lookup4().
On IPv4 with CONFIG_BASE_SMALL=y, connected_fd is bound second, and
udp_lib_get_port() adds it at the head of hslot2. It is scanned first and
taken by this shortcut, with no reuseport selection or rescore:
if (sk->sk_state == TCP_ESTABLISHED) {
result = sk;
continue;
}
On IPv6 with CONFIG_BASE_SMALL=y, the rescore does run. But connected_fd
outscores good_fd on its own merits. Even if the positive branch fell
back to result = sk, the next iteration would still pick connected_fd
through the TCP_ESTABLISHED shortcut.
So can this assertion catch a regression in the badness = score branch?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794759652.git.zihanx%40nebusec.ai
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads