From: Ralf Lici <ralf@mandelbit.com>
To: netdev-bot+sashiko@kernel.org
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, sd@queasysnail.net,
antonio@mandelbit.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v3 3/3] ipv6: use lookup cookies in selected socket dst cache paths
Date: Thu, 19 Nov 2026 13:34:50 +0100 [thread overview]
Message-ID: <20261119123451.419865-1-ralf@mandelbit.com> (raw)
In-Reply-To: <179508017589.3136.2311893930440004501@kernel.org>
On Thu, 19 Nov 2026 09:22:55 +0000, netdev-bot+sashiko@kernel.org wrote:
> ipv6: use lookup cookies in selected socket dst cache paths
>
> This commit changes tcp_v6_connect(), ip6_datagram_dst_update() and
> ip6_sk_dst_lookup_flow(). They now store the cookie returned by
> ip6_dst_lookup_flow_cookie() instead of sampling it after the lookup.
> The commit also adds ip6_dst_store_cookie() and keeps ip6_dst_store() as
> a wrapper for callers that are not converted yet.
>
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>
> [Severity: Low]
> This patch depends on the earlier commit "ipv6: add
> ip6_dst_lookup_flow_cookie". That commit does three things:
>
> - adds ip6_dst_lookup_flow_cookie()
> - changes ip6_dst_check() so that a dst with rt->sernum must match the
> supplied cookie
> - moves the fib6_update_sernum() calls in fib6_ifup()/fib6_ifdown() to
> after rt6_multipath_rebalance()
>
> The prerequisite has no Fixes: tag and no stable note. This commit does
> not mention the dependency either.
>
> If stable selection picks only this commit because of its Fixes: tag, it
> will not build, since ip6_dst_lookup_flow_cookie() is undefined. Could the
> prerequisite be tagged too, or the dependency be noted here, so both get
> backported together?
>
Since this targets net-next and I'm not asking for a backport, I'll drop
the Fixes tag from this patch in the next revision.
> > diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
> > index 95f936be32c6c..2684f6069a5e1 100644
> > --- a/include/net/ip6_route.h
> > +++ b/include/net/ip6_route.h
>
> [ ... ]
>
> > @@ -266,8 +266,16 @@ static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
> > #endif
> > }
> >
> > +static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
> > + bool daddr_set,
> > + bool saddr_set)
> > +{
> > + ip6_dst_store_cookie(sk, dst, rt6_get_cookie(dst_rt6_info(dst)),
> > + daddr_set, saddr_set);
> > +}
>
> [Severity: High]
> This wrapper still samples the cookie after the lookup. Three other
> writers of np->dst_cookie on TCPv6 sockets still go through it:
>
> net/ipv6/inet6_connection_sock.c:inet6_csk_route_socket() {
> ...
> dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
>
> if (!IS_ERR(dst))
> ip6_dst_store(sk, dst, false, false);
> ...
> }
>
> net/ipv6/af_inet6.c:inet6_sk_rebuild_header() {
> ...
> dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
> ...
> ip6_dst_store(sk, dst, false, false);
> ...
> }
>
> net/ipv6/tcp_ipv6.c:tcp_v6_syn_recv_sock() {
> ...
> memcpy(newnp, np, sizeof(struct ipv6_pinfo));
>
> ip6_dst_store(newsk, dst, false, false);
> ...
> }
>
> Can the same xfrm policy bypass still happen through these paths?
>
> xfrm_policy_insert() links the policy and then calls
> rt_genid_bump_ipv6(). Suppose an insertion lands between
> ip6_dst_lookup_flow() returning a plain route and the rt6_get_cookie()
> call inside ip6_dst_store(). The plain dst is then cached with the new
> serial, and ip6_dst_check() keeps accepting it.
>
> These paths run much more often than tcp_v6_connect():
>
> - After connect(), every refill for an established socket goes through
> inet6_csk_xmit()->inet6_csk_route_socket() whenever __sk_dst_check()
> fails. That includes the invalidation caused by the policy insertion
> itself.
> - A remote ICMPv6 Packet Too Big can force refills via
> tcp_v6_mtu_reduced()->inet6_csk_update_pmtu()->inet6_csk_route_socket().
> - For accepted sockets, tcp_v6_syn_recv_sock() reads the cookie only
> after inet6_csk_route_req(), tcp_create_openreq_child() and the
> ipv6_pinfo memcpy. That window is wider than the one in connect().
>
> The commit message says this is a partial conversion. With the Fixes:
> tag, though, stable trees would get a fix that leaves established active
> sockets and all accepted sockets exposed. The new kernel-doc for
> ip6_dst_lookup_flow_cookie() also says "A caller caching the dst should
> use this cookie when validating it with dst_check". These callers don't
> do that.
>
> Would it make sense to convert inet6_csk_route_socket(),
> inet6_sk_rebuild_header() and tcp_v6_syn_recv_sock() in this patch as
> well?
>
This is the same point as on v2: the partial conversion is deliberate
and stated in the cover letter and in this commit message.
That said, these are the only remaining ip6_dst_store users. Converting
them would let me drop the late-sampling wrapper, so every write to
np->dst_cookie would use a lookup cookie. inet6_csk_route_socket and
inet6_sk_rebuild_header are direct conversions. tcp_v6_syn_recv_sock
needs the cookie to follow the dst that Fast Open passes in from
tcp_conn_request.
David, Ido, would you prefer this series to cover all ip6_dst_store
users, or to keep the current three paths and convert the rest along
with the other cache users in a follow-up? I'll respin accordingly.
The next revision will also include the small changes from this round: a
note in 1/3 that the generation advances once per ip6_link_failure call,
a wider comment for rt6_exception_net, the narrowed kdoc and the barrier
pairing comments in 2/3.
--
Ralf Lici
Mandelbit Srl
prev parent reply other threads:[~2026-11-19 12:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 9:21 [PATCH net-next v3 0/3] ipv6: tie the dst cookie to the lookup that returned the dst Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 1/3] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
2026-11-19 9:22 ` netdev-bot+sashiko
2026-11-17 9:21 ` [PATCH net-next v3 2/3] ipv6: add ip6_dst_lookup_flow_cookie Ralf Lici
2026-11-18 8:48 ` Xia Yan
2026-11-18 14:39 ` Ralf Lici
2026-11-18 15:07 ` Xia Yan
2026-11-19 9:22 ` netdev-bot+sashiko
2026-11-19 12:31 ` Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 3/3] ipv6: use lookup cookies in selected socket dst cache paths Ralf Lici
2026-11-19 9:22 ` netdev-bot+sashiko
2026-11-19 12:34 ` Ralf Lici [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=20261119123451.419865-1-ralf@mandelbit.com \
--to=ralf@mandelbit.com \
--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-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sd@queasysnail.net \
--cc=steffen.klassert@secunet.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
all inboxes | Powered by JetHome®