net: prevent receive header offset overflow during decapsulation
Subsystems (3)
PATCH 1/1 net: prevent receive header offset overflow during decapsulation
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.
--- 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(+)
include/linux/skbuff.h +1 -0
@@ -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) + \
include/net/dropreason-core.h +6 -0
@@ -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
net/core/dev.c +4 -0
@@ -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 )
net/ipv4/ip_input.c +6 -0
@@ -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; }
net/ipv6/ip6_input.c +4 -0
@@ -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,
Signature · 1 line
Chris J Arges <[email protected]>
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The new SKB_MAX_RX_HEADROOM (32 KiB) checks run in only three
places: when __netif_receive_skb_core() is entered…
--
net: prevent receive header offset overflow during decapsulation
This patch limits receive headroom to 32 KiB (SKB_MAX_RX_HEADROOM). The goal is to keep the 16-bit skb header offsets from being truncated after repeated decapsulation. The check runs on entry to __netif_receive_skb_core() and at the resubmit points of ip_protocol_deliver_rcu() and ip6_protocol_deliver_rcu(), and drops packets with the new SKB_RX_HEADROOM drop reason.
[ ... ]
net/core/dev.c static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, · line 6229
Quoted 12 lines
net/core/dev.c +4
-0@@ -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; + }
[Severity: High]
This check runs once, when __netif_receive_skb_core() is entered. That is before the another_round label, sch_handle_ingress(), vlan_do_receive() and the rx_handler call.
Can headers stripped later in the same receive pass still push the 16-bit header offsets past U16_MAX?
For example, tc act_mpls with TCA_MPLS_ACT_POP calls skb_mpls_pop() once per action. Each call stores the current headroom into the u16 header fields:
net/core/skbuff.c:skb_mpls_pop() {
...
__skb_pull(skb, MPLS_HLEN);
skb_reset_mac_header(skb);
skb_set_network_header(skb, mac_len);
...
}Outside CONFIG_DEBUG_NET, the only guard in those helpers is DEBUG_NET_WARN_ON_ONCE(), so the value gets truncated silently.
The number of pops per pass doesn't look bounded:
- a filter can hold up to 32 actions
- a filter whose action control is continue returns a negative result, and __tcf_classify() moves on to the next tcf_proto without counting it toward max_reclassify_loop (that limit only covers the TC_ACT_RECLASSIFY / TC_ACT_GOTO_CHAIN reset path)
- about 512 matchall or flower filters with 32 pops each comes to roughly 16K pops in one pass
veth_setup() sets dev->max_mtu = ETH_MAX_MTU. A frame of about 65.5 KB carrying about 16K MPLS labels, sent with AF_PACKET on one veth end, would reach __netif_receive_skb_core() on the peer with about 30 bytes of headroom and pass this check.
tc ingress could then pop the labels while skb_ensure_writable() keeps pulling data from the frags into the linear head. At some point mac_header and network_header would wrap past U16_MAX.
After the wrap, the remaining skb_mpls_pop() calls would run memmove(), skb_postpull_rcsum() and skb_mod_eth_type() at the truncated offsets. ip_rcv_core() would then read ip_hdr() from stale bytes and set transport_header from that position. L4 code could then misparse the packet, for example in tcp_data_queue():
__skb_pull(skb, tcp_hdr(skb)->doff * 4);
Here doff comes from the wrong bytes, so could this wrap skb->len or hit the BUG() in __skb_pull()?
This setup needs only CAP_NET_ADMIN and CAP_NET_RAW in a netns owned by a user namespace.
Similar in-pass header strips look possible elsewhere:
- openvswitch pop_mpls with recirculation, where ovs_dp_process_packet() runs again without re-entering __netif_receive_skb_core()
- bpf_skb_adjust_room() shrinking, which adds len directly to mac_header and network_header
The commit message says:
Together, these checks
prevent 16-bit header-offset truncation in cases of repeated decapsulation.
Is that still accurate given these paths?
Would it be more robust to bound the offset where it is stored, either in the skb_set_*_header() / skb_reset_*_header() helpers or in the pop/shrink helpers, instead of only at the chosen re-entry points?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-prevent_rx_header_offset_overflow-v1-1-92a5be55f994%40cloudflare.com
Quoted 97 lines · On 2026-11-18 17:39:27, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The new
SKB_MAX_RX_HEADROOM(32 KiB) checks run in only three
places: when__netif_receive_skb_core()is entered…--
net: prevent receive header offset overflow during decapsulation
This patch limits receive headroom to 32 KiB (
SKB_MAX_RX_HEADROOM). The goal is to keep the 16-bit skb header offsets from being truncated after repeated decapsulation. The check runs on entry to__netif_receive_skb_core()and at the resubmit points ofip_protocol_deliver_rcu()andip6_protocol_deliver_rcu(), and drops packets with the newSKB_RX_HEADROOMdrop reason.[ ... ]
net/core/dev.c static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, · line 6229
Quoted 12 lines
net/core/dev.c +4
-0@@ -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; + }[Severity: High]
This check runs once, when
__netif_receive_skb_core()is entered. That is before theanother_roundlabel,sch_handle_ingress(),vlan_do_receive()and therx_handlercall.Can headers stripped later in the same receive pass still push the 16-bit header offsets past
U16_MAX?For example, tc
act_mplswithTCA_MPLS_ACT_POPcallsskb_mpls_pop()once per action. Each call stores the current headroom into the u16 header fields:net/core/skbuff.c:skb_mpls_pop() { ... __skb_pull(skb, MPLS_HLEN); skb_reset_mac_header(skb); skb_set_network_header(skb, mac_len); ... }Outside
CONFIG_DEBUG_NET, the only guard in those helpers isDEBUG_NET_WARN_ON_ONCE(), so the value gets truncated silently.The number of pops per pass doesn't look bounded:
- a filter can hold up to 32 actions
- a filter whose action control is continue returns a negative result, and__tcf_classify()moves on to the nexttcf_protowithout counting it towardmax_reclassify_loop(that limit only covers theTC_ACT_RECLASSIFY/TC_ACT_GOTO_CHAINreset path)
- about 512 matchall or flower filters with 32 pops each comes to roughly 16K pops in one pass
veth_setup()setsdev->max_mtu=ETH_MAX_MTU. A frame of about 65.5 KB carrying about 16K MPLS labels, sent withAF_PACKETon one veth end, would reach__netif_receive_skb_core()on the peer with about 30 bytes of headroom and pass this check.tc ingress could then pop the labels while
skb_ensure_writable()keeps pulling data from the frags into the linear head. At some pointmac_headerandnetwork_headerwould wrap pastU16_MAX.After the wrap, the remaining
skb_mpls_pop()calls would runmemmove(),skb_postpull_rcsum()andskb_mod_eth_type()at the truncated offsets.ip_rcv_core()would then readip_hdr()from stale bytes and settransport_headerfrom that position. L4 code could then misparse the packet, for example intcp_data_queue():__skb_pull(skb, tcp_hdr(skb)->doff * 4);Here doff comes from the wrong bytes, so could this wrap
skb->lenor hit theBUG()in__skb_pull()?This setup needs only
CAP_NET_ADMINandCAP_NET_RAWin a netns owned by a user namespace.
Quoted 8 lines
Similar in-pass header strips look possible elsewhere:
- openvswitch
pop_mplswith recirculation, whereovs_dp_process_packet()runs again without re-entering__netif_receive_skb_core()
-bpf_skb_adjust_room()shrinking, which adds len directly tomac_headerandnetwork_header
These additional paths can be addressed in a follow-up patchset. I'd prefer to fix the currently known cases first.
Quoted 6 lines
The commit message says:
Together, these checks
prevent 16-bit header-offset truncation in cases of repeated decapsulation.
Quoted 10 lines
Is that still accurate given these paths?
Would it be more robust to bound the offset where it is stored, either in the skb_set_*_header() / skb_reset_*_header() helpers or in the pop/shrink helpers, instead of only at the chosen re-entry points?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-prevent_rx_header_offset_overflow-v1-1-92a5be55f994%40cloudflare.com
If the checks were moved to where the offset is stored (using something like skb_set_transport_header_careful()), then we could introduce potential performance issues.
--chris
Ido Schimmel
maintainerQuoted 107 lines · Chris Arges
Quoted 97 lines · On 2026-11-18 17:39:27, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The new
SKB_MAX_RX_HEADROOM(32 KiB) checks run in only three
places: when__netif_receive_skb_core()is entered…--
net: prevent receive header offset overflow during decapsulation
This patch limits receive headroom to 32 KiB (
SKB_MAX_RX_HEADROOM). The goal is to keep the 16-bit skb header offsets from being truncated after repeated decapsulation. The check runs on entry to__netif_receive_skb_core()and at the resubmit points ofip_protocol_deliver_rcu()andip6_protocol_deliver_rcu(), and drops packets with the newSKB_RX_HEADROOMdrop reason.[ ... ]
net/core/dev.c static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, · line 6229
Quoted 12 lines
net/core/dev.c +4
-0@@ -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; + }[Severity: High]
This check runs once, when
__netif_receive_skb_core()is entered. That is before theanother_roundlabel,sch_handle_ingress(),vlan_do_receive()and therx_handlercall.Can headers stripped later in the same receive pass still push the 16-bit header offsets past
U16_MAX?For example, tc
act_mplswithTCA_MPLS_ACT_POPcallsskb_mpls_pop()once per action. Each call stores the current headroom into the u16 header fields:net/core/skbuff.c:skb_mpls_pop() { ... __skb_pull(skb, MPLS_HLEN); skb_reset_mac_header(skb); skb_set_network_header(skb, mac_len); ... }Outside
CONFIG_DEBUG_NET, the only guard in those helpers isDEBUG_NET_WARN_ON_ONCE(), so the value gets truncated silently.The number of pops per pass doesn't look bounded:
- a filter can hold up to 32 actions
- a filter whose action control is continue returns a negative result, and__tcf_classify()moves on to the nexttcf_protowithout counting it towardmax_reclassify_loop(that limit only covers theTC_ACT_RECLASSIFY/TC_ACT_GOTO_CHAINreset path)
- about 512 matchall or flower filters with 32 pops each comes to roughly 16K pops in one pass
veth_setup()setsdev->max_mtu=ETH_MAX_MTU. A frame of about 65.5 KB carrying about 16K MPLS labels, sent withAF_PACKETon one veth end, would reach__netif_receive_skb_core()on the peer with about 30 bytes of headroom and pass this check.tc ingress could then pop the labels while
skb_ensure_writable()keeps pulling data from the frags into the linear head. At some pointmac_headerandnetwork_headerwould wrap pastU16_MAX.After the wrap, the remaining
skb_mpls_pop()calls would runmemmove(),skb_postpull_rcsum()andskb_mod_eth_type()at the truncated offsets.ip_rcv_core()would then readip_hdr()from stale bytes and settransport_headerfrom that position. L4 code could then misparse the packet, for example intcp_data_queue():__skb_pull(skb, tcp_hdr(skb)->doff * 4);Here doff comes from the wrong bytes, so could this wrap
skb->lenor hit theBUG()in__skb_pull()?This setup needs only
CAP_NET_ADMINandCAP_NET_RAWin a netns owned by a user namespace.Quoted 8 lines
Similar in-pass header strips look possible elsewhere:
- openvswitch
pop_mplswith recirculation, whereovs_dp_process_packet()runs again without re-entering__netif_receive_skb_core()
-bpf_skb_adjust_room()shrinking, which adds len directly tomac_headerandnetwork_header
Quoted 2 lines
These additional paths can be addressed in a follow-up patchset. I'd prefer to fix the currently known cases first.
I'm pretty sure that only skb_mpls_pop() requires a fix and the bug being fixed here is more severe.
Quoted 13 lines
Quoted 13 lines
The commit message says:
Together, these checks
prevent 16-bit header-offset truncation in cases of repeated decapsulation.Is that still accurate given these paths?
Would it be more robust to bound the offset where it is stored, either in the skb_set_*_header() / skb_reset_*_header() helpers or in the pop/shrink helpers, instead of only at the chosen re-entry points?
Quoted 8 lines
Quoted 4 lines
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-prevent_rx_header_offset_overflow-v1-1-92a5be55f994%40cloudflare.comIf the checks were moved to where the offset is stored (using something like
skb_set_transport_header_careful()), then we could introduce potential performance issues.
Agreed.
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Wed, 18 Nov 2026 08:32:27 -0600 you wrote:
Repeated decapsulation can leave
skb->datafar fromskb->headwhile 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.
[...]
Here is the summary with links:
- net: prevent receive header offset overflow during decapsulation
https://git.kernel.org/netdev/net/c/b10c986f1769
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html