net: drop the stale dst when steering to another device
Subsystems (6)
v3 cover net: drop the stale dst when steering to another device
This patchset is created to address constant whining by both sashikos about this being an issue when fixing a UAF on a teql issue, see:
https://lore.kernel.org/netdev/[email protected]/
Two producers steer a packet to a network device of their choosing and then hand it to the neighbour layer for link-layer resolution:
3/4 netfilter: the neighbour variant of nft fwd, on the netdev egress
hook
4/4 bpf: bpf_redirect_neigh() when the program supplies the nexthop
Both rewrite skb->dev to the target device and leave the skb's dst pointing at the route the packet arrived through. When the target device's neighbour for the nexthop is incomplete the packet is parked on that neighbour's arp_queue, and draining the queue re-looks the neighbour up from the stale dst. The frame is therefore built with the original device's link-layer header and then transmitted on the target device: the packet leaves with another device's addresses, and the sender never learns that its nexthop was unreachable.
This is explicit: the steer-to-another-device path never worked in this respect, so there is nothing here to regress. Both producers shipped with skb->dev swapped to the target device and the route's dst still attached, and the arp_queue drain has re-derived the neighbour from that dst for as long as either producer has existed; the invariant "the skb's dst describes where the skb is going", which the routing path keeps when it steers, was never established for these two entry points. With no commit to anchor with a Fixes: tag and no crash, UAF or lockup involved, the series targets net-next and does not nominate Cc: stable:
a backport would change long-standing redirect behaviour for no crash-class benefit.
More context: this came out of the review of the fix for a parked skb being resolved against the wrong device in sch_teql, posted separately and not part of this series. The neighbour code's queue drain is doing the right thing there, it re-derives the neighbour from the skb, so the repair belongs with the producers rather than with the drain path. Both producers are fixed in the same series so neither is left behind; each patch that changes a producer carries its own reproduction recipe.
The reproduction for both arms is a pair of veth devices, one of them with an unresolved neighbour, plus a capture on the target's peer: the captured frame's source and destination addresses name the device whose neighbour was used to build it.
v2 drops the dst only when it describes a route, and keeps what the route carries (thanks to Pablo for catching this). A DST_METADATA dst is the tunnel template a tunnel helper attached to the packet, not a route, and dropping it would discard the encapsulation parameters, so it is left in place. A route carries encapsulation parameters too when it was installed with an ip, ip6 or xfrm encapsulation; 2/4 adds a helper that moves them onto a metadata dst before the route is released, so a producer that steers into an external tunnel device still finds them in skb_tunnel_info(), and one that steers into a collect_md xfrm interface still finds its if_id and underlying device. Neither case weakens the fix:
a metadata dst resolves neighbours through dst_blackhole_ops, whose lookup returns NULL, so the queue drain keeps the parking (target-device) neighbour exactly as it does with no dst at all.
1/4 is a prerequisite on the xfrm path turned up after Pablo's comment. The interface that consumes that metadata puts the original route back on the skb before the xfrm lookup, which needs its family, and installing a reference counted route over a dst slot that is still occupied trips the slot assertion; the slot is cleared first. The same overwrite is in the tc-bpf helper that attaches the metadata, so both sites are fixed in that patch.
---
v2 -> v3:
- Patch 2/4: Document the return value of skb_dst_drop_keep_metadata() in its kernel-doc comment. The missing Return: section was caught by NIPA CI.
v1 -> v2:
- Do not drop a dst that is not a route: a DST_METADATA dst is the tunnel template a tunnel helper attached to the packet, and dropping it discards the encapsulation parameters (Pablo Neira Ayuso).
- Keep a route's encapsulation parameters as well: a route installed with an ip, ip6 or xfrm encapsulation carries them in dst->lwtstate, which a drop would discard before a downstream tunnel or xfrm device could use them. The dst release now goes through a helper that moves them onto a metadata dst first (new 2/4).
- Fix the dst slot the xfrm consumer restores: a collect_md xfrm interface puts the original route back before the xfrm lookup, and installing it over a dst that is still there trips the slot assertion. New 1/4 clears the slot first at both that site and in the tc-bpf helper that attaches the metadata.
Jamal Hadi Salim (4):
net: xfrm: interface: restore dst_orig on every xfrm interface
net: dst: keep the LWT metadata of a dropped route
netfilter: nft_fwd_netdev: drop the stale dst when steering to a
device
bpf: drop the stale dst when redirecting to an explicit nexthop
include/net/dst_metadata.h | 1 + include/net/xfrm.h | 2 - net/core/dst.c | 76 ++++++++++++++++++++++++++++++++++ net/core/filter.c | 12 ++---- net/netfilter/nft_fwd_netdev.c | 6 +++ net/xfrm/xfrm_interface_bpf.c | 16 +++---- net/xfrm/xfrm_interface_core.c | 22 +++++----- 7 files changed, 104 insertions(+), 31 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/4 net: xfrm: interface: restore dst_orig on every xfrm interface
Found while testing the dst release for the two producers that steer a packet to another device, fixed later in this series. One of the consumers of the metadata such a release installs is an xfrm interface, which restores the original route before the xfrm lookup; the swap warned on the metadata dst still installed in the skb, and only the collect_md arm restored the route at all.
The issue:
An xfrm interface takes the if_id and the underlying device either from its configuration or, in collect_md mode, from the xfrm metadata on the skb. When that metadata also carries the route the packet arrived through, xfrmi_xmit2() puts the route back on the skb, because the xfrm lookup takes the address family from it. skb_dst_set() expects the dst slot to be empty for a reference counted dst and warns when it is not, so the route landed over a metadata dst that was still there; a kernel built with CONFIG_DEBUG_NET=y panics on the first packet that takes this path when panic_on_warn is set.
Two more defects sit in the same place. An interface with a configured if_id never restores the route: it takes the metadata dst as it is, whose address family is AF_UNSPEC, so the lookup finds no policy and the packet is dropped as a link failure instead of being transformed. And the restore moved the route out of the metadata dst, which a clone of the skb shares, so the clone that reached the interface first left the original packet with nothing to restore.
The same slot overwrite is in the unstable helper a tc-bpf program uses to attach that metadata: bpf_skb_set_xfrm_info() records the route as dst_orig and installs a per-cpu metadata dst over it. The per-cpu dst is shared by every invocation of the program, so the restore cannot keep anything in it.
The Fix:
Restore dst_orig in both arms of xfrmi_xmit2(), taking a reference with dst_clone() so the metadata dst keeps its own, and empty the counted slot with skb_dst_drop() before the route is installed. The helper allocates a metadata dst per skb instead of a per-cpu one, so the route it records belongs to that skb and is released with it; the per-cpu allocation is no longer used and goes away.
Conditions to recreate the bug:
A tc-bpf program that records the route as dst_orig with bpf_skb_set_xfrm_info() and redirects the packet to an xfrm interface is the shortest way to hit the overwrite. A netdev egress fwd rule that steers a packet routed with an xfrm encapsulation into an interface reaches the same place once the dst release earlier in this series keeps the route:
ip link add xf0 type xfrm if_id 42
ip link set xf0 up
ip neigh replace 10.20.0.1 lladdr 02:aa:00:00:00:ab \
dev va nud permanent
ip route add 10.20.0.1/32 dev va encap xfrm if_id 42 nft add rule netdev t c fwd ip to 10.1.0.2 device xf0
Send one packet to 10.20.0.1. With CONFIG_DEBUG_NET=y and panic_on_warn=1 the kernel panics in xfrmi_xmit() with the metadata dst still installed while the route is put back. The interface with the configured if_id drops the packet as a link failure without consulting the outbound policy, and a clone made after the metadata was attached consumes the route before the original packet arrives.
--- include/net/xfrm.h | 2 -- net/core/filter.c | 8 -------- net/xfrm/xfrm_interface_bpf.c | 16 +++++----------- net/xfrm/xfrm_interface_core.c | 22 ++++++++++++---------- 4 files changed, 17 insertions(+), 31 deletions(-)
include/net/xfrm.h +0 -2
@@ -2370,8 +2370,6 @@ static inline bool xfrm6_local_dontfrag(const struct sock *sk)#if (IS_BUILTIN (CONFIG_XFRM_INTERFACE ) &&IS_ENABLED (CONFIG_DEBUG_INFO_BTF )) || \ (IS_MODULE (CONFIG_XFRM_INTERFACE ) &&IS_ENABLED (CONFIG_DEBUG_INFO_BTF_MODULES )) -extern struct metadata_dst __percpu *xfrm_bpf_md_dst; -int register_xfrm_interface_bpf (void );#else
net/core/filter.c +0 -8
@@ -6354,14 +6354,6 @@ static const struct bpf_func_proto bpf_bind_proto = {#ifdef CONFIG_XFRM -#if (IS_BUILTIN (CONFIG_XFRM_INTERFACE ) &&IS_ENABLED (CONFIG_DEBUG_INFO_BTF )) || \ - (IS_MODULE (CONFIG_XFRM_INTERFACE ) &&IS_ENABLED (CONFIG_DEBUG_INFO_BTF_MODULES )) - -struct metadata_dst __percpu *xfrm_bpf_md_dst; -EXPORT_SYMBOL_GPL (xfrm_bpf_md_dst); - -#endif - BPF_CALL_5(bpf_skb_get_xfrm_state, struct sk_buff *, skb, u32, index, struct bpf_xfrm_state *, to, u32, size, u64, flags) {
net/xfrm/xfrm_interface_bpf.c +5 -11
@@ -68,16 +68,9 @@ __bpf_kfunc int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx, const struct bpif (unlikely (skb_metadata_dst (skb)))return -EINVAL ; -if (!xfrm_bpf_md_dst) { -struct metadata_dst __percpu *tmp; - - tmp =metadata_dst_alloc_percpu (0 ,METADATA_XFRM ,GFP_ATOMIC ); -if (!tmp) -return -ENOMEM ; -if (cmpxchg (&xfrm_bpf_md_dst,NULL , tmp)) -metadata_dst_free_percpu (tmp); - } - md_dst =this_cpu_ptr (xfrm_bpf_md_dst); + md_dst =metadata_dst_alloc (0 ,METADATA_XFRM ,GFP_ATOMIC ); +if (unlikely (!md_dst)) +return -ENOMEM ; info = &md_dst->u.xfrm_info;
@@ -86,7 +79,8 @@ __bpf_kfunc int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx, const struct bpskb_dst_force (skb); info->dst_orig =skb_dst (skb); -dst_hold ((struct dst_entry *)md_dst); +/* The allocated dst owns one reference, handed to the skb here. */ +skb_dstref_steal (skb);skb_dst_set (skb, (struct dst_entry *)md_dst);return 0 ; }
net/xfrm/xfrm_interface_core.c +12 -10
@@ -423,6 +423,7 @@ static int xfrmi_rcv_cb(struct sk_buff *skb, int err)static int xfrmi_xmit2 (struct sk_buff *skb,struct net_device *dev,struct flowi *fl) { +struct xfrm_md_info *md_info =skb_xfrm_md_info (skb);struct xfrm_if *xi =netdev_priv (dev);struct dst_entry *dst =skb_dst (skb);unsigned int length = skb->len;
@@ -433,25 +434,26 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)int mtu;if (xi->p.collect_md) { -struct xfrm_md_info *md_info =skb_xfrm_md_info (skb); -if (unlikely (!md_info))return -EINVAL ; if_id = md_info->if_id; fl->flowi_oif = md_info->link; -if (md_info->dst_orig) { -struct dst_entry *tmp_dst = dst; - - dst = md_info->dst_orig; -skb_dst_set (skb, dst); - md_info->dst_orig =NULL ; -dst_release (tmp_dst); - } }else { if_id = xi->p.if_id; } +/* The metadata dst carries the route the packet is still to be +* transformed for, and the lookup below takes the address family from +* the dst it is given. Put that route back, taking our own reference: +* the metadata dst keeps its own, as a clone of this skb shares it. +*/ +if (md_info && md_info->dst_orig) { + dst =dst_clone (md_info->dst_orig); +skb_dst_drop (skb); +skb_dst_set (skb, dst); + } +dst_hold (dst); dst =xfrm_lookup_with_ifid (xi->net, dst, fl,NULL ,0 , if_id);if (IS_ERR (dst)) {
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v3 1/4] net: xfrm: interface: restore dst_orig on every xfrm interface
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] xfrm: interface: missing Fixes trailer in bug-fix commit message --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] xfrm: interface: missing Fixes trailer in bug-fix commit message --
commit fc50a8a0e09367a243cf350a9e4dc409fd76b617
Author: Jamal Hadi Salim <[email protected]>
Quoted 62 lines
net: xfrm: interface: restore
dst_origon every xfrm interfaceFound while testing the dst release for the two producers that steer a packet to another device, fixed later in this series. One of the consumers of the metadata such a release installs is an xfrm interface, which restores the original route before the xfrm lookup; the swap warned on the metadata dst still installed in the skb, and only the
collect_mdarm restored the route at all.The issue:
An xfrm interface takes theif_idand the underlying device either from its configuration or, incollect_mdmode, from the xfrm metadata on the skb. When that metadata also carries the route the packet arrived through,xfrmi_xmit2()puts the route back on the skb, because the xfrm lookup takes the address family from it.skb_dst_set()expects the dst slot to be empty for a reference counted dst and warns when it is not, so the route landed over a metadata dst that was still there; a kernel built withCONFIG_DEBUG_NET=ypanics on the first packet that takes this path whenpanic_on_warnis set.Two more defects sit in the same place. An interface with a configured
if_idnever restores the route: it takes the metadata dst as it is, whose address family isAF_UNSPEC, so the lookup finds no policy and the packet is dropped as a link failure instead of being transformed. And the restore moved the route out of the metadata dst, which a clone of the skb shares, so the clone that reached the interface first left the original packet with nothing to restore.The same slot overwrite is in the unstable helper a tc-bpf program uses to attach that metadata:
bpf_skb_set_xfrm_info()records the route asdst_origand installs a per-cpu metadata dst over it. The per-cpu dst is shared by every invocation of the program, so the restore cannot keep anything in it.The Fix:
Restoredst_origin both arms ofxfrmi_xmit2(), taking a reference withdst_clone()so the metadata dst keeps its own, and empty the counted slot withskb_dst_drop()before the route is installed. The helper allocates a metadata dst per skb instead of a per-cpu one, so the route it records belongs to that skb and is released with it; the per-cpu allocation is no longer used and goes away.Conditions to recreate the bug:
A tc-bpf program that records the route asdst_origwithbpf_skb_set_xfrm_info()and redirects the packet to an xfrm interface is the shortest way to hit the overwrite. A netdev egress fwd rule that steers a packet routed with an xfrm encapsulation into an interface reaches the same place once the dst release earlier in this series keeps the route:ip link add xf0 type xfrm
if_id42
ip link set xf0 up
ip neigh replace 10.20.0.1 lladdr 02:aa:00:00:00:ab \
dev va nud permanent
ip route add 10.20.0.1/32 dev va encap xfrmif_id42 nft add rule netdev t c fwd ip to 10.1.0.2 device xf0Send one packet to 10.20.0.1. With
CONFIG_DEBUG_NET=yand panic_on_warn=1 the kernel panics inxfrmi_xmit()with the metadata dst still installed while the route is put back. The interface with the configuredif_iddrops the packet as a link failure without consulting the outbound policy, and a clone made after the metadata was attached consumes the route before the original packet arrives.
Quoted 2 lines
Reviewed-by Victor Nogueira <[email protected]>Signed-off-by Jamal Hadi Salim <[email protected]>
[Severity: Low]
This fixes runtime defects in bpf_skb_set_xfrm_info() and xfrmi_xmit2(). Should the commit message include a Fixes tag:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH net-next v3 1/4] net: xfrm: interface: restore dst_orig on every xfrm interface
Quoted 4 lines · On Mon, Nov 16, 2026 at 5:19 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] xfrm: interface: missing Fixes trailer in bug-fix commit message
Remember this for the future: net-next patches do not carry Fixes trailers. This is a net next patch. Just because i use the terms "bug" and "The Fix" doesnt qualify i put a fixes patch.
cheers,
jamal
Quoted 78 lines
--
commit
fc50a8a0e09367a243cf350a9e4dc409fd76b617
Author: Jamal Hadi Salim <[email protected]>Quoted 62 lines
net: xfrm: interface: restore
dst_origon every xfrm interfaceFound while testing the dst release for the two producers that steer a packet to another device, fixed later in this series. One of the consumers of the metadata such a release installs is an xfrm interface, which restores the original route before the xfrm lookup; the swap warned on the metadata dst still installed in the skb, and only the
collect_mdarm restored the route at all.The issue:
An xfrm interface takes theif_idand the underlying device either from its configuration or, incollect_mdmode, from the xfrm metadata on the skb. When that metadata also carries the route the packet arrived through,xfrmi_xmit2()puts the route back on the skb, because the xfrm lookup takes the address family from it.skb_dst_set()expects the dst slot to be empty for a reference counted dst and warns when it is not, so the route landed over a metadata dst that was still there; a kernel built withCONFIG_DEBUG_NET=ypanics on the first packet that takes this path whenpanic_on_warnis set.Two more defects sit in the same place. An interface with a configured
if_idnever restores the route: it takes the metadata dst as it is, whose address family isAF_UNSPEC, so the lookup finds no policy and the packet is dropped as a link failure instead of being transformed. And the restore moved the route out of the metadata dst, which a clone of the skb shares, so the clone that reached the interface first left the original packet with nothing to restore.The same slot overwrite is in the unstable helper a tc-bpf program uses to attach that metadata:
bpf_skb_set_xfrm_info()records the route asdst_origand installs a per-cpu metadata dst over it. The per-cpu dst is shared by every invocation of the program, so the restore cannot keep anything in it.The Fix:
Restoredst_origin both arms ofxfrmi_xmit2(), taking a reference withdst_clone()so the metadata dst keeps its own, and empty the counted slot withskb_dst_drop()before the route is installed. The helper allocates a metadata dst per skb instead of a per-cpu one, so the route it records belongs to that skb and is released with it; the per-cpu allocation is no longer used and goes away.Conditions to recreate the bug:
A tc-bpf program that records the route asdst_origwithbpf_skb_set_xfrm_info()and redirects the packet to an xfrm interface is the shortest way to hit the overwrite. A netdev egress fwd rule that steers a packet routed with an xfrm encapsulation into an interface reaches the same place once the dst release earlier in this series keeps the route:ip link add xf0 type xfrm
if_id42
ip link set xf0 up
ip neigh replace 10.20.0.1 lladdr 02:aa:00:00:00:ab \
dev va nud permanent
ip route add 10.20.0.1/32 dev va encap xfrmif_id42 nft add rule netdev t c fwd ip to 10.1.0.2 device xf0Send one packet to 10.20.0.1. With
CONFIG_DEBUG_NET=yand panic_on_warn=1 the kernel panics inxfrmi_xmit()with the metadata dst still installed while the route is put back. The interface with the configuredif_iddrops the packet as a link failure without consulting the outbound policy, and a clone made after the metadata was attached consumes the route before the original packet arrives.Quoted 2 lines
Reviewed-by Victor Nogueira <[email protected]>Signed-off-by Jamal Hadi Salim <[email protected]>[Severity: Low]
This fixes runtime defects inbpf_skb_set_xfrm_info()andxfrmi_xmit2(). Should the commit message include a Fixes tag:Fixes 94151f5aa966 ("xfrm: interface: Add unstable helpers for setting/getting XFRM metadata from TC-BPF")--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH net-next v3 1/4] net: xfrm: interface: restore dst_orig on every xfrm interface
In reply to Jamal Hadi SalimThank 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…
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] The commit fixes bugs that users can hit, but it has no Fixes:
tag and no Cc: stable.
- [Low] The commit message contradicts itself about where this patch sits in the series, and the second reproducer it gives does nothing at this…
- [Low] In bpf_skb_set_xfrm_info() (net/xfrm/xfrm_interface_bpf.c:82-84), the new comment "The allocated dst owns one reference, handed to the…
--
net: xfrm: interface: restore dst_orig on every xfrm interface
xfrmi_xmit2() now restores md_info->dst_orig on both collect_md and configured if_id interfaces. It takes its own reference with dst_clone() and drops the metadata dst from the skb before installing the route. bpf_skb_set_xfrm_info() now allocates a metadata dst per skb, and the shared per-cpu xfrm_bpf_md_dst is removed.
Quoted 2 lines
Found while testing the dst release for the two producers that steer a packet to another device, fixed later in this series. One of the consumers
[ ... ]
Quoted 11 lines
the shortest way to hit the overwrite. A netdev egress fwd rule that steers a packet routed with an xfrm encapsulation into an interface reaches the same place once the dst release earlier in this series keeps the route:
ip link add xf0 type xfrm
if_id42
ip link set xf0 up
ip neigh replace 10.20.0.1 lladdr 02:aa:00:00:00:ab \
dev va nud permanent
ip route add 10.20.0.1/32 dev va encap xfrmif_id42 nft add rule netdev t c fwd ip to 10.1.0.2 device xf0
Quoted 3 lines
Send one packet to 10.20.0.1. With
CONFIG_DEBUG_NET=yand panic_on_warn=1 the kernel panics inxfrmi_xmit()with the metadata dst still installed while the route is put back.
[Severity: Low]
The first paragraph says the dst release is "fixed later in this series". This paragraph says it comes "earlier in this series". Which one is meant?
This commit appears to be the first in the series. The dst release changes (skb_dst_drop_keep_metadata() and its use in nft_fwd_netdev) come after it.
At this commit, can the nft reproducer reach the new restore block in xfrmi_xmit2() at all? The only writer of xfrm_md_info.dst_orig is bpf_skb_set_xfrm_info(). For an encap xfrm route, skb_xfrm_md_info() falls back to the lwtunnel state:
include/net/dst_metadata.h:skb_xfrm_md_info() {
...
if (dst && dst->lwtstate &&
dst->lwtstate->type == LWTUNNEL_ENCAP_XFRM)
return lwt_xfrm_info(dst->lwtstate);
...
}dst_orig is never set in that state, so md_info->dst_orig stays NULL.
Also, on the tc-bpf path, wouldn't the first DEBUG_NET warning fire in bpf_skb_set_xfrm_info() rather than in xfrmi_xmit()? Before this patch, skb_dst_force() leaves a counted reference in the slot. Then skb_dst_set(skb, md_dst) trips skb_dst_check_unset() before the packet reaches the xfrm interface.
Quoted 4 lines
net/xfrm/xfrm_interface_bpf.c +0
-0
[ ... ]
net/xfrm/xfrm_interface_bpf.c __bpf_kfunc int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx, const struct bp · line 86
Quoted 10 lines
net/xfrm/xfrm_interface_bpf.c +2
-1@@ -86,7 +79,8 @@ __bpf_kfunc int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx, const struct bpskb_dst_force (skb); info->dst_orig =skb_dst (skb); -dst_hold ((struct dst_entry *)md_dst); +/* The allocated dst owns one reference, handed to the skb here. */ +skb_dstref_steal (skb);skb_dst_set (skb, (struct dst_entry *)md_dst);return 0 ; }
[Severity: Low]
This isn't a bug, but does this comment describe the line it sits on? It reads as describing the md_dst reference, which the following skb_dst_set() hands to the skb.
Here, skb_dstref_steal() clears skb->_skb_refdst without dropping the reference that skb_dst_force() took on the original route. That reference now belongs to info->dst_orig, and metadata_dst_free() releases it later:
net/core/dst.c:metadata_dst_free() {
...
dst_release(md_dst->u.xfrm_info.dst_orig);
...
}The kernel-doc for skb_dstref_steal() says:
* When in doubt, prefer skb_dst_drop() over skb_dstref_steal() to correctly
* handle dst_entry reference counting.
Using skb_dst_drop() here would free dst_orig while it is still in use. Could the comment say that the route's reference moves to info->dst_orig? The other one-way users in net/ipv4/netfilter.c, net/ipv6/netfilter.c and net/xfrm/xfrm_policy.c have comments like that.
Quoted 4 lines
net/xfrm/xfrm_interface_core.c +0
-0
[ ... ]
Quoted 9 lines
net/xfrm/xfrm_interface_core.c +0
-2@@ -433,25 +434,26 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)int mtu;if (xi->p.collect_md) { -struct xfrm_md_info *md_info =skb_xfrm_md_info (skb); -if (unlikely (!md_info))return -EINVAL ;
net/xfrm/xfrm_interface_core.c xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) · line 450
Quoted 10 lines
net/xfrm/xfrm_interface_core.c +0
-8if_id = md_info->if_id; fl->flowi_oif = md_info->link; -if (md_info->dst_orig) { -struct dst_entry *tmp_dst = dst; - - dst = md_info->dst_orig; -skb_dst_set (skb, dst); - md_info->dst_orig =NULL ; -dst_release (tmp_dst); - }
[Severity: Low]
Should this patch have a Fixes: tag and Cc: stable? The restore block removed here and the per-cpu xfrm_bpf_md_dst used by bpf_skb_set_xfrm_info() both come from:
The patch fixes problems that users can hit:
- the skb_dst_set() warning over a counted dst slot
- the route lost when a clone reaches the interface first
- the link-failure drops on a non-collect_md interface
The DEBUG_NET_WARN_ON_ONCE() in skb_dst_check_unset(), which turns the overwrite into a splat or a panic, was added later by commit a890348adcc9.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CORE-9NOG.v3.r0.20261115050625%40mojatatu.com
PATCH v3 2/4 net: dst: keep the LWT metadata of a dropped route
In reply to Jamal Hadi SalimFound while working on the two producers that steer a packet to another device's neighbour, fixed later in this series. Both release the route dst on the way, and a route installed with an encapsulation carries the parameters a device downstream needs: an ip or ip6 encapsulation holds an ip_tunnel_info, where skb_tunnel_info() reads it, and an xfrm encapsulation holds an xfrm_md_info, where skb_xfrm_md_info() reads it. The release discards them, so a tunnel or an xfrm interface downstream has nothing left to build the outer header with, or to select its if_id.
The Fix:
Add skb_dst_drop_keep_metadata(), which moves those parameters onto a metadata dst of its own before the route is released. The ip and ip6 payload is copied field by field; the route's dst cache belongs to its lwtstate and is shared by every packet that uses the route, so it is not
duplicated: the copy starts with an empty cache, which costs the tunnel one route lookup. The xfrm payload keeps the route itself, because the xfrm lookup reads its family; the counted reference the skb already holds moves into the metadata dst, which releases it once it has been consumed.
The helper owns the whole operation: a dst that is not a route is not dropped, because a metadata dst is the encapsulation itself. Its callers must not transmit with the stale route, so a failed copy is reported and the skb is left untouched for its owner to drop.
Conditions to recreate the bug:
Install a route with an encapsulation (ip route add ... encap ip id <id> dst <remote>, or encap xfrm if_id <id>), steer a packet to another device's neighbour with a netdev egress fwd rule or bpf_redirect_neigh(), and release the route dst before neigh_xmit() hands the packet on. A tunnel or xfrm device in the path then finds no parameters in skb_tunnel_info() or skb_xfrm_md_info() and drops the packet instead of using them.
---
v2 -> v3:
- Document the Return: value of skb_dst_drop_keep_metadata() in its kernel-doc comment. Caught by NIPA CI.
include/net/dst_metadata.h | 1 + net/core/dst.c | 76 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+)
include/net/dst_metadata.h +1 -0
@@ -138,6 +138,7 @@ struct metadata_dst *metadata_dst_alloc(u8 optslen, enum metadata_type type,void metadata_dst_free_percpu (struct metadata_dst __percpu *md_dst);struct metadata_dst __percpu *metadata_dst_alloc_percpu (u8 optslen,enum metadata_type type,gfp_t flags); +bool skb_dst_drop_keep_metadata (struct sk_buff *skb);static inline struct metadata_dst *tun_rx_dst (int md_size) {
net/core/dst.c +76 -0
79 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v3 2/4] net: dst: keep the LWT metadata of a dropped route
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…
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] The commit message presents this patch as a bug fix, with a "The Fix:" section, a "Conditions to recreate the bug" section and the…
- [Low] The Return: section of the kernel-doc for skb_dst_drop_keep_metadata() (net/core/dst.c:370-373) does not match…
--
net: dst: keep the LWT metadata of a dropped route
This adds skb_dst_drop_keep_metadata(). It releases an skb's route dst and moves any LWT encapsulation metadata onto a newly allocated metadata
dst: ip_tunnel_info for ip/ip6 encaps, xfrm_md_info for xfrm. The helper is meant for the nft fwd and bpf_redirect_neigh() producers changed later in the series.
Quoted 3 lines
Found while working on the two producers that steer a packet to another device's neighbour, fixed later in this series. Both release the route dst on the way, and a route installed with an encapsulation carries the
[Severity: Low]
Is this description accurate for the tree at this commit?
nft_fwd_neigh_eval() in net/netfilter/nft_fwd_netdev.c goes straight to neigh_xmit() and never calls skb_dst_drop():
skb->dev = dev; skb_clear_tstamp(skb); nf_dev_xmit_recursion_inc(); neigh_xmit(neigh_table, dev, addr, skb);
The nh != NULL path of __bpf_redirect_neigh_v4() and __bpf_redirect_neigh_v6() in net/core/filter.c also leaves the original route attached to the skb.
This commit adds no callers of skb_dst_drop_keep_metadata(). The route release only appears in the later patches "netfilter: nft_fwd_netdev:
drop the stale dst when steering to a device" and "bpf: drop the stale dst when redirecting to an explicit nexthop". The commit messages of those patches say the producers currently leave the dst untouched.
Quoted 3 lines
The Fix:
Addskb_dst_drop_keep_metadata(), which moves those parameters onto a metadata dst of its own before the route is released.
[ ... ]
Quoted 6 lines
Conditions to recreate the bug:
Install a route with an encapsulation (ip route add ... encap ip id <id> dst <remote>, or encap xfrmif_id<id>), steer a packet to another device's neighbour with a netdev egress fwd rule orbpf_redirect_neigh(), and release the route dst beforeneigh_xmit()hands the packet on.
To reproduce, the reader has to release the route dst before neigh_xmit(). Current code does not do that.
Could the message present this patch as a prerequisite helper for the later producer changes, rather than as a fix with "The Fix:" and "Conditions to recreate the bug:" sections?
Quoted 5 lines
net/core/dst.c +0
-0@@ -353,3 +353,79 @@ void metadata_dst_free_percpu(struct metadata_dst __percpu *md_dst)
[ ... ]
Quoted 7 lines
+ * A dst that is metadata is left in place.
+ *
+ * Return: true if the skb is left free to be sent, either because its dst is
+ * metadata already or because the LWT metadata was moved onto a new dst;
+ * false if no copy could be allocated, in which case the caller must drop the
+ * skb.
+ */
[Severity: Low]
Does this Return: section match what skb_dst_drop_keep_metadata() does?
The doc says false only means no copy could be allocated. The XFRM branch also returns false when skb_dst_force() fails:
if (!skb_dst_force(skb)) {
metadata_dst_free(md_dst);
return false;
}This happens when a noref route's refcount has already reached zero, for example during a concurrent route removal. By that point skb_dst_force() has set skb->_skb_refdst to 0, so the skb comes back with no dst. The commit message's "the skb is left untouched for its owner to drop" does not hold here either.
The doc says true only means the dst was already metadata or the metadata was moved. True is also returned when the skb has no dst at all, because skb_valid_dst() is false for a NULL dst:
if (!skb_valid_dst(skb)) return true;
True is also returned when the route has no lwtstate, or an lwtstate type other than IP, IP6 or XFRM (MPLS, SEG6, BPF and so on). In that case the route is dropped and the skb is left without a dst:
skb_dst_drop(skb); if (md_dst) skb_dst_set(skb, &md_dst->dst); return true;
The callers added later in the series drop the skb on false. Since this helper is exported, could the kernel-doc spell out these cases?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CORE-9NOG.v3.r0.20261115050625%40mojatatu.com
PATCH v3 3/4 netfilter: nft_fwd_netdev: drop the stale dst when steering to a device
In reply to Jamal Hadi SalimThis is a followup of the review of the teql arp-queue fix as reported by Sashiko.
The issue:
The neighbour variant of fwd rewrites skb->dev to the configured output device and calls neigh_xmit(), but leaves the skb's dst untouched. If that device's neighbour for the configured nexthop is incomplete, the packet is parked on the neighbour's arp_queue while the stale dst still describes the device the packet was routed through. Draining the queue re-looks the neighbour up from that dst, so the frame is built with the routed device's link-layer header and then transmitted on the configured device. The packet leaves with another device's addresses.
The Fix:
Release the dst before the device switch. Both lookup inputs the neighbour transmission needs, the device and the nexthop, are supplied by the rule, so the route dst is never consulted. Without it the queue drain keeps the parking neighbour and the frame carries the configured device's addresses.
The release goes through skb_dst_drop_keep_metadata(), so encapsulation parameters a route carries are handed over to a metadata dst instead of being lost, and a metadata dst already on the packet is left in place. If that copy cannot be allocated the packet is dropped, never sent with the stale route.
Conditions to recreate the bug:
Two network namespaces, A (10.10.0.1/24) and B (10.1.0.1/24) in one, their veth peers in the other with only A's peer addressed (10.10.0.2/24) so B's nexthop cannot be resolved by ARP. Resolve A's neighbour for 10.10.0.2 as permanent, then load this ruleset on A:
table netdev t {
chain c {
type filter hook egress device va priority 0
policy accept
fwd ip to 10.1.0.2 device vb
}
}Send one packet to 10.10.0.2. It is parked on B's incomplete neighbour for 10.1.0.2; once that neighbour becomes valid the frame leaves B carrying A's source address and A's neighbour as the destination.
---
v2 -> v3:
- Add the Reviewed-by tag from Pablo Neira Ayuso, given on the v2 posting of this patch.
net/netfilter/nft_fwd_netdev.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nft_fwd_netdev.c +6 -0
@@ -14,6 +14,7 @@#include <net/netfilter/nf_tables.h> #include <net/netfilter/nf_tables_offload.h> #include <net/netfilter/nf_dup_netdev.h> +#include <net/dst_metadata.h> #include <net/netfilter/nf_recursion.h> #include <net/neighbour.h> #include <net/ip.h>
@@ -160,6 +161,11 @@ static void nft_fwd_neigh_eval(const struct nft_expr *expr, goto out; } +if (!skb_dst_drop_keep_metadata (skb)) { + verdict =NF_DROP ; + goto out; + } +local_bh_disable ();if (nf_dev_xmit_recursion ()) {local_bh_enable ();
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v3 3/4] netfilter: nft_fwd_netdev: drop the stale dst when steering to a device
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
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] The commit message justifies the change by saying "the route dst is never consulted", but that only holds for the neighbour lookup.
- [Low] This patch fixes a user-visible bug but has no Fixes: tag.
--
netfilter: nft_fwd_netdev: drop the stale dst when steering to a device
This patch makes the neighbour variant of the nft fwd expression release the skb's dst before switching skb->dev to the configured device. Without this, a packet parked on an incomplete neighbour's arp_queue could later be sent with the link-layer header of the device it was originally routed through. The release goes through skb_dst_drop_keep_metadata(), so LWT/tunnel metadata is kept, and the packet is dropped if that copy fails.
Quoted 4 lines
net/netfilter/nft_fwd_netdev.c +0
-0
[ ... ]
net/netfilter/nft_fwd_netdev.c static void nft_fwd_neigh_eval(const struct nft_expr *expr, · line 168
Quoted 9 lines
net/netfilter/nft_fwd_netdev.c +5
-0@@ -160,6 +161,11 @@ static void nft_fwd_neigh_eval(const struct nft_expr *expr, goto out; } +if (!skb_dst_drop_keep_metadata (skb)) { + verdict =NF_DROP ; + goto out; + } +
[Severity: Low]
Should this have a Fixes: tag? The skb->dev = dev switch and the neigh_xmit() call in nft_fwd_neigh_eval() both come from:
d32de98ea70f ("netfilter: nft_fwd_netdev: allow to forward packets via neighbour layer")
That commit changed the device without releasing the dst, which is the behaviour fixed here. Something like this would help stable pick it up:
This patch also needs skb_dst_drop_keep_metadata(), which is added by the earlier patch in this series, "net: dst: keep the LWT metadata of a dropped route". Could that dependency be stated for backporters?
[Severity: Medium]
The commit message says:
Both lookup inputs the neighbour transmission needs, the device and the nexthop, are supplied by the rule, so the route dst is never consulted.
Is that true beyond the neighbour lookup? This call runs for every packet the neighbour variant of fwd handles, not only for packets that end up on an incomplete neighbour's arp_queue. For a plain route, skb_dst_drop_keep_metadata() ends up in skb_dst_drop(). After that, code on the configured device's transmit path sees skb_dst(skb) == NULL.
One example is an NBMA ipip/gre device (tnl_params->daddr == 0) used as the fwd target:
nft_fwd_neigh_eval()
skb_dst_drop_keep_metadata()
neigh_xmit()
... dev_queue_xmit()
ip_tunnel_xmit()net/ipv4/ip_tunnel.c:ip_tunnel_xmit() {
...
dst = tnl_params->daddr;
if (dst == 0) {
/* NBMA tunnel */
if (!skb_dst(skb)) {
DEV_STATS_INC(dev, tx_fifo_errors);
goto tx_error;
}
...
rt = skb_rtable(skb);
dst = rt_nexthop(rt, inner_iph->daddr);
...
}Before this patch, "fwd ip to X device tunX" on such a tunnel picked the destination with rt_nexthop() of the old route. Now the packet would be dropped and counted in tx_fifo_errors.
The ip6_tnl/sit NBMA paths that call dst_neigh_lookup(skb_dst(skb), ...) look like they are affected the same way. So does route realm (tclassid) classification on the target device's qdisc.
The change may well be correct overall. Could the commit message describe this effect on the resolved-neighbour path too, and not only the arp_queue drain?
Quoted 3 lines
net/netfilter/nft_fwd_netdev.c +0
-0local_bh_disable ();if (nf_dev_xmit_recursion ()) {local_bh_enable ();
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CORE-9NOG.v3.r0.20261115050625%40mojatatu.com
PATCH v3 4/4 bpf: drop the stale dst when redirecting to an explicit nexthop
In reply to Jamal Hadi SalimThis is a followup of the review of the teql arp-queue fix as reported by Sashiko.
The issue:__bpf_redirect_neigh_v4() and __bpf_redirect_neigh_v6() install a dst for the redirect target only when the program lets the helper do the FIB lookup. With BPF_F_NEXTHOP the program supplies the nexthop, the lookup is skipped, and whatever dst the packet arrived with stays attached while bpf_out_neigh_v{4,6}() switch skb->dev to the target device. If that device's neighbour is incomplete the packet is parked on its arp_queue with the original route's dst; draining the queue re-looks the neighbour up from that dst and builds the frame with the original device's link-layer header, then transmits it on the target device.
The Fix:
Release the dst when the nexthop is supplied. That branch never consults the route dst, so nothing that describes the route is lost, and the queue drain keeps the target device's parking neighbour.
The release goes through skb_dst_drop_keep_metadata(), so encapsulation parameters a route carries are handed over to a metadata dst instead of being lost, and a metadata dst already on the packet is left in place. Both wrappers take their existing drop path when that copy cannot be allocated, so a packet is never sent with the stale route.
Conditions to recreate the bug:
Two network namespaces, A (10.10.0.1/24) and B (10.1.0.1/24) in one, their veth peers in the other with only A's peer addressed (10.10.0.2/24) so B's nexthop cannot be resolved by ARP. Resolve A's neighbour for 10.10.0.2 as permanent and attach a cls_bpf egress program to A, with vb the index of B:
struct bpf_redir_neigh nh = { .nh_family = AF_INET,
.ipv4_nh = htonl(0x0a010002) };
return bpf_redirect_neigh(vb, &nh, sizeof(nh), 0);Send one packet to 10.10.0.2. It is parked on B's incomplete neighbour for 10.1.0.2; once that neighbour becomes valid the frame leaves B carrying A's source address and A's neighbour as the destination.
--- net/core/filter.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/filter.c +4 -0
@@ -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);
@@ -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);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v3 4/4] bpf: drop the stale dst when redirecting to an explicit nexthop
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] bpf: missing Fixes trailer for commit ba452c9e996d in commit message --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] bpf: missing Fixes trailer for commit ba452c9e996d in commit message
--
commit f68e158b3aca1ec216cec6453916862a5820e88d
Author: Jamal Hadi Salim <[email protected]>
Quoted 42 lines
bpf: drop the stale dst when redirecting to an explicit nexthop
This is a followup of the review of the teql arp-queue fix as reported by Sashiko.
The issue:
__bpf_redirect_neigh_v4()and__bpf_redirect_neigh_v6()install a dst for the redirect target only when the program lets the helper do the FIB lookup. WithBPF_F_NEXTHOPthe program supplies the nexthop, the lookup is skipped, and whatever dst the packet arrived with stays attached while bpf_out_neigh_v{4,6}() switchskb->devto the target device. If that device's neighbour is incomplete the packet is parked on itsarp_queuewith the original route's dst; draining the queue re-looks the neighbour up from that dst and builds the frame with the original device's link-layer header, then transmits it on the target device.The Fix:
Release the dst when the nexthop is supplied. That branch never consults the route dst, so nothing that describes the route is lost, and the queue drain keeps the target device's parking neighbour.The release goes through
skb_dst_drop_keep_metadata(), so encapsulation parameters a route carries are handed over to a metadata dst instead of being lost, and a metadata dst already on the packet is left in place. Both wrappers take their existing drop path when that copy cannot be allocated, so a packet is never sent with the stale route.Conditions to recreate the bug:
Two network namespaces, A (10.10.0.1/24) and B (10.1.0.1/24) in one, their veth peers in the other with only A's peer addressed (10.10.0.2/24) so B's nexthop cannot be resolved by ARP. Resolve A's neighbour for 10.10.0.2 as permanent and attach acls_bpfegress program to A, with vb the index of B:struct bpf_redir_neigh nh = { .nh_family = AF_INET, .ipv4_nh = htonl(0x0a010002) }; return bpf_redirect_neigh(vb, &nh, sizeof(nh), 0);Send one packet to 10.10.0.2. It is parked on B's incomplete neighbour for 10.1.0.2; once that neighbour becomes valid the frame leaves B carrying A's source address and A's neighbour as the destination.
Quoted 6 lines
Reported-by Sashiko (nipa) <[email protected]>Reviewed-by Victor Nogueira <[email protected]>Signed-off-by Jamal Hadi Salim <[email protected]>
[Severity: Low]
This fixes a bug on the explicit nexthop path in __bpf_redirect_neigh_v4() and __bpf_redirect_neigh_v6(). Should the commit message include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH net-next v3 4/4] bpf: drop the stale dst when redirecting to an explicit nexthop
In reply to Jamal Hadi SalimThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
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] The commit message says the explicit-nexthop branch "never consults the route dst, so nothing that describes the route is lost".
- [Low] The patch fixes a user-visible bug but has no Fixes: tag, and its commit message does not say which earlier patches it needs.
--
bpf: drop the stale dst when redirecting to an explicit nexthop
The patch changes __bpf_redirect_neigh_v4() and __bpf_redirect_neigh_v6(). When the BPF program supplies the nexthop, they now release the dst the packet arrived with, using skb_dst_drop_keep_metadata(). This stops a frame parked on the target device's arp_queue from being rebuilt later from the original route.
net/core/filter.c static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev, · line 2323
Quoted 11 lines
net/core/filter.c +2
-0@@ -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; }
[Severity: Low]
This isn't a runtime bug, but should this patch carry a Fixes: tag?
In both __bpf_redirect_neigh_v4() and __bpf_redirect_neigh_v6(), the if (!nh) { ... skb_dst_drop(); skb_dst_set(); } block with no else branch for an explicit nexthop came from:
ba452c9e996d ("bpf: Fix bpf_redirect_neigh helper api to support supplying nexthop")
So the stale dst has been reachable since that commit. Something like this would get the fix into stable:
The baseline tree also has no skb_dst_drop_keep_metadata(). It is added earlier in this series by "net: dst: keep the LWT metadata of a dropped route".
The METADATA_XFRM dst it can install also depends on "net: xfrm: interface:
restore dst_orig on every xfrm interface". Without that commit, xfrmi_xmit2() hits the skb_dst_set() warning, which panics under panic_on_warn.
Could the commit message name these prerequisites? A backport of this patch alone will not build. A backport with only the helper would bring back the xfrmi warning.
net/core/filter.c static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev, · line 2440
Quoted 9 lines
net/core/filter.c +2
-0err =bpf_out_neigh_v6 (net, skb, dev, nh);@@ -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; }
[Severity: Medium]
The commit message says:
That branch never consults the route dst, so nothing that describes the route is lost
That holds for bpf_out_neigh_v4() and bpf_out_neigh_v6(). Does it also hold for the target device's xmit path when the target is an NBMA tunnel (ipip, gre, sit or ip6tnl with no remote address)?
On those devices the neighbour is NOARP with direct output, so the BPF nexthop has no effect. The tunnel picks its outer endpoint from skb_dst():
tc egress prog
bpf_redirect_neigh(nbma_ifindex, &nh, ...)
__bpf_redirect_neigh_v4()
skb_dst_drop_keep_metadata()
bpf_out_neigh_v4()
neigh_output() -> dev_queue_xmit()
ipip_tunnel_xmit() / ipgre_xmit()
ip_tunnel_xmit()If the incoming route has no LWT state, skb_dst_drop_keep_metadata() leaves the skb with no dst. ip_tunnel_xmit() then always drops the packet:
net/ipv4/ip_tunnel.c:ip_tunnel_xmit() {
...
dst = tnl_params->daddr;
if (dst == 0) {
/* NBMA tunnel */
if (!skb_dst(skb)) {
DEV_STATS_INC(dev, tx_fifo_errors);
goto tx_error;
}
...
}ip6_tnl_xmit() goes to tx_err_link_failure in the same situation, and sit's ipip6_tunnel_dst_find() returns false. Before this patch these configurations transmitted, using rt_nexthop() of the original route.
If the incoming route has LWTUNNEL_ENCAP_IP or LWTUNNEL_ENCAP_IP6, the skb gets a METADATA_IP_TUNNEL metadata_dst instead. When that tun_info is not a usable IPv4 endpoint (encap ip6, or encap ip with no dst), ip_tunnel_xmit() falls through to:
} else if (payload_protocol == htons(ETH_P_IP)) {
rt = skb_rtable(skb);
dst = rt_nexthop(rt, inner_iph->daddr);
}and ip6_tnl_xmit() does:
} else if (payload_protocol == htons(ETH_P_IP)) {
const struct rtable *rt = skb_rtable(skb);
...
if (rt->rt_gw_family == AF_INET6)
memcpy(&fl6->daddr, &rt->rt_gw6, sizeof(fl6->daddr));
}skb_rtable() is a plain cast. Doesn't that mean rt_gw_family and rt_gw4/rt_gw6 are read from the metadata_dst's tun_info key bytes?
The reads stay inside the metadata_dst allocation, and rt is not used as the output route. The outer endpoint would still come from unrelated bytes, though.
Quoted 1 line
From the struct layouts,
rt_gw_familyappears to overlay the first byte of
key.u.ipv4.src. If so, a 10.x.x.x source address would look like AF_INET6 to ip6_tnl_xmit() and produce a bogus fl6->daddr.
The tunnel drivers calling skb_rtable() without skb_valid_dst() is not new. bpf_skb_set_tunnel_key() plus bpf_redirect() can already reach it. This patch adds another way to get there, though, and turns a configuration that used to transmit into one that always drops.
The same applies to __bpf_redirect_neigh_v6() when it hands packets to sit and ip6tnl NBMA devices.
Is this change in behaviour intended? Could the commit message mention it?
Quoted 2 lines
err =
bpf_out_neigh_v4(net, skb, dev, nh);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CORE-9NOG.v3.r0.20261115050625%40mojatatu.com
Re: [PATCH net-next v3 4/4] bpf: drop the stale dst when redirecting to an explicit nexthop
Quoted 12 lines · On Mon, Nov 16, 2026 at 5:48 AM <[email protected]> wrote:
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).
Quoted 5 lines
- [Medium] The commit message says the explicit-nexthop branch "never consults the route dst, so nothing that describes the route is lost".
- [Low] The patch fixes a user-visible bug but has no Fixes: tag, and its commit message does not say which earlier patches it needs.
For all of the patches in this patch set:
- i will send a v4 that fixes the commit logs and code comments you are complaining about. There is no code change coming.
- remember going forward, net-next does not require a Fixes tag.
pw-bot: cr
cheers,
jamal
Quoted 148 lines
--
bpf: drop the stale dst when redirecting to an explicit nexthop
The patch changes
__bpf_redirect_neigh_v4()and__bpf_redirect_neigh_v6(). When the BPF program supplies the nexthop, they now release the dst the packet arrived with, usingskb_dst_drop_keep_metadata(). This stops a frame parked on the target device'sarp_queuefrom being rebuilt later from the original route.net/core/filter.c static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev, · line 2323
Quoted 11 lines
net/core/filter.c +2
-0@@ -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; }[Severity: Low]
This isn't a runtime bug, but should this patch carry a Fixes: tag?In both
__bpf_redirect_neigh_v4()and__bpf_redirect_neigh_v6(), the if (!nh) { ...skb_dst_drop();skb_dst_set(); } block with no else branch for an explicit nexthop came from:
ba452c9e996d("bpf: Fixbpf_redirect_neighhelper api to support supplying nexthop")So the stale dst has been reachable since that commit. Something like this would get the fix into stable:
Fixes ba452c9e996d ("bpf: Fix bpf_redirect_neigh helper api to support supplying nexthop")The baseline tree also has no
skb_dst_drop_keep_metadata(). It is added earlier in this series by "net: dst: keep the LWT metadata of a dropped route".The
METADATA_XFRMdst it can install also depends on "net: xfrm: interface:
restoredst_origon every xfrm interface". Without that commit,xfrmi_xmit2()hits theskb_dst_set()warning, which panics underpanic_on_warn.Could the commit message name these prerequisites? A backport of this patch alone will not build. A backport with only the helper would bring back the xfrmi warning.
net/core/filter.c static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev, · line 2440
Quoted 9 lines
net/core/filter.c +2
-0err =bpf_out_neigh_v6 (net, skb, dev, nh);@@ -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; }[Severity: Medium]
The commit message says:That branch never consults the route dst, so nothing that describes the route is lost
That holds for
bpf_out_neigh_v4()andbpf_out_neigh_v6(). Does it also hold for the target device's xmit path when the target is an NBMA tunnel (ipip, gre, sit or ip6tnl with no remote address)?On those devices the neighbour is NOARP with direct output, so the BPF nexthop has no effect. The tunnel picks its outer endpoint from
skb_dst():tc egress prog
bpf_redirect_neigh(nbma_ifindex, &nh, ...)__bpf_redirect_neigh_v4() skb_dst_drop_keep_metadata() bpf_out_neigh_v4() neigh_output() -> dev_queue_xmit() ipip_tunnel_xmit() / ipgre_xmit() ip_tunnel_xmit()If the incoming route has no LWT state,
skb_dst_drop_keep_metadata()leaves the skb with no dst.ip_tunnel_xmit()then always drops the packet:net/ipv4/ip_tunnel.c:ip_tunnel_xmit() { ... dst = tnl_params->daddr; if (dst == 0) { /* NBMA tunnel */ if (!skb_dst(skb)) { DEV_STATS_INC(dev, tx_fifo_errors); goto tx_error; } ... }
ip6_tnl_xmit()goes totx_err_link_failurein the same situation, and sit'sipip6_tunnel_dst_find()returns false. Before this patch these configurations transmitted, usingrt_nexthop()of the original route.If the incoming route has
LWTUNNEL_ENCAP_IPorLWTUNNEL_ENCAP_IP6, the skb gets aMETADATA_IP_TUNNELmetadata_dstinstead. When thattun_infois not a usable IPv4 endpoint (encap ip6, or encap ip with no dst),ip_tunnel_xmit()falls through to:} else if (payload_protocol == htons(ETH_P_IP)) { rt = skb_rtable(skb); dst = rt_nexthop(rt, inner_iph->daddr); }and
ip6_tnl_xmit()does:} else if (payload_protocol == htons(ETH_P_IP)) { const struct rtable *rt = skb_rtable(skb); ... if (rt->rt_gw_family == AF_INET6) memcpy(&fl6->daddr, &rt->rt_gw6, sizeof(fl6->daddr)); }
skb_rtable()is a plain cast. Doesn't that meanrt_gw_familyand rt_gw4/rt_gw6 are read from the metadata_dst'stun_infokey bytes?The reads stay inside the
metadata_dstallocation, and rt is not used as the output route. The outer endpoint would still come from unrelated bytes, though.Quoted 1 line
From the struct layouts,
rt_gw_familyappears to overlay the first byte ofkey.u.ipv4.src. If so, a 10.x.x.x source address would look like
AF_INET6toip6_tnl_xmit()and produce a bogusfl6->daddr.The tunnel drivers calling
skb_rtable()withoutskb_valid_dst()is not new.bpf_skb_set_tunnel_key()plusbpf_redirect()can already reach it. This patch adds another way to get there, though, and turns a configuration that used to transmit into one that always drops.The same applies to
__bpf_redirect_neigh_v6()when it hands packets to sit and ip6tnl NBMA devices.Is this change in behaviour intended? Could the commit message mention it?
Quoted 2 lines
err = bpf_out_neigh_v4(net, skb, dev, nh);--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CORE-9NOG.v3.r0.20261115050625%40mojatatu.com