BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zihan Xi" <zihanx@nebusec.ai>, bpf@vger.kernel.org
Subject: Re: [PATCH net 1/2] udp: fix reuseport rescore fallback
Date: Tue, 17 Nov 2026 03:55:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-218170@kernel.org> (raw)
In-Reply-To: <8c46325c4a433f02fdc7241c0c3884126cb502af.1794759652.git.zihanx@nebusec.ai>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] udp: score > badness check on rescore breaks SO_REUSEPORT
  selection
--

commit ab974582f7bf280a71fe95ae3563909536a788c1
Author: Zihan Xi <zihanx@nebusec.ai>

udp: fix reuseport rescore fallback

This commit updates udp4_lib_lookup2() and udp6_lib_lookup2() to fall back
to the current candidate socket sk when a socket selected from a reuseport
group with connected sockets does not score higher on rescore.

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;
> +		}
> +
>  		if (score > badness) {
>  			badness = score;
>  
> -			if (need_rescore)
> -				continue;
> -
>  			if (sk->sk_state == TCP_ESTABLISHED) {
>  				result = sk;
>  				continue;
> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index 9dcefa1625223..c5adeaaf5b428 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -234,12 +234,17 @@ static struct sock *udp6_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;
> +		}
> +
>  		if (score > badness) {
>  			badness = score;
>  
> -			if (need_rescore)
> -				continue;
> -
>  			if (sk->sk_state == TCP_ESTABLISHED) {
>  				result = sk;
>  				continue;

[Severity: High]
Does checking score > badness when need_rescore is true discard the socket
selected by reuseport whenever it has the same score as sk?

Before jumping to rescore, udp4_lib_lookup2() and udp6_lib_lookup2()
already set badness = score for sk.  When reuseport_has_conns(sk) is true
and inet_lookup_reuseport() or inet6_lookup_reuseport() selects another
unconnected socket in the group with an equal score, score == badness on
the rescore pass.  The strict score > badness check then takes the else
branch (result = sk), regressing efc6b6f6c311 ("udp: Improve load
balancing for SO_REUSEPORT.") by delivering all traffic for unconnected
sockets in the group to the first matching socket in hslot2->head.

Checking score >= badness in the need_rescore block would keep result when
it scores at least as well as sk while still falling back to sk when
result scores lower.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794759652.git.zihanx@nebusec.ai?part=1

  parent reply	other threads:[~2026-11-17  3:55 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-17  3:55   ` sashiko-bot [this message]
2026-11-16  3:55 ` [PATCH net 2/2] selftests: net: cover connected UDP reuseport rescore Zihan Xi
2026-11-17  3:55   ` sashiko-bot

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=sashiko-outbox-218170@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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