Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: ralf@mandelbit.com
Cc: netdev@vger.kernel.org, dsahern@kernel.org, idosch@nvidia.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, ncardwell@google.com,
	kuniyu@google.com, steffen.klassert@secunet.com,
	herbert@gondor.apana.org.au, fw@strlen.de,
	yanxia@cmss.chinamobile.com, sd@queasysnail.net,
	antonio@mandelbit.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v4 3/5] ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check
Date: Tue, 24 Nov 2026 10:26:52 +0000	[thread overview]
Message-ID: <179551601267.3135.12313397782341117829@kernel.org> (raw)
In-Reply-To: <5409c8c2f60cdc4816a57adf841934688a5a010d.1795166508.git.ralf@mandelbit.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] In net/ipv6/route.c, ip6_dst_check() (lines 2821-2822) now
  returns a nexthop-object per-CPU dst (rt->sernum != 0) only if `cookie…

--

ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check

This patch makes ip6_dst_check() compare the cookie passed by the caller
with rt->sernum for dsts of nexthop-object routes. Before, it only checked
rt->sernum against the current IPv6 generation. The commit message says
existing callers are unaffected because rt6_get_cookie() returns
rt->sernum for these dsts.

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 98e3ca0644ab9..4c02c5168163c 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -2819,7 +2819,7 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
>  	rt = dst_rt6_info(dst);
>  
>  	if (rt->sernum)
> -		return rt6_is_valid(rt) ? dst : NULL;
> +		return (rt6_is_valid(rt) && cookie == rt->sernum) ? dst : NULL;

[Severity: Low]
Is "their validation is unchanged" true for the IPv6 UDP rx dst cache?
Until now the cookie was ignored for these dsts, so a cached dst and its
cookie could come from different lookups without any effect. With this
check they have to match.

In udp6_sk_rx_dst_set(), the dst and the cookie are written separately:

net/ipv6/udp.c:udp6_sk_rx_dst_set() {
	if (udp_sk_rx_dst_set(sk, dst))
		sk->sk_rx_dst_cookie = rt6_get_cookie(dst_rt6_info(dst));
}

udp_sk_rx_dst_set() updates only the pointer, using xchg(). Nothing
serializes softirq writers running on different CPUs, so this ordering
looks possible:

CPU A
  xchg(sk_rx_dst, dst1)            dst1->sernum == g1
                                   IPv6 generation moves to g2
CPU B
  xchg(sk_rx_dst, dst2)            dst2->sernum == g2
  sk_rx_dst_cookie = g2
CPU A
  sk_rx_dst_cookie = g1

The socket now holds dst2 with cookie g1. After that, every call to
udp_v6_early_demux() fails:

    dst = dst_check(dst, sk->sk_rx_dst_cookie);

rt6_is_valid(dst2) is true, but g1 != g2. udp_v6_early_demux() does not
clear sk_rx_dst when this check fails.

The full input lookup on CPU B then returns the same per-CPU dst2. So in
__udp6_lib_rcv() this condition is false:

		if (unlikely(rcu_dereference(sk->sk_rx_dst) != dst))
			udp6_sk_rx_dst_set(sk, dst);

That means the stale cookie is never corrected.

Could this leave early demux disabled for that socket on that CPU? Each
packet would pay for a full FIB lookup until the generation advances again
or a packet arrives on a CPU with a different per-CPU dst.

The window between the xchg() and the cookie store is short, but a hardirq
can stretch it. On PREEMPT_RT, softirqs run in threads, so preemption can
too. Later patches in the series do not touch this UDP rx path.

ip6_dst_store() has a similar split-store pattern. There, a failed
sk_dst_check() resets the cache, so it recovers. TCP rx dst writers are
serialized by the socket lock, so any mismatch there is only transient.

>  
>  	rcu_read_lock();
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795166508.git.ralf%40mandelbit.com

  reply	other threads:[~2026-11-24 10:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:36 [PATCH net-next v4 0/5] ipv6: tie the dst cookie to the lookup that returned the dst Ralf Lici
2026-11-20  9:36 ` [PATCH net-next v4 1/5] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
2026-11-24 10:26   ` netdev-bot+sashiko
2026-11-20  9:36 ` [PATCH net-next v4 2/5] ipv6: advance the serial after rebalancing in fib6_ifup and fib6_ifdown Ralf Lici
2026-11-20  9:36 ` [PATCH net-next v4 3/5] ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check Ralf Lici
2026-11-24 10:26   ` netdev-bot+sashiko [this message]
2026-11-20  9:36 ` [PATCH net-next v4 4/5] ipv6: add ip6_dst_lookup_flow_cookie Ralf Lici
2026-11-24 10:26   ` netdev-bot+sashiko
2026-11-20  9:36 ` [PATCH net-next v4 5/5] ipv6: use lookup cookies in selected socket dst cache paths Ralf Lici

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=179551601267.3135.12313397782341117829@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=antonio@mandelbit.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ralf@mandelbit.com \
    --cc=sd@queasysnail.net \
    --cc=steffen.klassert@secunet.com \
    --cc=yanxia@cmss.chinamobile.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