From: netdev-bot+sashiko@kernel.org
To: jhs@mojatatu.com
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
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 [thread overview]
Message-ID: <179511856597.3136.7846835490904436138@kernel.org> (raw)
In-Reply-To: <CORE-9NOG.v4.r0.20261116135311-4@mojatatu.com>
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
next prev parent reply other threads:[~2026-11-19 20:02 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 19:01 [PATCH net-next v4 0/4] net: drop the stale dst when steering to another device Jamal Hadi Salim
2026-11-16 19:01 ` [PATCH net-next v4 1/4] net: xfrm: interface: restore dst_orig on every xfrm interface Jamal Hadi Salim
2026-11-17 19:02 ` sashiko-bot
2026-11-19 20:02 ` netdev-bot+sashiko
2026-11-16 19:01 ` [PATCH net-next v4 2/4] net: dst: keep the LWT metadata of a dropped route Jamal Hadi Salim
2026-11-19 20:02 ` netdev-bot+sashiko
2026-11-16 19:01 ` [PATCH net-next v4 3/4] netfilter: nft_fwd_netdev: drop the stale dst when steering to a device Jamal Hadi Salim
2026-11-17 19:02 ` sashiko-bot
2026-11-19 20:02 ` netdev-bot+sashiko
2026-11-16 19:01 ` [PATCH net-next v4 4/4] bpf: drop the stale dst when redirecting to an explicit nexthop Jamal Hadi Salim
2026-11-16 20:46 ` Alexei Starovoitov
2026-11-16 22:06 ` Jamal Hadi Salim
2026-11-17 4:50 ` Alexei Starovoitov
2026-11-17 13:15 ` Jamal Hadi Salim
2026-11-17 14:00 ` Jamal Hadi Salim
2026-11-17 19:02 ` sashiko-bot
2026-11-19 20:02 ` netdev-bot+sashiko [this message]
2026-11-19 20:29 ` Jamal Hadi Salim
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=179511856597.3136.7846835490904436138@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=victor@mojatatu.com \
--cc=yonghong.song@linux.dev \
/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