Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: jhs@mojatatu.com
Cc: netdev@vger.kernel.org, pablo@netfilter.org, fw@strlen.de,
	phil@nwl.cc, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	jiri@resnulli.us, victor@mojatatu.com, sashiko-bot@kernel.org
Subject: Re: [PATCH net-next v3 1/4] net: xfrm: interface: restore dst_orig on every xfrm interface
Date: Mon, 16 Nov 2026 10:48:13 +0000	[thread overview]
Message-ID: <179482609307.3136.802369385137912510@kernel.org> (raw)
In-Reply-To: <CORE-9NOG.v3.r0.20261115050625-1@mojatatu.com>

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.

> 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

[ ... ]

> 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.

[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.

> diff --git a/net/xfrm/xfrm_interface_bpf.c b/net/xfrm/xfrm_interface_bpf.c
> index 5ea15037ebd10..8e83c624b774a 100644
> --- a/net/xfrm/xfrm_interface_bpf.c
> +++ b/net/xfrm/xfrm_interface_bpf.c

[ ... ]

> @@ -86,7 +79,8 @@ __bpf_kfunc int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx, const struct bp
>  	skb_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.

> diff --git a/net/xfrm/xfrm_interface_core.c b/net/xfrm/xfrm_interface_core.c
> index 9835fbe63ccb8..896180f8d1719 100644
> --- a/net/xfrm/xfrm_interface_core.c
> +++ b/net/xfrm/xfrm_interface_core.c

[ ... ]

> @@ -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);
> -		}

[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:

Fixes: 94151f5aa966 ("xfrm: interface: Add unstable helpers for setting/getting XFRM metadata from TC-BPF")

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.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CORE-9NOG.v3.r0.20261115050625%40mojatatu.com

  reply	other threads:[~2026-11-16 10:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 10:19 [PATCH net-next v3 0/4] net: drop the stale dst when steering to another device Jamal Hadi Salim
2026-11-15 10:19 ` [PATCH net-next v3 1/4] net: xfrm: interface: restore dst_orig on every xfrm interface Jamal Hadi Salim
2026-11-16 10:48   ` netdev-bot+sashiko [this message]
2026-11-15 10:19 ` [PATCH net-next v3 2/4] net: dst: keep the LWT metadata of a dropped route Jamal Hadi Salim
2026-11-16 10:48   ` netdev-bot+sashiko
2026-11-15 10:19 ` [PATCH net-next v3 3/4] netfilter: nft_fwd_netdev: drop the stale dst when steering to a device Jamal Hadi Salim
2026-11-16 10:48   ` netdev-bot+sashiko
2026-11-15 10:19 ` [PATCH net-next v3 4/4] bpf: drop the stale dst when redirecting to an explicit nexthop Jamal Hadi Salim
2026-11-16 10:48   ` netdev-bot+sashiko

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=179482609307.3136.802369385137912510@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=sashiko-bot@kernel.org \
    --cc=victor@mojatatu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox