From nobody Fri Apr 3 03:02:34 2026 Received: from mail115-63.sinamail.sina.com.cn (mail115-63.sinamail.sina.com.cn [218.30.115.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E90F533E7 for ; Wed, 25 Mar 2026 01:47:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=218.30.115.63 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774403258; cv=none; b=q/29qqyh7bxfRYMtg40WQMc+r6pV13tiBVuY7PCKZY5CvpL+eo008NvAN4pp/ZJ08NUOv46sACSxNSakpzzUtPU0/cMp84CV6ZbUMPO827OAPw/rwIsev2p+6r4JekR5M/MlkyfJnzwVLj1vp0wJX0fCu9hsfungNivGXGhMq2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774403258; c=relaxed/simple; bh=y3wUchI4euG087/dGBLCL/DR030jRj50L8viLMeI5wE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=o9cGMRjQczTBwxb9c+qr9eaWRJpklH9KyGBWmH6/h6nXAALASAU47dh/yedpB1wzgYzm3HepSt+GOm0tbfL0Qa8GQBqZu1tS6DreNHF86Gl9BbCtGdxwMPHro1ZPP3trDsJX5iHreAjFmxc04VNPZKy36fD1ml+uiGjzGdJskIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.com; spf=pass smtp.mailfrom=sina.com; dkim=pass (1024-bit key) header.d=sina.com header.i=@sina.com header.b=MS5/j0+Q; arc=none smtp.client-ip=218.30.115.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=sina.com header.i=@sina.com header.b="MS5/j0+Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sina.com; s=201208; t=1774403255; bh=k3X39rrnC7SX6DJDzJdrtuGNS4llrt1fQ3S0axsiZOg=; h=From:Subject:Date:Message-Id; b=MS5/j0+QiW8HBXVddmhCBpZN5xBNWPrurQGQjH4JSc8e1smzKBhFmVwh8NTxoDFch AnMPIWQNQPZ0aSbokwiZBzuVG0d4NtsfsagZGIZA2Bve5zYEXO5q56Zsk7gtBZ7NII ShCZLqGwjQ/NEWBo/5S6VIERWZSwDREVVvH4Xvy4= X-SMAIL-HELO: pek-lpg-core6.wrs.com Received: from unknown (HELO pek-lpg-core6.wrs.com)([60.247.85.88]) by sina.com (10.185.250.22) with ESMTP id 69C33E200000708D; Wed, 25 Mar 2026 09:45:06 +0800 (CST) X-Sender: johnny_haocn@sina.com X-Auth-ID: johnny_haocn@sina.com Authentication-Results: sina.com; spf=none smtp.mailfrom=johnny_haocn@sina.com; dkim=none header.i=none; dmarc=none action=none header.from=johnny_haocn@sina.com X-SMAIL-MID: 9224317602261 X-SMAIL-UIID: 0FF4B9B0FA884FD9B072ED988F877CFE-20260325-094506-1 From: Johnny Hao To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jakub Kicinski , =?UTF-8?q?Maciej=20=C5=BBenczykowski?= , Daniel Borkmann , Willem de Bruijn , Johnny Hao Subject: [PATCH 5.15.y] net: clear the dst when changing skb protocol Date: Wed, 25 Mar 2026 09:45:04 +0800 Message-Id: <20260325014504.2853667-1-johnny_haocn@sina.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Jakub Kicinski [ Upstream commit ba9db6f907ac02215e30128770f85fbd7db2fcf9 ] A not-so-careful NAT46 BPF program can crash the kernel if it indiscriminately flips ingress packets from v4 to v6: BUG: kernel NULL pointer dereference, address: 0000000000000000 ip6_rcv_core (net/ipv6/ip6_input.c:190:20) ipv6_rcv (net/ipv6/ip6_input.c:306:8) process_backlog (net/core/dev.c:6186:4) napi_poll (net/core/dev.c:6906:9) net_rx_action (net/core/dev.c:7028:13) do_softirq (kernel/softirq.c:462:3) netif_rx (net/core/dev.c:5326:3) dev_loopback_xmit (net/core/dev.c:4015:2) ip_mc_finish_output (net/ipv4/ip_output.c:363:8) NF_HOOK (./include/linux/netfilter.h:314:9) ip_mc_output (net/ipv4/ip_output.c:400:5) dst_output (./include/net/dst.h:459:9) ip_local_out (net/ipv4/ip_output.c:130:9) ip_send_skb (net/ipv4/ip_output.c:1496:8) udp_send_skb (net/ipv4/udp.c:1040:8) udp_sendmsg (net/ipv4/udp.c:1328:10) The output interface has a 4->6 program attached at ingress. We try to loop the multicast skb back to the sending socket. Ingress BPF runs as part of netif_rx(), pushes a valid v6 hdr and changes skb->protocol to v6. We enter ip6_rcv_core which tries to use skb_dst(). But the dst is still an IPv4 one left after IPv4 mcast output. Clear the dst in all BPF helpers which change the protocol. Try to preserve metadata dsts, those may carry non-routing metadata. Cc: stable@vger.kernel.org Reviewed-by: Maciej =C5=BBenczykowski Acked-by: Daniel Borkmann Fixes: d219df60a70e ("bpf: Add ipip6 and ip6ip decap support for bpf_skb_ad= just_room()") Fixes: 1b00e0dfe7d0 ("bpf: update skb->protocol in bpf_skb_net_grow") Fixes: 6578171a7ff0 ("bpf: add bpf_skb_change_proto helper") Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20250610001245.1981782-1-kuba@kernel.org Signed-off-by: Jakub Kicinski [ The context change is due to the commit d219df60a70e ("bpf: Add ipip6 and ip6ip decap support for bpf_skb_adjust_room()") in v6.3 which is irrelevant to the logic of this patch. ] Signed-off-by: Johnny Hao --- net/core/filter.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 77785e70cf70..87aaab182e60 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3219,6 +3219,13 @@ static const struct bpf_func_proto bpf_skb_vlan_pop_= proto =3D { .arg1_type =3D ARG_PTR_TO_CTX, }; =20 +static void bpf_skb_change_protocol(struct sk_buff *skb, u16 proto) +{ + skb->protocol =3D htons(proto); + if (skb_valid_dst(skb)) + skb_dst_drop(skb); +} + static int bpf_skb_generic_push(struct sk_buff *skb, u32 off, u32 len) { /* Caller already did skb_cow() with len as headroom, @@ -3315,7 +3322,7 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb) } } =20 - skb->protocol =3D htons(ETH_P_IPV6); + bpf_skb_change_protocol(skb, ETH_P_IPV6); skb_clear_hash(skb); =20 return 0; @@ -3345,7 +3352,7 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb) } } =20 - skb->protocol =3D htons(ETH_P_IP); + bpf_skb_change_protocol(skb, ETH_P_IP); skb_clear_hash(skb); =20 return 0; @@ -3532,10 +3539,10 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u3= 2 off, u32 len_diff, /* Match skb->protocol to new outer l3 protocol */ if (skb->protocol =3D=3D htons(ETH_P_IP) && flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV6) - skb->protocol =3D htons(ETH_P_IPV6); + bpf_skb_change_protocol(skb, ETH_P_IPV6); else if (skb->protocol =3D=3D htons(ETH_P_IPV6) && flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV4) - skb->protocol =3D htons(ETH_P_IP); + bpf_skb_change_protocol(skb, ETH_P_IP); } =20 if (skb_is_gso(skb)) { --=20 2.34.1