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=1796384210; b=OZVgV4Ay4wlDThOMf+YC3xZsROxlThFbWiw1rYiQXgJMhwt5wNTmp3lhPgVKnDJfAMAD E4L3pai7CDU5zzSKadws/0ZHI6kqvE0v1aHOt75O+Z+JGPMTTkGNs6ln96eLUCrADhEQ4 afzbI4EIhYo364n48IsljSHr9H/yTkPTVhkJ0yXyj+4BLoeH+yiFMUipqpRhWo2+Bj4rp 5C/RLBGQRhAX+l09/HHoteEnqvAWVMd8KqkwOIiag4wHYCCR9SHcStXc8kPiwNFdEl6yA KV+sTH3xUs/wlrk6mXKusPNvmUdjImLgm9WRPAsmo09/qsIuIEQL+ZLDd9iIl+7gxZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384210; 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=nmm08f/+xUuecLYDjDLUyD46UvTkUtzBJiIv/ggF8BU=; b=f7zp3sgYsA/m0ZLCZD0hVypwy3YBXHXwKn8OGI9qymKj1b3Tno+iYtzfJDUo+qrv1hLW ItVT9QDjl6y8s15cCK+iOnzjzzOgR1MtdsvTb2S9QXoZhjR3FDcQCka5VeiSVKYMAZMOH W0uE0uHeDDwledMB+FH+rEL/2+JIoCP+f6dxmn0Ab/A7Yh2XMPI/FEXU03hQWNi+aoMU1 y2gVAizz1Vvfa2p8yeXRWXT6tmICk8ENSVFoXLlb90b732MNwM9hJrCs+hrmL/WCQpzzP i7qVKiRs+EStaYzKUQ5IBAqasxO5x9/JZrpZwOuTS1DCoShmwm9TGeHPna9L1dK4hlA== 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=M77ah3D+; 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 139E8606A322; Fri, 4 Dec 2026 11:36:50 +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=M77ah3D+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 819221F000C2; Fri, 4 Dec 2026 11:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384209; bh=nmm08f/+xUuecLYDjDLUyD46UvTkUtzBJiIv/ggF8BU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M77ah3D+aOceSpbZo+MvWZSmJedhnSy1j05bKdZeZ1EXdFiZRC1FYrigpafX1yO8X c6CcsN6tS6wRG5E5FbIep2hkwwb3uTVv/6KrTqHYOOYXUB89kVbN0OGZ7xv7VukKSB NhB77tZpc9SKJ+nB13j6a2QvfVrt1AEPRX5Jj3hE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Eric Dumazet , Chris J Arges , Ido Schimmel , Paolo Abeni , Sasha Levin Subject: [PATCH 6.12 541/555] net: prevent receive header offset overflow during decapsulation Date: Fri, 4 Dec 2026 19:09:44 +0900 Message-ID: <20261204100629.247578691@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: 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 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris J Arges [ Upstream commit b10c986f1769287270de248548476f6dc2275d59 ] Repeated decapsulation can leave skb->data far from skb->head while the remaining packet data is still valid. Since the skb header positions are 16-bit offsets, a later header update can truncate and make header access use unrelated bytes and eventually crash. Limit receive headroom to 32 KiB. This is well beyond the headroom of normal packets while allowing the networking stack to pull enough headers in a single pass without overflowing 16-bit header offsets. Tunnel decapsulation re-enters __netif_receive_skb_core(), so its check protects nested IPIP and GRE. FOU and GUE bypass receive core, so check their IPv4 and IPv6 resubmission paths too. Together, these checks prevent 16-bit header-offset truncation in cases of repeated decapsulation. Report these rejections with the SKB_RX_HEADROOM drop reason. Fixes: 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff") Cc: stable@kernel.org Suggested-by: Eric Dumazet Signed-off-by: Chris J Arges Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261118-prevent_rx_header_offset_overflow-v1-1-92a5be55f994@cloudflare.com Signed-off-by: Paolo Abeni [ carges: add drop_reason variable to dev.c and adjust dropreason-core.h ] Signed-off-by: Chris J Arges Signed-off-by: Sasha Levin --- include/linux/skbuff.h | 1 + include/net/dropreason-core.h | 6 ++++++ net/core/dev.c | 7 ++++++- net/ipv4/ip_input.c | 6 ++++++ net/ipv6/ip6_input.c | 4 ++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 7df799b751ceb..d1831da744815 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -267,6 +267,7 @@ SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X)) #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2)) +#define SKB_MAX_RX_HEADROOM (U16_MAX / 2) /* return minimum truesize of one skb containing X bytes of data */ #define SKB_TRUESIZE(X) ((X) + \ diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 31e0cc1b64ff1..ac4bf047d7b92 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -106,6 +106,7 @@ FN(IP_TUNNEL_ECN) \ FN(TUNNEL_TXINFO) \ FN(LOCAL_MAC) \ + FN(SKB_RX_HEADROOM) \ FNe(MAX) /** @@ -488,6 +489,11 @@ enum skb_drop_reason { * the MAC address of the local netdev. */ SKB_DROP_REASON_LOCAL_MAC, + /** + * @SKB_DROP_REASON_SKB_RX_HEADROOM: accumulated receive headroom + * exceeds the header-offset budget. + */ + SKB_DROP_REASON_SKB_RX_HEADROOM, /** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen diff --git a/net/core/dev.c b/net/core/dev.c index 426f6d2e19524..1a9bd6a9eb454 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5661,6 +5661,7 @@ static inline int nf_ingress(struct sk_buff *skb, struct packet_type **pt_prev, static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, struct packet_type **ppt_prev) { + enum skb_drop_reason drop_reason = SKB_DROP_REASON_UNHANDLED_PROTO; struct packet_type *ptype, *pt_prev; rx_handler_func_t *rx_handler; struct sk_buff *skb = *pskb; @@ -5674,6 +5675,10 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, trace_netif_receive_skb(skb); orig_dev = skb->dev; + if (unlikely(skb_headroom(skb) > SKB_MAX_RX_HEADROOM)) { + drop_reason = SKB_DROP_REASON_SKB_RX_HEADROOM; + goto drop; + } skb_reset_network_header(skb); if (!skb_transport_header_was_set(skb)) @@ -5851,7 +5856,7 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, dev_core_stats_rx_dropped_inc(skb->dev); else dev_core_stats_rx_nohandler_inc(skb->dev); - kfree_skb_reason(skb, SKB_DROP_REASON_UNHANDLED_PROTO); + kfree_skb_reason(skb, drop_reason); /* Jamal, now you will not able to escape explaining * me how you were going to use this. :-) */ diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 9db51472c1e0f..29d7afaa1f583 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -205,6 +205,12 @@ void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol) ret = INDIRECT_CALL_2(ipprot->handler, tcp_v4_rcv, udp_rcv, skb); if (ret < 0) { + if (unlikely(skb_headroom(skb) > SKB_MAX_RX_HEADROOM)) { + __IP_INC_STATS(net, IPSTATS_MIB_INDISCARDS); + kfree_skb_reason(skb, + SKB_DROP_REASON_SKB_RX_HEADROOM); + return; + } protocol = -ret; goto resubmit; } diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index 54fc4b0eb57ba..e6e71f6f60b28 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -438,6 +438,10 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, ret = INDIRECT_CALL_2(ipprot->handler, tcp_v6_rcv, udpv6_rcv, skb); if (ret > 0) { + if (unlikely(skb_headroom(skb) > SKB_MAX_RX_HEADROOM)) { + SKB_DR_SET(reason, SKB_RX_HEADROOM); + goto discard; + } if (ipprot->flags & INET6_PROTO_FINAL) { /* Not an extension header, most likely UDP * encapsulation. Use return value as nexthdr -- 2.53.0