Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796247766; b=GaGOpNdTaU+J5ioOCtBpCs4eb3xv34EzzT1P4Q7dyvlYKfsnwo/QXQvtDrCZ05Z2EvDf PrJ6jJwy72vH3nX39i89+ICiwR/BfQnunvTvHtbImTm5Z7VgbhY/5n/PfypwvJ9PpYmpd 5UMh3doTi3FX7GqrLeM0mlPb4jJbObRqJJHR+1eXF3abuVlhuVRaw3wVrukISm6UW5Uv4 luEYfoJnl6D6xg0P6K9pZbSgftJAEvSZep5qzmrEQAUmep2S7KCkR+UB+QNZwNgZ4YUyo aQZF/U69UDfti4wX0rBzr2LPhzCojuD/NbTsO8JoUcMZZB0w7Sbkbu1HoFWAOX1fLBw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796247766; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=7uLEebXf4xVcSN07PL2/lM2sRIWMivJtUtg0R7RiaWU=; b=K+QBLAdczkEzK1MxynFNs2xErACugBjmj6aIAOcKwgYZDXBisaIcKP4sr0+UWKyBR35S G6MSN4N3LfFxHsbiCJPnoxZrFBfG9qbQtV0IFb02+DeXWj/8pjf5+cewOAp3Uv449yZz8 Sq3bgxj110roBGeDVS/CnNbu2urFYodIwMu2KEJfp3ZPodst3g9iy4PNP3BuYHDtr26D6 D2lkJQjRVgxaJr0DOF2RlCsGgitIZErY5ZkbULcZor/XjLTtZ9k+MFkrPg33MmvGts6+B Kzt/JSgNeN2DWTyHQM7y7Gpoc/m2TyJzkeXGo4WLg7+XVVq3grPjZDfn8vQpC6ZJoWA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass header.d=cloudflare.com header.i=@cloudflare.com header.a=rsa-sha256 header.s=google09082023 header.b=CzNGEMN6; arc=none smtp.remote-ip=209.85.167.178 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52714606A322 for ; Wed, 2 Dec 2026 21:42:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 52714606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=cloudflare.com header.i=@cloudflare.com header.a=rsa-sha256 header.s=google09082023 header.b=CzNGEMN6 Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-55650fe1f0dso7564814b6e.2 for ; Wed, 02 Dec 2026 13:42:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1796247765; x=1796852565; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7uLEebXf4xVcSN07PL2/lM2sRIWMivJtUtg0R7RiaWU=; b=CzNGEMN6NGeuzMAXBFvIbrIpTs61wS2KASQpioz2t+AEbYpK6YIIjanl41jJ8g8tMD DsI9RtOWy/HGcMNtUf7dc9qvOO3Kssf224acig0erQQmrSIq0AE2xOakmocgX0GK6kfh x9F1qYTojPes9I18Vh8Hmhi+dssh0NDOpSY8WzNFZHKQhvBobixuKhDbGIsdEmuZy7HU TnIn98lWOYbMAAhc6zh0rDNgjJ3ahVLuuxVk2JM/n4hKwB/fSkY/zQM1qwftGKD2Vc/a 1amtmifl6h04WN9UUjsP0II8OUEnUjC4WrADB0cLsZ4TY+gw+jZeuPy+Px8QFYqFblrv e05g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796247765; x=1796852565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=7uLEebXf4xVcSN07PL2/lM2sRIWMivJtUtg0R7RiaWU=; b=yFj6smChNWKChL6fnR+aMOzSoGIdFkZCdiP3phuVmT4oLXwJUBGZRJJCy1sahdSdHv bdAASmd/pyfzBgS8TTdlJPvqhggmxCkf74HCQ/Mw3insa1oEAkXfQpP55sy8+MhjVu/S +SHeUT7g+cITpRXhC93H6F830TA4rilEcSS4NW8bzbBB8dJB1b19/Pb6wgYaOlSx9J7E JsKpldPObekirZqivyrxOdeeUdG72qsmZRNBeRep0S616lUpQ7aPdjyz1cZRxw9x9myL ffSKXX4oqYMfBTM2zo22WpDKweQlRZrVfH80if6wH4U6O4M7cL7zBYsmi7bUNnRdxrVc B9UA== X-Gm-Message-State: APuU4Z90eWO5l9+c+1gxb4I88XJSLfEbE0qZMR3p3jqUN+oD01omc8FR eey0pruR7Fm3G3NyG+1BxcCuMcGhmUAksff8KjHtQSVPzn8jJdOb9hACJmbyOVmIYkwiSPPBUhT kevO7kcIhYA== X-Gm-Gg: AZFdTZdy8OddeN0NE32AOX1f8jt2c/OVoKEpne0RyQ8jNgh2P7wwdLHU1xkXbT0JPzu BHpkNrRZ12cx2gp0DAqH2taapA5aLHO82ej8s1MtAmuW3k3UtRuu39NEBNMiiblDrNhwNiTgJUI cq+VfXdi6y07+C95yQBJ9F/BvOaMqepBbHbLenHnMT8QqxdYfS5rrB2c5Hr4j6wLNoQmRoRCpHV wVTFyKV0HAcjDD4nLrbbCsq8SALqTuCHvdKXMaZCO8AGSlsl7AmkQBy6MuNYwwNf5b2CQVYPUxI Yw/mG5/fdUIkCNspCdcVGigMMB0ay/5mX/08NP3l6i/lb1sBnQf4rJSw9yJTyWmBC2q/9chWISN PK1PoBKIKUi909MkT1sYTgEboaGy4z3vx/LV8RD5P87vfFqS7ziFnVrqzcA2290QvjOSIzFHd+E g00UjjpIp3eneX5BEqOUgcom4Yj/fJ3LGKgNTnXeNtWkwy5Wh7vMCOa2KMson7546NpjwWuxhJX 8a9x1V83nwXlBkk2edO2XfVMZAkYfXSJ6Z7X0N9VD8LA3QzrtoeqFZbfpjvK2SJ5oKZhLaKO1Xy nzo/qRWVEfk= X-Received: by 2002:a05:6808:308a:b0:568:185e:e69 with SMTP id 5614622812f47-57a09c10ff0mr48663993b6e.13.1796247765220; Wed, 02 Dec 2026 13:42:45 -0800 (PST) Received: from 20HS2G4 ([2a09:bac6:bf21:1923::281:c]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a347636b9sm31919984b6e.7.2026.12.02.13.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 13:42:44 -0800 (PST) From: Chris J Arges To: stable@vger.kernel.org Cc: Chris J Arges , stable@kernel.org, Eric Dumazet , Ido Schimmel , Paolo Abeni Subject: [PATCH 6.6.y] net: prevent receive header offset overflow during decapsulation Date: Wed, 2 Dec 2026 15:42:35 -0600 Message-ID: <20261202214239.2247565-1-carges@cloudflare.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120227-unsecured-january-d8c5@gregkh> References: <2026120227-unsecured-january-d8c5@gregkh> 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 [ 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 ] Signed-off-by: Chris J Arges --- 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 6484ac551ec7..8e61f86133c0 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -266,6 +266,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 16c140e00cc8..814227a08ee3 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -85,6 +85,7 @@ FN(PACKET_SOCK_ERROR) \ FN(TC_CHAIN_NOTFOUND) \ FN(TC_RECLASSIFY_LOOP) \ + FN(SKB_RX_HEADROOM) \ FNe(MAX) /** @@ -369,6 +370,11 @@ enum skb_drop_reason { * iterations. */ SKB_DROP_REASON_TC_RECLASSIFY_LOOP, + /** + * @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 95beb4b402d0..61033953bd34 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5508,6 +5508,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; @@ -5521,6 +5522,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)) @@ -5697,7 +5702,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 5e9c8156656a..df91d00d7af8 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 c5ae346e29cf..70a759715220 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