From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381895; b=1tYia+w+FnEkH7g7kwyA30X6skqAvatrca+H+mxA6Ur96VRuMzkJSleI/epqSfBbAeig RyqnWu8TRAyapfTc3jsT95hmmKj84PKToUklpPrUI3BA7dKsxc7DriIbQSGElJh1mDJW3 IC5lEZfGlf06bZmP/jR/HdsRcmCpLL1T6oBMyIlA8bOF5VfN3cnoOTflBcYsT/65B0PM7 xKbhuluZfds7gkCFm5jauxo1VVFjmAIxyHUmreterNOmnr3bhFWPGi0xriLVM9al6CD/D St5VILdXysSDTZdRnCWOVfnPS090NTbdmXQwj8u+U30OVOqvqt5rQl2aBpzSu3UnFOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381895; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=H6RBG/q70INMXSsy/WVU944BXvd0RQ1RkjDTJx5Tt9g=; b=EY6DE6apd/+oz0S2GleKAh4ob/1qabdhNZ/lLKSo/ji86wGv4vX5GcFtGbLjgR7Y7UNG ctVDSNiS/P0CbxXtsyAU/UqiT5YacrWxd9wUlEKMRTgRanYDKwNZOxAa416AWbnTscV+O bM5GYaNVh7PhyT+beii0wnv3Yn789DunkgXti9qqJnRrYfDotJY8XiQQ2chLF+TbJP9hP Rd1QnQLOy999GgnlkKrl7vND20K3Ztan5nL+pKANU53dhVX1Mg2hRComrCoGh+UkN3Jlt qgBR3t5/CWNK4YAhoLTXpk3QstzFQAOwkuLChu5kCYqBCU2awwy26BUde0mF8T8Cp4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=S7hxivD9; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B270606A330; Fri, 4 Dec 2026 10:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=S7hxivD9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C644A1F000C2; Fri, 4 Dec 2026 10:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381895; bh=H6RBG/q70INMXSsy/WVU944BXvd0RQ1RkjDTJx5Tt9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=S7hxivD9BBzuqBQDh9gzUsmSwpbZuDIyv+0kCAe+oeu8dYyZtT7PTIHEu6V07SRT8 oXX11yca6E825fAfvNjv6FXF0PLP0sjLBWWY38Y60vMh0BXwmcNNTKSQYGlS2soMUX /IboPPeXzGvretDJ707FPhgCuFziyvto2Nahf37o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Piyus Kedia , Kapil Vaswani , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.18 219/703] net: clear skb->mac_len in skb_unset_mac_header() Date: Fri, 4 Dec 2026 19:01:58 +0900 Message-ID: <20261204100633.661438258@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 7a505bb0168a132c2a3ab4efff4c6d6474ca3aa1 ] skb_unset_mac_header() marks the mac header as unset but leaves skb->mac_len alone, so an skb can end up with no mac header and a non-zero mac_len. Code that uses mac_len to decide whether a mac header is present is then misled. end_dt_vrf_rcv() (SRv6 End.DT4/End.DT6) unsets the mac header of the decapsulated packet so that the VRF device can rebuild it. The VRF device only does so when a packet sniffer is attached, so without one the skb continues up the stack with mac_len == 14. In xfrm4_remove_tunnel_encap() and xfrm6_remove_tunnel_encap(), skb_mac_header_rebuild() is a no-op for such an skb, and the following if (skb->mac_len) eth_hdr(skb)->h_proto = skb->protocol; writes two bytes at skb->head + 0xffff + offsetof(struct ethhdr, h_proto): BUG: KASAN: slab-out-of-bounds in xfrm4_remove_tunnel_encap+0x17d/0x220 Write of size 2 at addr ffff88805f85800b by task syz-executor/10831 xfrm4_remove_tunnel_encap xfrm_input xfrm4_esp_rcv ip_protocol_deliver_rcu ip_local_deliver_finish seg6_local_input_core lwtunnel_input __netif_receive_skb netif_receive_skb tun_rx_batched tun_get_user __input_process_payload() in net/xfrm/xfrm_iptfs.c has the same three lines and reported as a use-after-free rather than an out-of-bounds. The address written is fixed relative to skb->head, so what it lands in is whatever the allocator placed sixteen pages past the skb: a live object gives slab-out-of-bounds, a freed one or a page back on the buddy free list gives use-after-free, and a different live object gives no report at all. Clearing mac_len at the source makes the guard false at all three sites. Clear mac_len in skb_unset_mac_header() so that all callers leave the skb in a consistent state, and remove the now redundant assignment in skb_carve_reset_headers(). The other callers are on egress paths (__bpf_redirect_neigh(), bpf_lwt_push_ip_encap()) or only reach the helper when the mac header was already unset (bpf_update_srh_state()), and do not read mac_len afterwards. vrf_prepare_mac_header(), the rebuild end_dt_vrf_rcv() unsets the header for, pushes ETH_HLEN and then calls skb_reset_mac_header() and skb_reset_mac_len(), so it recomputes mac_len itself and never reads the stale value. The issue was reported on the list by Piyus Kedia and Kapil Vaswani, who found it by fuzzing with AI assistance and reproduced the KASAN splat on v7.4-rc3. Their reproducer was not published. Fixes: 664d6f86868b ("seg6: add support for the SRv6 End.DT4 behavior") Reported-by: Piyus Kedia Reported-by: Kapil Vaswani Closes: https://lore.kernel.org/netdev/20261116174531.2540348-2-piyus@iiitd.ac.in/ Suggested-by: Kapil Vaswani Suggested-by: Piyus Kedia Tested-by: Piyus Kedia Signed-off-by: Eric Dumazet Signed-off-by: Piyus Kedia Link: https://patch.msgid.link/20261117143612.95112-1-piyus@iiitd.ac.in Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- include/linux/skbuff.h | 1 + net/core/skbuff.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 1ce81b7028928..dd5ae7a373851 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3163,6 +3163,7 @@ static inline u32 skb_mac_header_len(const struct sk_buff *skb) static inline void skb_unset_mac_header(struct sk_buff *skb) { skb->mac_header = (typeof(skb->mac_header))~0U; + skb->mac_len = 0; } static inline void skb_reset_mac_header(struct sk_buff *skb) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 60eb8b4328f89..27eb14c2b330f 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6813,7 +6813,6 @@ static void skb_carve_reset_headers(struct sk_buff *skb) skb_unset_mac_header(skb); skb_unset_transport_header(skb); skb_reset_network_header(skb); - skb->mac_len = 0; /* Inner offsets have no "unset" marker, zero them so that * skb_inner_network_header_was_set() becomes false and no -- 2.53.0