🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Andrea Mayer Tue, 20 Oct 2026 23:41
Re: [PATCH net v2 1/1] seg6: validate state in netfilter continuations
#5779
Author: Andrea Mayer
Date: Tue, 20 Oct 2026 23:41
157 lines
16289 bytes
On Sun, 18 Oct 2026 14:27:29 +0800
Ren Wei <weir@nebusec.ai> wrote:

Hi,

Thanks for the v2.

> From: Zixuan Chai <petalzu987@gmail.com>
>
> Netfilter hooks can drop or replace skb_dst() while an SRv6 packet is
> queued for continuation. The End.DX4 and End.DX6 finish callbacks and
> the seg6local input continuation currently dereference the destination's
> lwtstate without validating it. The seg6_iptunnel input and output
> continuations make the same assumption after POST_ROUTING hooks.
>
> Validate skb_valid_dst(), a non-NULL lwtstate, and the expected
> LWTUNNEL_ENCAP_SEG6_LOCAL or LWTUNNEL_ENCAP_SEG6 type before using the
> state. Drop the skb when validation fails. This check is by type, not by
> identity of the original state. It does not walk through an XFRM dst or
> take an additional lwtstate reference. Retain the loop-detection
> explanation for saving the lwtstate address in seg6_input_core().

The last two sentences seem to repeat the "Changes in v2" entries. What
changed from the previous version goes only below the "---".

>
> The End.DX4 reproducer creates a SEG6_LOCAL End.DX4 SID, enables
> nf_hooks_lwtunnel, installs an IPv4 PREROUTING DNAT rule, and injects an
> outer IPv6/inner IPv4 frame through AF_PACKET from a non-root user in a
> fresh user/network namespace. DNAT drops skb_dst() before
> input_action_end_dx4_finish() resumes.
>
> A separate root-only reproducer exercises seg6_output_core(): an SRv6
> encap route, POST_ROUTING SNAT, and an ESP transport policy replace the
> route destination before the continuation resumes.
>
> On a clean KASAN kernel, the End.DX4 reproducer triggered a NULL pointer
> dereference in input_action_end_dx4_finish from packet_sendmsg(). On the
> patched kernel, the End.DX4 reproducer completed with exit status 0. The
> SNAT+ESP/XFRM reproducer ran twice; one run returned exit status 0. No
> target KASAN report, Oops, or kernel panic was found on the patched
> guest. Tests used QEMU TCG because KVM was unavailable to the test user.

The message gives the clean-kernel result only for End.DX4. What does the
SNAT+ESP/XFRM reproducer do there?

> Fixes: 7a3f5b0de364 ("netfilter: add netfilter hooks to SRv6 data plane")
> Cc: stable@vger.kernel.org
> Reported-by: Vega <vega@nebusec.ai>
> Closes: https://bugtracker.nebusec.ai/f/11977

As Hangbin noted, this link is not public: it asks for a login. A
Closes: tag should point to a public report. The Reported-by can stay.

> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260720204430.1886091-1-xmei5@asu.edu
> Assisted-by: LLM
> Signed-off-by: Zixuan Chai <petalzu987@gmail.com>
> Signed-off-by: Ren Wei <weir@nebusec.ai>
>
> ---
> Changes in v2:
> - Add unlikely() to the new checks.
> - Validate the current dst/lwtstate type in both seg6local and
>   seg6_iptunnel continuations; drop invalid state.
> - Do not walk through XFRM dsts or take an extra lwtstate reference.
> - Retain the seg6_input_core() loop-detection comment.
> - Document both reproducer setups and clean/patched KASAN results.
> - v1 Link: https://lore.kernel.org/all/cover.1790748418.git.petalzu987@gmail.com/
>
> [snip]
>
> @@ -557,7 +573,6 @@ static int seg6_input_finish(struct net *net, struct sock *sk,
>  static int seg6_input_core(struct net *net, struct sock *sk,
>  			   struct sk_buff *skb)
>  {
> -	struct dst_entry *orig_dst = skb_dst(skb);
>  	struct dst_entry *dst = NULL;
>  	struct lwtunnel_state *lwtst;
>  	struct seg6_lwt *slwt;
> @@ -568,7 +583,11 @@ static int seg6_input_core(struct net *net, struct sock *sk,
>  	 * need the address of its lwtstate. So, save the address of lwtstate
>  	 * now and use it later as a comparison.
>  	 */
> -	lwtst = orig_dst->lwtstate;
> +	lwtst = seg6_lwt_state_from_skb(skb);
> +	if (unlikely(!lwtst)) {
> +		err = -EINVAL;
> +		goto drop;
> +	}

The first line of this comment still names orig_dst, but this patch
removes orig_dst.

[snip]

One more point, on where the check runs. Checking the state and dropping
the packet looks fine. The same check can also live in the okfn passed to
NF_HOOK(). There it runs only when nf_hooks_lwtunnel is on, which is when
a hook can change the dst. With End.DX4 as an example:

  Before this patch, nf_hooks_lwtunnel off (the default): no check.

  This patch, nf_hooks_lwtunnel off:

    lwtunnel_input()                  [dispatch on lwtstate->type]
      seg6_local_input()
        seg6_local_input_core()       [check 1: same dst, cannot fail]
          input_action_end_dx4()
            input_action_end_dx4_finish()
                                      [check 2: same dst, cannot fail]

  Check in the okfn, nf_hooks_lwtunnel on:

    lwtunnel_input()                  [dispatch on lwtstate->type]
      seg6_local_input()
        NF_HOOK(LOCAL_IN)             [dst may change]
          okfn: check, then seg6_local_input_core()
            input_action_end_dx4()
              NF_HOOK(PRE_ROUTING)    [dst may change]
                okfn: check, then input_action_end_dx4_finish()

  Check in the okfn, nf_hooks_lwtunnel off: no check, as before this patch.

seg6_input_core() and seg6_output_core() are in a similar situation.
Before this patch, the nf_hooks_lwtunnel_enabled static key kept the
netfilter code off this path. Without CONFIG_NETFILTER the sysctl that
turns the key on is not even built, and the checks added by this patch
still run on every packet.

In code, for End.DX4, something like (just an example):

	static int input_action_end_dx4_finish_nf(struct net *net,
						  struct sock *sk,
						  struct sk_buff *skb)
	{
		if (unlikely(!seg6_local_lwt_from_skb(skb))) {
			kfree_skb(skb);
			return -EINVAL;
		}

		return input_action_end_dx4_finish(net, sk, skb);
	}

input_action_end_dx4_finish() itself does not change, and the price is
one tiny wrapper like this for each of the five core functions, in place
of the check at the top of each of them.

With the check inside the core functions, it runs on every path, also
where it cannot fail. With the wrapper, it runs only on the NF_HOOK()
path. I would like to hear your opinions on this.

Thanks,

Ciao,
Andrea
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads