From: netdev-bot+sashiko@kernel.org
To: zihanx@nebusec.ai
Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
bpf@vger.kernel.org, willemdebruijn.kernel@gmail.com,
davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com,
horms@kernel.org, benh@amazon.com, kuniyu@google.com,
shuah@kernel.org, vega@nebusec.ai, kuba@kernel.org
Subject: Re: [PATCH net 1/2] udp: fix reuseport rescore fallback
Date: Thu, 19 Nov 2026 09:57:42 +0000 [thread overview]
Message-ID: <179508226205.3136.710014559426997072@kernel.org> (raw)
In-Reply-To: <8c46325c4a433f02fdc7241c0c3884126cb502af.1794759652.git.zihanx@nebusec.ai>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
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] The patch adds a rescore branch to udp4_lib_lookup2()
(net/ipv4/udp.c:478-484) and udp6_lib_lookup2()…
--
udp: fix reuseport rescore fallback
This changes the UDP lookup rescore path in udp4_lib_lookup2() and
udp6_lib_lookup2(). When the reuseport group has connected sockets, the
socket selected by reuseport is now kept only if its rescored value is
strictly higher than the current badness. Otherwise the lookup goes back to
the socket that set the current score.
Link: https://bugtracker.nebusec.ai/f/net/ipv6/udp.c||udp6_lib_lookup2||socket-hijack||m7q
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index 2e5562f353f85..23a8c951559c7 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -475,12 +475,17 @@ static struct sock *udp4_lib_lookup2(const struct net *net,
> rescore:
> score = compute_score(need_rescore ? result : sk, net, saddr,
> sport, daddr, hnum, dif, sdif);
> + if (need_rescore) {
> + if (score > badness)
> + badness = score;
> + else
> + result = sk;
> + continue;
> + }
[Severity: High]
Does this throw away the reuseport selection whenever the selected socket
only ties with sk, and not just when it fails to match the packet?
All unconnected members of a reuseport group get the same base score from
compute_score(). udp_reuseport_add_sock() requires the same family,
ipv6_only, bound device and rcv_saddr, and unconnected sockets have no
daddr or dport. The only thing that can differ is the incoming CPU bonus:
net/ipv4/udp.c:compute_score() {
...
if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
score++;
return score;
}
The hash path only ever returns a non-established socket:
net/core/sock_reuseport.c:reuseport_select_sock_by_hash() {
...
if (sk->sk_state != TCP_ESTABLISHED) {
if (!READ_ONCE(reuse->incoming_cpu))
return sk;
...
}
Once the group has at least one connected socket, reuseport_has_conns() is
true and the lookup goes like this:
udp4_lib_lookup2()
first unconnected member sk scores > badness
inet_lookup_reuseport() picks unconnected socket X
goto rescore
compute_score(X) == badness
result = sk
If so, all traffic for the unconnected members would go to the first group
member in the hslot2 chain. Wouldn't SK_REUSEPORT BPF and
SO_ATTACH_REUSEPORT_CBPF steering to unconnected members also be ignored
without any warning?
That looks like the behaviour that efc6b6f6c311, the Fixes: target of this
patch, removed. Its commit message says:
"unconnected sockets have the same score, hence only does the first
unconnected socket in udp_hslot always receive all packets ... the
result of reuseport_select_sock() should be used for load balancing."
The old code kept X on a tie. The problem described in this commit message
is the case where X does not match the packet at all: compute_score()
returns -1, for example when BPF selects a socket connected to a different
peer.
Could the fallback to sk happen only when score < 0 (or at most when
score < badness)? That would fix that case and keep load balancing.
The same logic is added to udp6_lib_lookup2(), where badness starts at -1
and the rescored unconnected socket also ties with sk.
The commit message says "Keep the selected socket only when its score is
higher". It does not mention the effect on load balancing or BPF steering.
Also, the selftest added later in this series ("selftests: net: cover
connected UDP reuseport rescore") only checks a CBPF program that selects
the connected socket. It never selects an unconnected peer, so it would not
catch this.
> +
> if (score > badness) {
> badness = score;
>
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794759652.git.zihanx%40nebusec.ai
next prev parent reply other threads:[~2026-11-19 9:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 3:55 [PATCH net 0/2] udp: fix connected reuseport rescore fallback Zihan Xi
2026-11-16 3:55 ` [PATCH net 1/2] udp: fix " Zihan Xi
2026-11-16 4:51 ` Alexei Starovoitov
2026-11-16 5:08 ` zihan xi
2026-11-19 9:57 ` netdev-bot+sashiko [this message]
2026-11-16 3:55 ` [PATCH net 2/2] selftests: net: cover connected UDP reuseport rescore Zihan Xi
2026-11-19 9:57 ` netdev-bot+sashiko
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=179508226205.3136.710014559426997072@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=benh@amazon.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=vega@nebusec.ai \
--cc=willemdebruijn.kernel@gmail.com \
--cc=zihanx@nebusec.ai \
/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