🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17055

Re: [PATCH net-next v3 1/4] net: xfrm: interface: restore dst_orig on every xfrm interface

#17055
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 10:48
165 lines
14028 bytes
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
Technical Details
Message-ID: <179482609307.3136.802369385137912510@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364203-linux-kernel-netdev=dewy.ru
References: <CORE-9NOG.v3.r0.20261115050625-1@mojatatu.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364203-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179482609307.3136.802369385137912510@kernel.org>
References: <CORE-9NOG.v3.r0.20261115050625-1@mojatatu.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2038257"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:vB06n5KM6GVv1Tsdwcwr8ogS8qM= sha256:sWNtUe93BIKt+dukyW+GL/Fmr3WU7GrVUBkyuL6ti7o=
	sha1:uTY+JMazf5Du4MDh1fzVEQmnJvc= sha256:Q+jS2CYVys+oiD0omXbWtVjy+SDR2l0xl9NxppBUmu8=
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 27CAB114BA8; Mon, 16 Nov 2026 13:48:39 +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 MYk0_-PCqd2n;
	Mon, 16 Nov 2026 13:48:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-364203-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 28D19114BA5; Mon, 16 Nov 2026 13:48:26 +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 50C0A27B3A; Mon, 16 Nov 2026 10:48:22 +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=1794826100;
	b=x5mMW5tHV69glk+kgH7/mhhrk+LtdxQuM0/9U9E4JsfAPqtyd65d3Q/iRXcOoiliJ0aK
	 Rt4ZKaDoZSa7v8YUFsorkOmavIcqm3XJk+/fqIfKhwvE+5ZtISSuohhUCuH3gZSYOBWPx
	 6tj6uBCykjwjHzJx+ULULSRfzrCA5Z4IHMhOMGe950eeTWBGw+D26L01EU2MiUVQBEbFw
	 zg4zPu458h2QU7TIs+AEAh17P014i15CsrH01Ffjng+Cx1B2WYWc5+Kg7zL1C3pw5TR0g
	 J/faBDVvf7ov7nJwUATE1wUIzch0MeLGMSGBocuGRi5WzJj4/sxaLRHklSYnEk7rmQg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794826100;
	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=bpAqt3vkpgdi9prEru8xJMcJCmuHua0RnlTvNxptGDE=;
	b=FKjlkfOtX9ccocjf3c7ANKEUUg4DE6NTpSGa+BcYLmvrMGxd1+1FFr/cxkEXrmI0/csS
	 f1tbkFUsZrVGjn9Nfn7xObtrL1WQ985fN9lzC1HQEw2NmBttw2i6Odb1fBmrL0R0M0u7y
	 LhVbRw3bVOlj//vORGwLJ5ydbnWzVxDagILoiENFwp0Dkc2dtCOPPc6Plvc+3xSf0H0NR
	 4wrMUB6xVETIam/kr9LMI/fjJkn8GfmpYsv3/FmzyPxgeYHI4OIz032p9/0aBXw0jxwkH
	 +DRK/TYLzB/miPL17SsQZ7iCMJqsHowNN4882DHjkF5Xl+cXQAZUiWlDkjTIY3fZDgQ==
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=nYZGuI9H;
	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 956E3606A891;
	Mon, 16 Nov 2026 10:48:20 +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=nYZGuI9H
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=1794826094;
	b=WRNFOqyHTG5ly3TaR0UUjcKx8uRW1xWAM26AL1zj1gwaQXYYjRmNDsmMLjJh+Ky33ESy
	 htAa/HIYe//cTKQPgtlenTxXDMPBrzUDDcPGFlMRtsMFI0kyzP0A4oFH9JF0KkwlJT4CX
	 SSupBQwbUVuF+eGLzI5YyEMPF54XgGj7rU8/mAtUTG39zdkR9HtL0qMiuOCSwciG9sELD
	 iabNnFAoGPXbRaWXFtmDzBZlXYxMZUuEIlTZN3hTQOJyqFFr4NgPr3GkEAp58+dyLHpbG
	 LTjfsyfTe4ESKVAlZSfD5moOYu/FvgqZ8iWhHreYuBTzV3vCwxNuODm6gfs4crfIEYA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794826094;
	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=bpAqt3vkpgdi9prEru8xJMcJCmuHua0RnlTvNxptGDE=;
	b=DCv1neZTv4xQw5+tpw86NH7lSP9t0ebChPSvzgZrdpdOXkQLDFX16e7AQ6vKIedyn+LM
	 xdGb0SCORwRVuDw5h13JXgKw46C3MiKiYQz6aGQCPSKPSlfru4/hew+dH+1Nlj+YOJ9Du
	 42RaNibE2jFazs5FITco/NzQEuGiRy+asQ1XxH71o6ixiT5+XVLtiAIj271fyLhuKEJoD
	 J/9bS1WCRAC0Dp1WZNb15CRoI2BXwiJLfMvtyDkA6eDlcZ4Uh577xOvF0L3u3JQ29XhSw
	 2Z8Z8/cWkBfVcjSpJYrpb8BDcV+B4QdGR0jtnA6KaKbk+0Lf+9STbs+DafmJeDqPqOg==
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=nYZGuI9H;
	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 B4C4E606A323;
	Mon, 16 Nov 2026 10:48:14 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CBF71F000C4;
	Mon, 16 Nov 2026 10:48:13 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794826094;
	bh=bpAqt3vkpgdi9prEru8xJMcJCmuHua0RnlTvNxptGDE=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=nYZGuI9HsutNv7MNlehITYeIvk9DkMW7zVq7//uSS8bGVGe9ULAarbQSc6IlWw28X
	 NSWpo2ZnDhLUJTHXFtYF3w/ZYtLWJUGliz3ABwd0yK8wGjzTX9tp0eqjst6nKngig4
	 45YRBXH4S0B/kfPN7f8CV3tR/DM4CJT090kqC4ndX2NqVj2VYHoJC2kVG2w/c/76av
	 UGWn8ToSWlxH/rlc/KTRHN1BN+OGB3kWdIygcGPBNprSYNMCdfHcFQ4BQf1wzkNjov
	 kzrVwhxQVn0+4wPNE8wxsEr4ZfcPM7XOk+IdKBEtNoU8uTtPrJp2vzyDgKm2BFW2zV
	 2KjvsT3njCaAQ==
X-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
X-In-Reply-To: <CORE-9NOG.v3.r0.20261115050625-1@mojatatu.com>
X-sashiko-severity: Low
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