Article View: linux.kernel.netdev
Article #19349Re: [PATCH net-next v4 4/4] bpf: drop the stale dst when redirecting to an explicit nexthop
From: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 20:02
Date: Thu, 19 Nov 2026 20:02
153 lines
13846 bytes
13846 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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).
- [Medium] In the explicit-nexthop branch of __bpf_redirect_neigh_v4(),
the new skb_dst_drop_keep_metadata() call can replace a real struct…
- [Low] The patch fixes a long-standing, user-visible bug but has no
Fixes: tag and no Cc: stable.
--
bpf: drop the stale dst when redirecting to an explicit nexthop
This patch changes __bpf_redirect_neigh_v4() and __bpf_redirect_neigh_v6()
so they release the arrival dst through skb_dst_drop_keep_metadata() when
the BPF program supplies an explicit nexthop. Without it, a packet parked
on the target device's incomplete neighbour can later leave with the
original device's link-layer header. Encapsulation parameters carried by
the route are moved onto a metadata dst.
Link: https://lore.kernel.org/netdev/QDISC-6HS9.v3.r0.20261103062649-2@mojatatu.com/
Link: https://lore.kernel.org/netdev/avTfQjFQYR2NNdRg@chamomile/
> diff --git a/net/core/filter.c b/net/core/filter.c
> index bd98d29ed7f8f..ae5346d6abd23 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2318,6 +2318,8 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev,
> skb_dst_set(skb, dst);
> } else if (nh->nh_family != AF_INET6) {
> goto out_drop;
> + } else if (!skb_dst_drop_keep_metadata(skb)) {
> + goto out_drop;
> }
>
> err = bpf_out_neigh_v6(net, skb, dev, nh);
[Severity: Low]
Should this patch carry a Fixes: tag, and maybe Cc: stable?
The nh != NULL branch in __bpf_redirect_neigh_v4() and
__bpf_redirect_neigh_v6() skips the FIB lookup and keeps the incoming
dst. That branch appears to come from commit ba452c9e996d ("bpf: Fix
bpf_redirect_neigh helper api to support supplying nexthop"). Before that
commit, bpf_redirect_neigh() always did a FIB lookup on the target device
and installed the resulting route.
The commit message gives a reproducer that puts wrong addresses on the
wire. Would a tag like this one help stable trees that carry ba452c9e996d
pick up the fix?
Fixes: ba452c9e996d ("bpf: Fix bpf_redirect_neigh helper api to support supplying nexthop")
> @@ -2433,6 +2435,8 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev,
>
> skb_dst_drop(skb);
> skb_dst_set(skb, &rt->dst);
> + } else if (!skb_dst_drop_keep_metadata(skb)) {
> + goto out_drop;
> }
>
> err = bpf_out_neigh_v4(net, skb, dev, nh);
[Severity: Medium]
Can this pass a metadata_dst to code that still casts the skb dst to a
struct rtable?
Suppose the arrival route has lwtstate of type LWTUNNEL_ENCAP_IP,
LWTUNNEL_ENCAP_IP6 or LWTUNNEL_ENCAP_XFRM. Then
skb_dst_drop_keep_metadata() replaces the rtable with a METADATA_IP_TUNNEL
or METADATA_XFRM dst, and that dst uses dst_blackhole_ops:
net/core/dst.c:skb_dst_drop_keep_metadata() {
...
md_dst = metadata_dst_alloc(src->options_len,
METADATA_IP_TUNNEL, GFP_ATOMIC);
...
skb_dst_drop(skb);
if (md_dst)
skb_dst_set(skb, &md_dst->dst);
...
}
If the redirect target is a non-collect_md NBMA tunnel, its transmit path
still calls skb_rtable() on that dst. For an IPv4 payload with raddr set
to any:
net/ipv6/ip6_tunnel.c:ip6_tnl_xmit() {
...
} else if (payload_protocol == htons(ETH_P_IP)) {
const struct rtable *rt = skb_rtable(skb);
if (!rt)
goto tx_err_link_failure;
if (rt->rt_gw_family == AF_INET6)
memcpy(&fl6->daddr, &rt->rt_gw6, sizeof(fl6->daddr));
}
...
}
ip_tunnel_xmit() falls back the same way when skb_tunnel_info() gives no
usable AF_INET key dst. That covers METADATA_XFRM, an AF_INET6 key from
LWTUNNEL_ENCAP_IP6 on an IPv4 route, and a key.u.ipv4.dst of zero:
net/ipv4/ip_tunnel.c:ip_tunnel_xmit() {
...
} else if (payload_protocol == htons(ETH_P_IP)) {
rt = skb_rtable(skb);
dst = rt_nexthop(rt, inner_iph->daddr);
}
...
}
On 64-bit, rt_gw_family and rt_gw4/rt_gw6 land on the tun_info.key
address fields in the metadata_dst union. So rt_gw_family reads the first
byte of key.u.ipv4.src, and rt_gw6 starts at key.u.ipv4.dst.
Here is an example. An IPv4 route carries "encap ip ... src 10.x.x.x dst
D", and a tc egress program redirects with a supplied nexthop to an NBMA
ip4ip6 tunnel. Then rt_gw_family reads as 10, which is AF_INET6.
ip6_tnl_xmit() copies 16 bytes starting at key.u.ipv4.dst into
fl6->daddr, and the packet is encapsulated towards an outer IPv6 address
made of tunnel key bytes.
Before this patch the skb kept the real rtable on this path, so the cast
read real route fields.
The METADATA_XFRM layout does not seem to match AF_INET or AF_INET6.
IPv6 payloads coming from __bpf_redirect_neigh_v6() look like they are
dropped, because dst_blackhole_neigh_lookup() returns NULL. So this looks
limited to IPv4 payloads in the IP/IP6 encap case.
The commit message says:
The release here can leave one behind as well, when the parameters a
route carries are not usable for the payload. The cast is repaired
separately.
ip_tunnel_xmit() and ip6_tnl_xmit() are unchanged at this commit. Should
this patch go after the skb_rtable() fix, or include it? Otherwise this
path is exposed until that fix lands.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CORE-9NOG.v4.r0.20261116135311%40mojatatu.com
Technical Details
Message-ID:
<179511856597.3136.7846835490904436138@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.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-367301-linux-kernel-netdev=dewy.ruReferences:
<CORE-9NOG.v4.r0.20261116135311-4@mojatatu.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.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-367301-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v4 4/4] bpf: drop the stale dst when redirecting to an explicit nexthop Date: Thu, 19 Nov 2026 20:02:45 +0000 Organization: Usenet Network Message-ID: <179511856597.3136.7846835490904436138@kernel.org> References: <CORE-9NOG.v4.r0.20261116135311-4@mojatatu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2968163"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:y1mQf7f3hUCR6ewy2lQnfwc7Jgw= sha256:66G1w3HHuLcQZ8yEBFkiGbnnzsl1KiNkrRa4V+sqE08= sha1:dXaI0Fg8NhIgsNiTEQ1R/4q2Y9s= sha256:VvvGDcqoeU73aww3yQhHQAo54dFMbUUTtVovRN8q1dc= 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 F3CA9115760; Thu, 19 Nov 2026 23:03:04 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.5 X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[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 ibP5mhFo_FYq; Thu, 19 Nov 2026 23:03:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-367301-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 21F3611573C; Thu, 19 Nov 2026 23:02:50 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 23B206C399A; Thu, 19 Nov 2026 20:02:50 +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=1795118568; b=R35OdpSZefCg2iKAlV712g50golKD2RHC8SK+Ujtv9ksLWu4bPkQJvpa53g81CHGFXm/ pG7TCU/Ia+rWbNjmnxW/tRj3dBTTwiz2OhNDXvX00mKRGd7nqM9ZZGcv4xPY+zHebDq02 XuAuInRYg6vzSjUGhWu2LlFPC40r/qmANoMyFNRHomdxrMCKmP73bgTSabjjQ4B5yHJxb j6JHzZhz+GykZFrg1Y4YPvYWNHhUyyxbl3do9gmjW3zzdrIPkkfF7462m1HYIGsW3Xmsb ci8MCRXJ9SLtgKlwVZ3cvfgFq7AFwy6vbvuQ40UZl0NrI39K8AP9nTzPwaZq+UAzC7w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795118568; 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=RKK0OI96pECkHppROmIdESDMy4NSloW0JuhxhC44a4A=; b=ECeSPhr/aElpljrhhoNP3xT24NTFMpRw9CxhCTW21a8wKiXCwvm2oziAETrhfw0QXo64 bCxDlqumV+ZDziFwpqOXV4S2tbeVv2TwvMlMTHvQ+AtzqlyUqOQO9TimAyyCyu3hVCIFa go1kBkGe8oWSGWHgL8mLkcQMaI3U1d9Y5DhPli5dNq01FtvDhB42A5/OHfH3f8quPARSL 2QDTwo+bJqrighkQ1ckXutXjgL43yRfIXcz9e4tifoNlwKwLi3JIkAHMSr6ZkKSeySMWR dG1UtXq1aJ7YMA42YiGwOAuLpQGkDH8YyWcAn/KsFQEINzQ4MPtA3ZKYDwGNB9wKoDA== 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=PpH7DsWN; 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 C0AF0606A336; Thu, 19 Nov 2026 20:02:48 +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=PpH7DsWN 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=1795118568; b=tzySdFuYWzmJ8oD5G3Hh9AFMmr4CWStu1fpqhoUjA0xdKFsUdTt9A80F5rbLHukeslTB /oGKrbIjTS/vFyR77OD/6KvHrrHvAHIv8+mC2xDSPsCPjed5vo55Jizqm9vHJUNwm++Lb 7y6b+gLrHxjy/lRQOlIvtrxTa/PEoZ1XnGkojtcEVcw2ESAGEeais4P4yPaPorjtOHcgw ibFXjaoVNsYcPSbP5j3Ttpid7gBQbgkxJetm2elmoPRJZiM5cPtrk6Q0uJMMo9wimVU0i C4AR6f/PRiHvYhaodR7OJhkN1j88loEGb0WchP++69tRTSE6HJG1oN0d7lOKygmZgcw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795118568; 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=RKK0OI96pECkHppROmIdESDMy4NSloW0JuhxhC44a4A=; b=joWzqAMuDv3sCA9XffJ+1RY5nBGXEA89Z7bMRHiuSNc6B84JnWmS0dmUBgfYRQTQrgBK 1S/O4iPrWi/xhPk9xZ27aiZSu4MOBh354gaKchRcWPA89ioOatBuLC04qs6lhV4RNGxsI YrM/F0wKROVmwXzNfM6TJrUdBa8qpensoNaOy3Mc8j6OJlljjLz/ANorxOShEC1+W1MLW Aj3hur5hapacmkw8SoBlNfB912HJnKYUpHTcrviam/ncc2S20ulndV96UpebtdY4FMnKA 4gFGZY0UL5IKUU9Cl+k9W4eqDbhR00O/ohGs6N7BwRLJjAXgi8Pj8PXzdbwRnKbStyA== 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=PpH7DsWN; 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 E09C2606A332; Thu, 19 Nov 2026 20:02:47 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62C9D1F000C7; Thu, 19 Nov 2026 20:02:46 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795118567; bh=RKK0OI96pECkHppROmIdESDMy4NSloW0JuhxhC44a4A=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=PpH7DsWNKZZ5nDxLnHjF/22h6Rz55sVIj+y3RERJctzTeuY3SOwzt11Ct10nU6qbH HcxcPbjuGTh3gK9vCn3g7/BLeJVspYOvxE5j1gsVGCHyiP1Om1UT8IE+Bo6u5T5KFb KBfFMsWRuKIfcUsizdCPgpJh4oSR4fxCa+OntDcPhz0YIcaH3vdl6ujfzhgXXDyHoj XfdA7QMIE/T3ZetULJxEESYQThEO1iv/kOFhDno1uF55cI3IRxnFY2aLkN9Lwz6Bcu rL8Oa07Oxvy24cRTiDMZGrFQDNFSUhG3qw0P0wpyEBN+oQ7lnPwvHsCAz9eAZbpthW zV3YE5OI5MXUA== X-Cc: netdev@vger.kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, sdf@fomichev.me, martin.lau@linux.dev, ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, bpf@vger.kernel.org, jiri@resnulli.us, victor@mojatatu.com, sashiko-bot@kernel.org X-In-Reply-To: <CORE-9NOG.v4.r0.20261116135311-4@mojatatu.com> X-sashiko-severity: Medium 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