From: Chris J Arges <carges@cloudflare.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>
Cc: June Slater <june@cloudflare.com>,
Dan Jones <danjones@cloudflare.com>,
Jesse Brandeburg <jbrandeburg@cloudflare.com>,
Josef Bacik <josef@toxicpanda.com>,
Chris Mason <mason@kernel.org>,
kernel-team@cloudflare.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@kernel.org,
Chris J Arges <carges@cloudflare.com>
Subject: [PATCH] net: prevent receive header offset overflow during decapsulation
Date: Wed, 18 Nov 2026 08:32:27 -0600 [thread overview]
Message-ID: <20261118-prevent_rx_header_offset_overflow-v1-1-92a5be55f994@cloudflare.com> (raw)
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 <edumazet@kernel.org>
Signed-off-by: Chris J Arges <carges@cloudflare.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
include/linux/skbuff.h | 1 +
include/net/dropreason-core.h | 6 ++++++
net/core/dev.c | 4 ++++
net/ipv4/ip_input.c | 6 ++++++
net/ipv6/ip6_input.c | 4 ++++
5 files changed, 21 insertions(+)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 6787fcf6ac3e..adc61f5e3e85 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -268,6 +268,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 fa2fe8990557..903d6a3a0ff1 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -128,6 +128,7 @@
FN(PSP_INPUT) \
FN(PSP_OUTPUT) \
FN(RECURSION_LIMIT) \
+ FN(SKB_RX_HEADROOM) \
FNe(MAX)
/**
@@ -612,6 +613,11 @@ enum skb_drop_reason {
* itself.
*/
SKB_DROP_REASON_RECURSION_LIMIT,
+ /**
+ * @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 3c58db732761..6140fd9d11cd 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6223,6 +6223,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 !defined(CONFIG_DEBUG_NET)
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 9860178752b8..c74886b1f445 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -207,6 +207,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 d332ec60f915..6dc1211eade6 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -479,6 +479,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
---
base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5
change-id: 20261118-prevent_rx_header_offset_overflow-45e24a2686d2
Best regards,
--
Chris J Arges <carges@cloudflare.com>
next reply other threads:[~2026-11-18 14:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 14:32 Chris J Arges [this message]
2026-11-18 14:38 ` netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118-prevent_rx_header_offset_overflow-v1-1-92a5be55f994@cloudflare.com \
--to=carges@cloudflare.com \
--cc=danjones@cloudflare.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=jbrandeburg@cloudflare.com \
--cc=josef@toxicpanda.com \
--cc=june@cloudflare.com \
--cc=kernel-team@cloudflare.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®