Article View: linux.kernel.netdev
Article #21702Re: [PATCH net-next v4 4/5] ipv6: add ip6_dst_lookup_flow_cookie
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 10:26
Date: Tue, 24 Nov 2026 10:26
211 lines
15519 bytes
15519 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 2 · 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] ip6_dst_lookup_flow_cookie() (net/ipv6/ip6_output.c) only closes
the lookup/cookie race when the returned dst is a plain route.
- [High] The generation check in ip6_dst_lookup_flow_cookie() is only
sound if every writer publishes its full routing/policy change before…
--
ipv6: add ip6_dst_lookup_flow_cookie
This adds ip6_dst_lookup_flow_cookie(). Like ip6_dst_lookup_flow(), it
does the route and xfrm policy lookup, and it also returns the dst
validation cookie. The cookie is sampled between two reads of the IPv6
generation and forced to 0 if the generation changed. A comment is also
added to fib6_new_sernum() describing the writer side ordering that the
helper relies on.
> diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
> index e1d49897d6ab0..1915d31136d65 100644
> --- a/net/ipv6/ip6_fib.c
> +++ b/net/ipv6/ip6_fib.c
> @@ -123,6 +123,10 @@ static void fib6_walkers_skip_rt(struct net *net, struct fib6_info *rt)
> fib6_walkers_replace_leaf(net, rt, next);
> }
>
> +/* The successful atomic_try_cmpxchg is fully ordered: it publishes the
> + * routing change before the new generation, and the new generation before
> + * the nodes stamped with it. ip6_dst_lookup_flow_cookie relies on both.
> + */
[Severity: High]
Does xfrm_policy_insert() follow this ordering when it replaces an
existing policy (excl == 0)?
In xfrm_policy_insert(), the IPv6 generation is advanced before the
replaced policy is unlinked:
net/xfrm/xfrm_policy.c:xfrm_policy_insert() {
...
__xfrm_policy_link(policy, dir);
...
else
rt_genid_bump_ipv6(net);
if (delpol) {
xfrm_policy_requeue(delpol, policy);
__xfrm_policy_unlink(delpol, dir);
}
...
}
Nothing advances the generation after the unlink. xfrm_policy_kill(delpol)
only does atomic_inc(&policy->genid), and that only affects bundles.
Suppose the new policy has a larger priority value than the old one, and
a later entry in the chain has priority <= the new priority. Then
xfrm_policy_insert_list() links the new policy behind that entry, which
puts it after the old policy. During this window, xfrm_policy_lookup_bytype()
takes the first match, so it keeps selecting the old policy.
Can this sequence happen?
CPU2 xfrm_policy_insert() CPU1 ip6_dst_lookup_flow_cookie()
__xfrm_policy_link(P_new)
rt_genid_bump_ipv6() /* G+1 */
gen0 = G+1
xfrm_lookup() matches P_old
(allow, no templates), returns
dst_orig untransformed
*cookie = rt6_get_cookie(rt) = G+1
gen1 = G+1, cookie is kept
__xfrm_policy_unlink(P_old)
The socket's cached plain route would then keep passing ip6_dst_check().
Traffic would go out in plaintext even though P_new requires IPsec or
blocks the flow. This lasts until an unrelated IPv6 generation change.
The following patch, "ipv6: use lookup cookies in selected socket dst
cache paths", relies on lookup cookies to prevent this kind of plaintext
bypass. No later patch in the series changes xfrm_policy_insert().
> diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
> index 3cc911f6618e7..083ffdc8f4046 100644
> --- a/net/ipv6/ip6_output.c
> +++ b/net/ipv6/ip6_output.c
[ ... ]
> @@ -1300,6 +1299,60 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, st
> }
> EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
>
[ ... ]
> +struct dst_entry *ip6_dst_lookup_flow_cookie(struct net *net,
> + const struct sock *sk,
> + struct flowi6 *fl6,
> + const struct in6_addr *final_dst,
> + u32 *cookie)
> +{
> + const struct rt6_info *rt;
> + struct dst_entry *dst;
> + int gen0, gen1;
> +
> + gen0 = rt_genid_ipv6(net);
> + /* read the generation before looking at the FIB or xfrm policies,
> + * pairs with the full barrier in fib6_new_sernum
> + */
> + smp_rmb();
> +
> + dst = ip6_dst_lookup_flow(net, sk, fl6, final_dst);
> + if (IS_ERR(dst))
> + return dst;
> +
> + rt = dst_rt6_info(dst);
> + *cookie = rt->sernum ? gen0 : rt6_get_cookie(rt);
> +
> + /* keep the FIB and cookie reads before the final generation read,
> + * pairs with the full barrier in fib6_new_sernum
> + */
> + smp_rmb();
> + gen1 = rt_genid_ipv6(net);
> + if (unlikely(gen0 != gen1))
> + *cookie = 0;
[Severity: High]
If ip6_dst_lookup_flow() returns an xfrm bundle, does zeroing the cookie
here change anything?
xfrm_dst_check() never reads the cookie:
net/xfrm/xfrm_policy.c:xfrm_dst_check() {
...
if (READ_ONCE(dst->obsolete) < 0 && !stale_bundle(dst))
return dst;
...
}
xfrm_bundle_ok() checks only dst_check(path, path_cookie) and
dst_check(xdst->route, route_cookie), plus the policy and state genids.
Those two cookies are sampled with rt6_get_cookie() after the route and
policy lookups, which is inside the gen0..gen1 window. That is the same
late sampling that the commit message describes as the bug:
net/ipv6/xfrm6_policy.c:xfrm6_fill_dst() {
...
xdst->route_cookie = rt6_get_cookie(rt);
...
}
net/xfrm/xfrm_policy.c:xfrm_init_path() {
...
path->path_cookie = rt6_get_cookie(dst_rt6_info(dst));
...
}
Could this interleaving occur?
1. A reader (tcp_v6_connect(), ip6_datagram_dst_update() or
ip6_sk_dst_lookup_flow() after the following patch) reads gen0 = G,
looks up route R, and xfrm_lookup() selects the existing policy P_old.
2. A higher precedence policy P_new with a different selector is
inserted, so P_old is not killed and its genid does not change.
xfrm_policy_insert() calls rt_genid_bump_ipv6() -> fib6_flush_trees(),
which sets fib6_sernum to G+1 and stamps every node with G+1.
3. The reader's xfrm_bundle_create() then reads route_cookie and
path_cookie as G+1.
4. Since gen1 != gen0, *cookie is set to 0, but the bundle ignores it.
The socket caches the bundle. Later dst_check() calls pass because
fn_sernum is G+1 and P_old->genid has not changed.
The flow would keep using P_old until some unrelated generation change.
That means the old tunnel or SA stays in use, even if P_new is a block
policy. A concurrent fib6_add() of a more specific route could pair the
old xdst->route with a new serial in the same way.
The commit message says:
xfrm bundles retain their existing validation through their own route
and path cookies.
That validation depends on the same racy sampling this patch is meant to
fix. The cookie value alone cannot invalidate a bundle, so does the
gen0 != gen1 case need something more? For example, a result telling the
caller not to cache the dst, or marking the bundle obsolete.
> +
> + return dst;
> +}
> +EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow_cookie);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795166508.git.ralf%40mandelbit.com
Technical Details
Message-ID:
<179551601473.3135.7741252633833955764@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370233-linux-kernel-netdev=dewy.ruReferences:
<65536a8e6733b8fb94614de2e104548a921a52dd.1795166508.git.ralf@mandelbit.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370233-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v4 4/5] ipv6: add ip6_dst_lookup_flow_cookie Date: Tue, 24 Nov 2026 10:26:54 +0000 Organization: Usenet Network Message-ID: <179551601473.3135.7741252633833955764@kernel.org> References: <65536a8e6733b8fb94614de2e104548a921a52dd.1795166508.git.ralf@mandelbit.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="4111598"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:2kMxtJ0SauRv+qLy7eNs0C1zi4A= sha256:SAzsWwm5U8Dqe36YlWfZD5rHKTmsuYc6H+W2Lcgpuq8= sha1:q763qFiSITN+khFNQAM4S070blk= sha256:WzMpOpvm/R5QmyE8Hr5S3S6WN32G/PlkxQm+QgMmlac= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 3E956125DEF; Tue, 24 Nov 2026 13:27:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aRzzhOm-tNoE; Tue, 24 Nov 2026 13:27:11 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-370233-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id DE188125DF3; Tue, 24 Nov 2026 13:27:02 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 445692C10D; Tue, 24 Nov 2026 10:27:00 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795516017; b=U1rlTyQdRRa6zwZTH5Sm6+YflCqHdzC6Mgb3BkHFKvTf8mIY9W3j+wZknQtpRgczncsY aaO2g29/zT0zGSQY4YXe4TzupzWkuOMyRbALbCDQZ2Pw9gn2X1RvR1C0unw0JkfLpJp95 DbcQILVjWQnHNGhgxg0Ndk+UumVQXDAwXNaOgmEvYLdVn6wAJTzRHK2ZRbYM9P+MPodgt YxvoUtmW5ECnyoDc+SCeaRQvk5oZE0HVq1PXlrnXgD6Jqevwz4sxrKcpcMCuWZdXT7YtJ YxeuT1GMBu/b1oXnpcba52yWbfA8y6W/ROo4w0025Sb4mtAKUV62gE0bIE+1FHn/nnw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795516017; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=RR8/wx+Bi2pUf4daCstWfkjJ5lPJfN0XHQOGHvFDzXg=; b=G2Q1OIj5xrnkC13E8RZINpzPx4y7ZvGSlmNOn/i2wy2WbteylWk/52x4KkMoE3fxRnQi mlmWfEVwQd17tF33mNPd7dQQkPTy3K9AIzRbTM1aQxNaj238SEKc7/OlW0jRdBW5YUGuz s6bzUkUXazamQFqFRRFBFg2zcEgue5RRhb2K65azH5c2McjCQycfn06QlVdzsxtXf7fmi oZOUWxtsS4I6rx0glf1sDroBQe1sb8AabqdSq2Qslwp5efr335mhDntfChGi/9gc/B547 vwQ1+/HCSeWsjJ6KyrUdl+EIwEoBDOgT4lkIlUzDsPq6zN274QibLDbkD1Ob6e4BSPQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=exRdq0Np; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D19E5606A681; Tue, 24 Nov 2026 10:26:57 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=exRdq0Np X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795516017; b=Cr+cClyecPfHZ5ct4sRpn9EMBiKDKlvgkIg8c0muV+nThxm3/tjzxXCDCiU+5OvUm61S x94IdE9N4WeiRM/zZnxcxxwi+0/SwfEssUxmwPDclYP9jFzFEs94vAallCMUs0+kj4lEy DTnGfk5f6wUMm2h9Dxc9RQKRQ9GKgvdCB08B36nwRs246j0bjGX/xFLoGFs25jfBkcw4A oGhipwXwbWLxm0zVYZveuS2JQ+EPvlZ9eDmHm48JEpSo4zdh3yGaZQjpUChtA/JMh2rQT x2gABHsZGGmOCmMMF+AnlDyuDG9Xy4F1ySk/fwf9dU5p9C+CL5IxtPD2E1HITXzoShQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795516017; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=RR8/wx+Bi2pUf4daCstWfkjJ5lPJfN0XHQOGHvFDzXg=; b=p9/jAXQDrvcqBur5p6diiB55FODJcWdVWx92y1KD6gnw1smrSOuO4EB4R5ZCPEfBDJgK JzdciH4fxMOZfIT0ehEN4Y4Q7e3byYKKGnkusCknEL1LVM82KD4umR8dFnAMb4DMxTXmq d5bUB9BmJM/8QWFGAo5z9NSCH1MCw9hz7T4af45enni1VkJWBEV0vosts3yj0yBUGgubB hst2mV0h5j8cZ0OH1KpG+cMM+jN5REk+X2vHm/+DQAKVCQxcVQ0Y1I7lckMd+3BV+y7gO ga0l3awtrCOTtCBKEPTgfXmvraJaC961DhUNgIOfXok4kdp/4Sk6Z6p14fSPE8lbhow== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=exRdq0Np; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F23BC606A338; Tue, 24 Nov 2026 10:26:56 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28E0A1F000D4; Tue, 24 Nov 2026 10:26:55 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795516016; bh=RR8/wx+Bi2pUf4daCstWfkjJ5lPJfN0XHQOGHvFDzXg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=exRdq0NpUtTmSkH8QoKpDdNaVH6lsM0El6Ttqg0SNtTQMvjtCrIILilab84hkuaZH PXLw/J9LZQYCO8dXgxjqmxLMJ0epOmuzOnIakEjNCV4cvw5TRWTQTGiA+N5XTI6PmU 03B+U8jQrB+LxocxKVvnx5Dyf0QExnc3I+Fi2W0672L/YvsE9S/1cI+f17+Pb83Lf8 WQMvJRLv8+v3HKNCIyCoPIjad2yJbXWzTAqKJG4O5maZXBQKtZNpmfhAY9QlLdFn9G TgkHwd9YGy4Y71DjSIhz+1NYhXb7Sq5Mes/pZgykyhMSLXgzW+RggkKm8g5nkjaeOc 05xRorL4PtWRg== X-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 X-In-Reply-To: <65536a8e6733b8fb94614de2e104548a921a52dd.1795166508.git.ralf@mandelbit.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list