Re: [PATCH net] seg6: fix NULL deref in input_action_end_dx{4,6}_finish() after nf hook
From: Xiang Mei
Date: Tue Jul 28 2026 - 17:21:13 EST
On Thu, Jul 23, 2026 at 10:22 AM Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> wrote:
>
> On Mon, Jul 20, 2026 at 08:44:29PM +0000, Xiang Mei (Microsoft) wrote:
> > When nf_hooks_lwtunnel is enabled, the End.DX4/End.DX6 actions dispatch
> > the decapsulated inner packet through the NF_INET_PRE_ROUTING hook chain
> > with input_action_end_dx{4,6}_finish() as the okfn. Both functions read
> > the lwtunnel state via orig_dst = skb_dst(skb) and dereference
> > orig_dst->lwtstate.
> >
> > A hook in that chain can legitimately drop the dst: nf_nat_ipv{4,6}_in()
> > calls skb_dst_drop(skb) when a DNAT rule rewrites the destination
> > address, leaving skb_dst(skb) NULL. The okfn then dereferences a NULL
> > orig_dst, causing a general protection fault and a panic (the fault
> > happens in softirq NAPI receive context).
> >
> > Free the skb and bail out when the dst was dropped, instead of
> > proceeding with a lost lwtunnel state.
> >
> > Oops: general protection fault, probably for non-canonical address...
> > KASAN: null-ptr-deref in range [0x0000000000000080-0x0000000000000087]
> > RIP: 0010:input_action_end_dx6_finish (net/ipv6/seg6_local.c:912)
> > Call Trace:
> > input_action_end_dx6 (net/ipv6/seg6_local.c:946)
> > seg6_local_input_core (net/ipv6/seg6_local.c:1621)
> > seg6_local_input (net/ipv6/seg6_local.c:1643)
> > lwtunnel_input (net/core/lwtunnel.c:465)
> > ipv6_rcv (net/ipv6/ip6_input.c:351)
> > __netif_receive_skb_core.constprop.0 (net/core/dev.c:6165)
> > Kernel panic - not syncing: Fatal exception in interrupt
> >
> > Fixes: 7a3f5b0de364 ("netfilter: add netfilter hooks to SRv6 data plane")
> > Reported-by: AutonomousCodeSecurity@xxxxxxxxxxxxx
> > Signed-off-by: Xiang Mei (Microsoft) <xmei5@xxxxxxx>
> > ---
> > net/ipv6/seg6_local.c | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> > diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
> > index 2b41e4c0dddd..45e66ba306ca 100644
> > --- a/net/ipv6/seg6_local.c
> > +++ b/net/ipv6/seg6_local.c
> > @@ -909,6 +909,11 @@ static int input_action_end_dx6_finish(struct net *net, struct sock *sk,
> > struct in6_addr *nhaddr = NULL;
> > struct seg6_local_lwt *slwt;
> >
> > + if (!orig_dst) {
>
> This should be:
>
> if (!skb_valid_dst(orig_dst)) {
>
That's correct, thanks. v2 gonna use it. Two small notes.
skb_valid_dst() takes the skb, not the dst.
The lwtstate NULL test is still needed on top. A hook can leave a valid
route that has no lwtunnel state, and seg6_local_lwtunnel() would then
read lwt->data off NULL.
So v2 has:
static struct seg6_local_lwt *seg6_local_lwt_from_skb(struct sk_buff *skb)
{
struct dst_entry *dst = skb_dst(skb);
if (!skb_valid_dst(skb) || !dst->lwtstate ||
dst->lwtstate->type != LWTUNNEL_ENCAP_SEG6_LOCAL)
return NULL;
return seg6_local_lwtunnel(dst->lwtstate);
}
Xiang
> > + kfree_skb(skb);
> > + return -EINVAL;
> > + }
> > +
> > slwt = seg6_local_lwtunnel(orig_dst->lwtstate);
> >
> > /* The inner packet is not associated to any local interface,
> > @@ -962,6 +967,11 @@ static int input_action_end_dx4_finish(struct net *net, struct sock *sk,
> > struct iphdr *iph;
> > __be32 nhaddr;
> >
> > + if (!orig_dst) {
>
> Same here.
>
> > + kfree_skb(skb);
> > + return -EINVAL;
> > + }
> > +
> > slwt = seg6_local_lwtunnel(orig_dst->lwtstate);
> >
> > iph = ip_hdr(skb);
> > --
> > 2.43.0
> >