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@microsoft.com Signed-off-by: Xiang Mei (Microsoft) --- 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) { + 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) { + kfree_skb(skb); + return -EINVAL; + } + slwt = seg6_local_lwtunnel(orig_dst->lwtstate); iph = ip_hdr(skb); -- 2.43.0