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=1796380216; b=vr2DY9Sfu0BO012Em6sv90O4OLM9aGmWS5zqsEUxprK0TtkclRBju2rm+SM4f2VFcPwS zflDXvD9tlDhqq56wDDO//UfmnKBQN0147UcrmzR+zdrFl/ImlMoMSsAMaqfuvC/Mb7qc S5dGU/ZTvgdvdx71ILTr6iV5A44xqJC0/gbtXTHoK4/cEqaJGviHM9RfurwjH2ShDZlcW 1P9/hVTA8ZZfthORt2XIstal8vNP0XzrP8DQbLoyqAmC97rL+GRjzNSFMnJZQMgfbpCT4 jsvJaDZQglU7z58ffwHdipI9QDt0qDqb7WRg+mLTPxgITCJ2RnAODJyQWH6E4wXX1SA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380216; 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=NKHOCYw3CwnZGMeL96qvdoYV8vUvbG7Z808o1VynbP0=; b=oyxmAmigu1VW/ozqGknA/a5FW2P2SsmffuFdpvsoryjmoUpYCKOzyThiz9oyMbKhHNF1 GxaSG0LPJqGSisOK1H0bOI8MmU9NheF/MxXoN++XdEdn/jwfNXfVKudIPh2C96HkqXcY6 wgJGt8dIYquUB5tA19QGaKttEEKQBy/0nbV1demuOtaO2DZwPFPQV7Fi75Npbs8Vi3GZP gEB6MZLqVfkmDX0/JS6NMqWSXhpWwy4Ejb9JSM9jfNIQvYJurwWKLpPLfBUieosotJDxE fKiyeMZOXRru7tht/aMVixLOUbk2i17ksWk8SuyfBNpq9MbDLxcR3WhJiSEFbTzeDqA== 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=DpTPJcM0; 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 770F9606A335; Fri, 4 Dec 2026 10:30:16 +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=DpTPJcM0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E37411F000C2; Fri, 4 Dec 2026 10:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380216; bh=NKHOCYw3CwnZGMeL96qvdoYV8vUvbG7Z808o1VynbP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DpTPJcM0ICdDL1lhXHuubbMH5JFQqzVtTaHxZcliD/MW1CPCwjUWUL4aWKiPRi0X/ T1z/Gj02hfBVhYj5AaaioQXq7nsWAqp5Uep/s/S9lejcq+RWSFZYg1G8CR9OKoPfmg yjP98dq+haj1XoTfUu5g2drt4noIbqckD+ImD0mM= 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 7.3 175/742] net: clear skb->mac_len in skb_unset_mac_header() Date: Fri, 4 Dec 2026 19:00:39 +0900 Message-ID: <20261204100639.738694906@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 707082f68f210..5e6ae9598b141 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3177,6 +3177,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 e685964654df5..1856aecd5558c 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6905,7 +6905,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