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=1796383494; b=RwfuRXpv1GIQHFMOb6aeSS10oOeGAwWZ6AsuSUZoJK/y+8U2hTyji8uoCYTe3LHn4llO RTrGjPChHWDoUpuxT9u/F9hejVknbYNIxTUDmeYu+SWcrsAKTfC9yIVs9wuUEsIi3uvea Gwfz63PvTv0XvCzaeWHEbRh9j36Gj1zrcmssQT2p1sGGheWRaR+w1W+DndOk8Rh3wcCbn LADDEa2mWleb0jFMTde4vi7MuyzBQ7AW8WLS1Bc/LvMxgog51rN3OIbRH4Iks2zee18G0 CvioKCmzZCeAloYs3a/zRdO5HFOVS8dCPm0BSdIXXMKkxgP/8doFzTfmScdi8kM2dGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383494; 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=79MfqHc+/rTR12qa7uS6w9KNxX7hk6njjjo70S08I6s=; b=doIwXK1jHcEsQ5MLPcC87i7dks/0veQB0F2TRmsXkHX6tXgqiQJaxRoGycKG9ZVUYgIX 6Cp3pUveseYs3KjZ/Ueufc18Lv7IvTKNxfTm5uQ0+AKBFPzX7LcWbg7OHgIUzRacoFTu3 KZ8IUkAzijC25/l624Qtf1+FDhwyw1BzrRy0uNcC9bKXlfmvD8kVBBmPf2UH2cT8lNURY 8KhCrtlLApavO+K1uvr/CNeLWLXttoFzxUUCb9TiNgXIFmMa1h8mYzFGN3GIvIOrumRUL 5WgL30azbHL3Fhlos7B+o0IgX672ZcJoY44ThN0k2zFtB+griVLbvCqn/Q/ANBnwc1Q== 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=XrHySqtf; 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 02F6E606A322; Fri, 4 Dec 2026 11:24:54 +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=XrHySqtf Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE71A1F000C2; Fri, 4 Dec 2026 11:24:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383493; bh=79MfqHc+/rTR12qa7uS6w9KNxX7hk6njjjo70S08I6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XrHySqtfPgnbXzz3B7ReSJvTDn9f+oJFIgijVL5lA7e9aflE2hdKfAEsZ7q+UHrLz Edm0ekbLxAhT3WYKPw+Jk2Y0hPQ20kcOQzH97U6F5/E9NX/alFvcNIWGZ1pXfymtii o4xWqW4fuPDGvA1W9HGHhhGLb+gyiWW127TrqE9w= 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.12 229/555] net: clear skb->mac_len in skb_unset_mac_header() Date: Fri, 4 Dec 2026 19:04:32 +0900 Message-ID: <20261204100617.898337195@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 0e352786115cc..7df799b751ceb 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3105,6 +3105,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 341cc822933f1..b772dd4c041f4 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6743,7 +6743,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