πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25799

Re: [PATCH 15/22] net: xfrm: interface: restore dst_orig on every xfrm interface

#25799
From: netdev-bot+sashiko
Date: Wed, 02 Dec 2026 13:12
120 lines
12589 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 message leaves out the most serious production impact
  of the per-cpu design that this patch removes.
- [Low] The patch carries 'Cc: stable@vger.kernel.org' and 'Fixes:
  94151f5aa966' (Dec 2022, v6.2 cycle), but it depends on helpers that…

--

net: xfrm: interface: restore dst_orig on every xfrm interface

This patch makes xfrmi_xmit2() restore md_info->dst_orig for both
collect_md interfaces and interfaces with a configured if_id. It takes its
own reference with dst_clone() and drops the metadata dst from the skb
before installing the route. It also changes bpf_skb_set_xfrm_info() to
allocate a metadata dst per skb instead of using the shared per-cpu
xfrm_bpf_md_dst, which is removed.

Link: https://lore.kernel.org/netdev/DMZJS8O5A4YX.9T2P4DT0DAB7@gmail.com/

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

[Severity: Low]

This isn't a bug in the code. But does this paragraph understate what the
per-cpu design did on production kernels built without CONFIG_DEBUG_NET?

In the old bpf_skb_set_xfrm_info(), the skb's counted reference on its
route was moved into the shared per-cpu metadata dst and never dropped:

	skb_dst_force(skb);
	info->dst_orig = skb_dst(skb);

	dst_hold((struct dst_entry *)md_dst);
	skb_dst_set(skb, (struct dst_entry *)md_dst);

Only one path gave that reference back: the collect_md arm of
xfrmi_xmit2(), which cleared md_info->dst_orig and kept the route on the
skb.

Any other packet left its route reference in
this_cpu_ptr(xfrm_bpf_md_dst). That covers a packet dropped after the
helper, a packet redirected to a non-xfrm device, and a packet sent
through an xfrm interface with a configured if_id.

The next call to the helper on that CPU overwrote info->dst_orig. The
per-cpu object is never freed, so metadata_dst_free() never got to run
this:

	if (md_dst->type == METADATA_XFRM)
		dst_release(md_dst->u.xfrm_info.dst_orig);

So it looks like one dst reference leaked for every such packet.

Also, if_id, link and dst_orig lived in a per-cpu object rather than in
each packet. A packet held in a qdisc between the helper and xfrmi_xmit2()
could then pick up another packet's if_id and route, or find dst_orig
already cleared. Is that right?

The fix description only says the route "belongs to that skb and is
released with it". Could the message also name the dst reference leak and
the mixing of metadata between packets, next to the DEBUG_NET warning and
the dropped packet?

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

[ ... ]

> @@ -86,7 +79,11 @@ __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 metadata dst releases dst_orig when it is freed, so the
> +	 * reference the skb held is stolen rather than dropped. The dst
> +	 * allocated above is handed to the skb with its single reference.
> +	 */
> +	skb_dstref_steal(skb);

[Severity: Low]

The patch carries Cc: stable and Fixes: 94151f5aa966, which dates from
the v6.2 cycle. skb_dstref_steal() was only added in August 2025, by
commit c3f0c02997c7f8.

Will this build on stable branches that contain the Fixes target but not
that commit, such as 6.6.y or 6.12.y?

The reproducer in the commit message also looks specific to newer
kernels:

  so the first packet that calls it panics inside bpf_skb_set_xfrm_info() on
  a CONFIG_DEBUG_NET=y build with panic_on_warn=1.

That warning is the DEBUG_NET_WARN_ON_ONCE() in skb_dst_check_unset(),
which skb_dst_set() calls. It was added by commit a890348adcc993, also in
August 2025. On older stable kernels skb_dst_set() overwrites the slot
without warning, so the stated reproducer would not trigger there.

Should the commit message name these dependencies, or point to an adapted
backport for older trees, for example one that clears skb->_skb_refdst
directly?

>  	skb_dst_set(skb, (struct dst_entry *)md_dst);
>  	return 0;
>  }

-- 
Sashiko AI review Β· https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201124252.1163254-2-steffen.klassert%40secunet.com
Technical Details
Message-ID: <179621715052.3146.1140038363639422089@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375799-linux-kernel-netdev=dewy.ru
References: <20261201124252.1163254-16-steffen.klassert@secunet.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375799-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH 15/22] net: xfrm: interface: restore dst_orig on every
 xfrm interface
Date: Wed, 02 Dec 2026 13:12:30 +0000
Organization: Usenet Network
Message-ID: <179621715052.3146.1140038363639422089@kernel.org>
References: <20261201124252.1163254-16-steffen.klassert@secunet.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1977035"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:t6cu5dWIX+CE8njYUzzdWcmVUXU= sha256:ovG6G48e+akwjDPrUmrK0mkztxed+zwfqgiu0wxXvgI=
	sha1:X3RMfE5lSayfiAESkitl31qoi/I= sha256:xMJkL3wkiXKq6xOz+0AGBuu1cruIwCEeGvv8J1Z2Jv0=
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 3B447117649; Wed,  2 Dec 2026 16:12:53 +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 VEA8vFhicOy5;
	Wed,  2 Dec 2026 16:12:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375799-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 034B3117646; Wed,  2 Dec 2026 16:12:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id BFD472C363; Wed,  2 Dec 2026 13:12:32 +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=1796217152;
	b=byxE3stjn93JuI5Yyt3KB/CbJtq53cmElN7VdO0bQ5BvTzbd7coSlueDvjX1U3U5kuf7
	 ocYD/64qnH9Mcx4aE+jsR8j8tW+XwZJ0d8OiTVflYEWT7amvaYCAUEPAZuBWahJN4aEdw
	 9d2uAlwD/ttxmy4PCsXHZNi0+jEJrW+6jii/nK4IDCI+FPvvvShKhx+rzhC6gQRo8eGyb
	 rmrZmhiNv373+bmNerFY7QvF1fKoS1RFFelZBHziMwC4KPNuKMqyiUAlGiNGevosqRoYS
	 1ml2JRlBlNNW5GrP3HxdFtLETuUGAqQHR3FUALIuUxMaXtaDu1s45rbPKAn+YGrzKvw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796217152;
	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=cM43TUjLgHvFUZ4Y1b07pQ0kbmXf17FVZu4yPdjTW5o=;
	b=aYUXLVTAPD9t6ZttXo53cKfM3ARuU3UQdRISjFnlG6IR6B3pBWP2Jqmkfjyh2FFAbfqr
	 +UHZWwdakDknHX9rhECnyewDJynaJcsqF/MxrM5gic184DUWGGVYae6NEwy20HhZs50XJ
	 nlWsX4MAxqFF4BXf8plGTcAkRow0tWhnpdB7yXMpI6yHX9C8N9P7E/Par3E9LaiCh6nOy
	 keJPnFLJVvh80i0OL8g+ODTwSSRJNw50Mdzy8iuH2pUU0HfzFiWzOCPapp5UJHMNtcfNi
	 h/zRymazVrBNegzxevarGYTtn21sqqUgQ1K+rjhuzoCQGlaVnuVBS3bBlr/LbwLipog==
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=VDQW50AB;
	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 2F290606A32E;
	Wed,  2 Dec 2026 13:12:32 +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=VDQW50AB
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=1796217151;
	b=kiIztvkCAIpi2/ZIRlYKclBiVI0HVLp/jIB0Duiz4ED5G1rZS3KI7bnCU5qSBk3daHkX
	 WrKHaVqZ+UAC2xyySLnhPH+VSJhXZWKuVYhrq2dVxUDHFN6xnjiDGtw6PsHFrkvi5tPY1
	 klIZlhleaCQTnbogiuFtXRfCsj7jorwuWJQns3jRVzUy3Ln5aGNrAz6sk8UejddKfZNA4
	 yTUv7Qx10MKR1iupb/wLdYVcc87zEFd3VMZxEYZLeuiOBQH8nGviyQNbVDj8GPM59jIFO
	 yGBqjsjcUD6zOLoIDImSGp4ddHf30FpwjDA8lCWrC+J9TuC/pNDPQNg+cEhNXe5MU0Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796217151;
	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=cM43TUjLgHvFUZ4Y1b07pQ0kbmXf17FVZu4yPdjTW5o=;
	b=2ZyxnL6RROqXbEwCOVew2sjqGGCNPQSVAAZF6PfaPChiRD4lLehlBZaqF5wGaWG+Yxik
	 Q5iI8lgR9moNYOf4Q1Ht9dXqxZtGGjwkwQMPBS1KUN2BFqxcx+V/jMauyWCeyStORNF08
	 c+/rAa1dNiHoFcMuvkW2+MQAiOPrlvrGTXr3Q5NNEsUtka8gMQ78rJdn59XufZKbwQya8
	 in3g7f22qaRPETwHJDvlAFncSEeIqsUYyvvhlKOrsNkhFFfDngl3Mp0wz/oIct8TM48c/
	 3hM7el2KROea+lFHb6GSp2WQ9jMi72YGAyGUbtmYU9yBncrbVBALuD21e6oZcH4h6fA==
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=VDQW50AB;
	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 5198C606A327
	for <netdev@vger.kernel.org>; Wed,  2 Dec 2026 13:12:31 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5CC71F000C1;
	Wed,  2 Dec 2026 13:12:30 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796217151;
	bh=cM43TUjLgHvFUZ4Y1b07pQ0kbmXf17FVZu4yPdjTW5o=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=VDQW50ABeJyKl5SSbTH1Wcom/yVypaOdKQnuXCoVd6qwnuDrbNLE+Y88IKydIGEmB
	 vgARRxLPTQGgw8De5VUVkItqXZwirseuMbV/XsDMgEjYwHzi8Crh+gle3HjtcSor2P
	 I5nwMiHCFrmECxOW0oZ2QrSccAfHTA62hISAapV3d1sJUTmIeazVGicqjKegYhGs+4
	 Vs1tCnwLTl9ubWm63d3e8/HG22HBxKy20EYdliCEVl+93boU+sGCVHbLV+JIiUnUAr
	 PtLGWxphQn4OoR3eu1ZmaxCJv/NKvHG1bGYDoej86muqwYlsSOCoBxmlN/saR8lNWK
	 Ow6G5UkLRaguw==
X-Cc: davem@davemloft.net, kuba@kernel.org, herbert@gondor.apana.org.au,
 netdev@vger.kernel.org
X-In-Reply-To: <20261201124252.1163254-16-steffen.klassert@secunet.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