Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: steffen.klassert@secunet.com
Cc: davem@davemloft.net, kuba@kernel.org,
	herbert@gondor.apana.org.au, netdev@vger.kernel.org
Subject: Re: [PATCH 15/22] net: xfrm: interface: restore dst_orig on every xfrm interface
Date: Wed, 02 Dec 2026 13:12:30 +0000	[thread overview]
Message-ID: <179621715052.3146.1140038363639422089@kernel.org> (raw)
In-Reply-To: <20261201124252.1163254-16-steffen.klassert@secunet.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 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

  reply	other threads:[~2026-12-02 13:12 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 12:41 [PATCH 0/22] pull request (net): ipsec 2026-12-01 Steffen Klassert
2026-12-01 12:41 ` [PATCH 01/22] xfrm: ipcomp: account full fragment pages in truesize Steffen Klassert
2026-12-01 13:36   ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 02/22] xfrm: esp: reset outer TCP GSO metadata on espintcp input Steffen Klassert
2026-12-01 12:41 ` [PATCH 03/22] xfrm: keep the mode module pinned until destroy_state returns Steffen Klassert
2026-12-01 12:41 ` [PATCH 04/22] xfrm: serialize SA activation with state deletion Steffen Klassert
2026-12-01 12:41 ` [PATCH 05/22] xfrm: keep old state references until migration deletion completes Steffen Klassert
2026-12-01 12:41 ` [PATCH 06/22] xfrm: hold migrated states through rollback Steffen Klassert
2026-12-01 12:41 ` [PATCH 07/22] xfrm: check inner family via skb_dst for small_ipv6 DF clearing Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len() Steffen Klassert
2026-12-01 12:41 ` [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 10/22] xfrm: fix IPv6 first-fragment protocol decode Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 12/22] xfrm: espintcp: read the socket error queue for MSG_ERRQUEUE Steffen Klassert
2026-12-01 12:41 ` [PATCH 13/22] xfrm: iptfs: force a dst reference before queueing an skb Steffen Klassert
2026-12-01 13:36   ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 14/22] xfrm: espintcp: select receive path by skb protocol Steffen Klassert
2026-12-01 12:41 ` [PATCH 15/22] net: xfrm: interface: restore dst_orig on every xfrm interface Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko [this message]
2026-12-01 12:41 ` [PATCH 16/22] xfrm: iptfs: make room before copying a continuation in reassembly Steffen Klassert
2026-12-01 12:41 ` [PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy Steffen Klassert
2026-12-01 12:41 ` [PATCH 18/22] xfrm: Give GC list nodes their own storage Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 19/22] xfrm: Serialize device state teardown Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 20/22] xfrm: Wait for an RCU grace period before freeing device state Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush" Steffen Klassert
2026-12-02 13:12   ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 22/22] xfrm: Serialize offload stats updates with x->lock Steffen Klassert

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=179621715052.3146.1140038363639422089@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=steffen.klassert@secunet.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