From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Steffen Klassert <steffen.klassert@secunet.com>,
<netdev@vger.kernel.org>
Subject: [PATCH 02/22] xfrm: esp: reset outer TCP GSO metadata on espintcp input
Date: Tue, 1 Dec 2026 13:41:28 +0100 [thread overview]
Message-ID: <20261201124252.1163254-3-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com>
From: Guoshuai Yang <yangguoshuai@gmail.com>
When ESP packets are received over TCP (RFC 8229 espintcp), strparser
slices individual length-prefixed ESP records from the outer TCP stream by
cloning the incoming TCP skb(s) in __strp_recv().
If the outer TCP skb was GRO-coalesced before reaching strparser, its
skb_shinfo carries the outer TCP stream's GSO metadata (gso_size, gso_segs,
and gso_type). When an ESP record spans two outer TCP segments, strparser
chains the spillover clone onto skb_shinfo(head)->frag_list.
Subsequently in esp_input() and esp6_input(), skb_cow_data() unshares the
head skb via pskb_expand_head() (preserving the outer TCP gso_size and
gso_type in the new private skb_shinfo) and calls skb_copy() on each cloned
frag_list member, which copies the outer TCP GSO fields via
skb_copy_header() onto a linear frag_list child skb allocated from slab
with head_frag == 0.
Furthermore, on kernels with TCP fraglist GRO support, if an outer TCP GRO
aggregate carrying SKB_GSO_FRAGLIST reaches the espintcp socket unsegmented
(for example, when rx-gro-list is enabled on a device in an outer netns
where tcp4/6_check_fraglist_gro() finds no local socket and the aggregate
is forwarded across a NETIF_F_GSO_FRAGLIST-capable veth device into the
netns hosting the espintcp socket) and is chained onto
skb_shinfo(head)->frag_list by __strp_recv(), skb_cow_data() invokes
skb_copy() / skb_copy_expand() on that frag_list member and hits
WARN_ON_ONCE(skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST), failing with
-ENOMEM before decryption even begins. (On older stable trees without TCP
fraglist GRO, the pre-pass is a no-op.)
After ESP decryption and header removal, the resulting single inner packet
still has skb_is_gso(skb) == true with the stale outer TCP gso_size, while
skb_headlen(head_skb) is now smaller than that gso_size due to stripping
the outer framing and ESP header. When this packet passes through
gro_cells_receive() (which flushes frag_list packets via GRO_NORMAL
without resetting gso_size) and is forwarded, validate_xmit_skb() invokes
tcp_gso_segment() -> skb_segment(). Because head_skb is shorter than the
stale gso_size and SKB_GSO_DODGY is not set, skb_segment() attempts to map
the slab-backed frag_list member as a scatter-gather page fragment where
list_skb->head_frag == 0. On current mainline kernels, skb_segment()
triggers DEBUG_NET_WARN_ON_ONCE(1) and fails with -EINVAL, causing
validate_xmit_skb() to drop all multi-segment espintcp packets. On stable
kernels prior to the removal of BUG_ON(!list_skb->head_frag) in
skb_segment() (such as 6.12.94 where this trace was captured), it crashes
the kernel:
Internal error: Oops - undefined instruction: 0 [#1] SMP ARM
PC is at skb_segment+0x574/0xd20
LR is at skb_segment+0x884/0xd20
Call trace:
skb_segment from tcp_gso_segment
tcp_gso_segment from inet_gso_segment
inet_gso_segment from skb_mac_gso_segment
skb_mac_gso_segment from __skb_gso_segment
__skb_gso_segment from validate_xmit_skb
validate_xmit_skb from __dev_queue_xmit
__dev_queue_xmit from ip_finish_output2
ip_finish_output2 from ip_output
ip_output from ip_sublist_rcv_finish
ip_sublist_rcv_finish from ip_sublist_rcv
ip_list_rcv from __netif_receive_skb_list_core
__netif_receive_skb_list_core from __netif_receive_skb_list
__netif_receive_skb_list from gro_normal_list
gro_normal_list from gro_cell_poll
Similarly, if a decrypted inner packet with a frag_list later takes the
ip_do_fragment() frag_list fast path, each detached frag_list member is
transmitted as a standalone IP fragment and would still carry the stale
outer TCP GSO state when reaching validate_xmit_skb(). And even when an
ESP record does not have a frag_list, leaving the stale outer TCP gso_size
on the decrypted inner skb prevents dev_gro_receive() from initializing
gso_size to the inner packet's skb_gro_len().
We cannot reset GSO state earlier in espintcp_rcv() / handle_esp() because
the skb may still be a clone sharing skb_shinfo with the outer TCP skb held
by strparser. Instead, in esp_input() and esp6_input():
1. Prior to skb_cow_data(), unshare/unclone and reset GSO metadata on any
frag_list member carrying SKB_GSO_FRAGLIST (unsharing any shared
predecessor frag_list members along the walk) so skb_copy() /
skb_copy_expand() inside skb_cow_data() does not hit WARN_ON_ONCE() and
drop the packet.
2. At skip_cow, where the head skb and all frag_list members are guaranteed
to be uncloned with private skb_shinfo, call skb_gso_reset() on both the
head skb and each skb_walk_frags() member.
Fixes: e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
Cc: stable@vger.kernel.org
Signed-off-by: Guoshuai Yang <yangguoshuai@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
include/net/esp.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++
net/ipv4/esp4.c | 9 +++++++++
net/ipv6/esp6.c | 9 +++++++++
3 files changed, 69 insertions(+)
diff --git a/include/net/esp.h b/include/net/esp.h
index 322950727dd0..83c75ef59482 100644
--- a/include/net/esp.h
+++ b/include/net/esp.h
@@ -28,6 +28,57 @@ static inline void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8
tail[plen - 1] = proto;
}
+static inline int esp_reset_espintcp_fraglist_gso(struct sk_buff *skb)
+{
+ struct sk_buff **fragp;
+ struct sk_buff *frag;
+
+ skb_walk_frags(skb, frag) {
+ if (skb_shinfo(frag)->gso_type & SKB_GSO_FRAGLIST)
+ break;
+ }
+ if (!frag)
+ return 0;
+
+ if (skb_unclone(skb, GFP_ATOMIC))
+ return -ENOMEM;
+
+ for (fragp = &skb_shinfo(skb)->frag_list; (frag = *fragp);
+ fragp = &frag->next) {
+ if (skb_shared(frag)) {
+ struct sk_buff *nfrag;
+
+ nfrag = skb_clone(frag, GFP_ATOMIC);
+ if (!nfrag)
+ return -ENOMEM;
+
+ nfrag->next = frag->next;
+ consume_skb(frag);
+ frag = nfrag;
+ *fragp = frag;
+ }
+
+ if (!(skb_shinfo(frag)->gso_type & SKB_GSO_FRAGLIST))
+ continue;
+
+ if (skb_unclone(frag, GFP_ATOMIC))
+ return -ENOMEM;
+
+ skb_gso_reset(frag);
+ }
+
+ return 0;
+}
+
+static inline void esp_reset_espintcp_gso(struct sk_buff *skb)
+{
+ struct sk_buff *iter;
+
+ skb_gso_reset(skb);
+ skb_walk_frags(skb, iter)
+ skb_gso_reset(iter);
+}
+
struct esp_info {
struct ip_esp_hdr *esph;
__be64 seqno;
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index ae701561d9f1..111bea0bd260 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -893,6 +893,12 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
}
}
+ if (x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP) {
+ err = esp_reset_espintcp_fraglist_gso(skb);
+ if (err)
+ goto out;
+ }
+
err = skb_cow_data(skb, 0, &trailer);
if (err < 0)
goto out;
@@ -900,6 +906,9 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
nfrags = err;
skip_cow:
+ if (x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
+ esp_reset_espintcp_gso(skb);
+
err = -ENOMEM;
tmp = esp_alloc_tmp(aead, nfrags, seqhilen);
if (!tmp)
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index d654f0f44238..b287c807b018 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -936,6 +936,12 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb)
}
}
+ if (x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP) {
+ ret = esp_reset_espintcp_fraglist_gso(skb);
+ if (ret)
+ goto out;
+ }
+
nfrags = skb_cow_data(skb, 0, &trailer);
if (nfrags < 0) {
ret = -EINVAL;
@@ -943,6 +949,9 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb)
}
skip_cow:
+ if (x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
+ esp_reset_espintcp_gso(skb);
+
ret = -ENOMEM;
tmp = esp_alloc_tmp(aead, nfrags, seqhilen);
if (!tmp)
--
2.53.0
next prev parent reply other threads:[~2026-12-01 12:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:41 [PATCH 0/22] pull request (net): ipsec 2026-12-01 Steffen Klassert
2026-12-01 12:41 ` [PATCH 01/22] xfrm: ipcomp: account full fragment pages in truesize Steffen Klassert
2026-12-01 12:41 ` Steffen Klassert [this message]
2026-12-01 12:41 ` [PATCH 03/22] xfrm: keep the mode module pinned until destroy_state returns Steffen Klassert
2026-12-01 12:41 ` [PATCH 04/22] xfrm: serialize SA activation with state deletion Steffen Klassert
2026-12-01 12:41 ` [PATCH 05/22] xfrm: keep old state references until migration deletion completes Steffen Klassert
2026-12-01 12:41 ` [PATCH 06/22] xfrm: hold migrated states through rollback Steffen Klassert
2026-12-01 12:41 ` [PATCH 07/22] xfrm: check inner family via skb_dst for small_ipv6 DF clearing Steffen Klassert
2026-12-01 12:41 ` [PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len() Steffen Klassert
2026-12-01 12:41 ` [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload Steffen Klassert
2026-12-01 12:41 ` [PATCH 10/22] xfrm: fix IPv6 first-fragment protocol decode Steffen Klassert
2026-12-01 12:41 ` [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments Steffen Klassert
2026-12-01 12:41 ` [PATCH 12/22] xfrm: espintcp: read the socket error queue for MSG_ERRQUEUE Steffen Klassert
2026-12-01 12:41 ` [PATCH 13/22] xfrm: iptfs: force a dst reference before queueing an skb Steffen Klassert
2026-12-01 12:41 ` [PATCH 14/22] xfrm: espintcp: select receive path by skb protocol Steffen Klassert
2026-12-01 12:41 ` [PATCH 15/22] net: xfrm: interface: restore dst_orig on every xfrm interface Steffen Klassert
2026-12-01 12:41 ` [PATCH 16/22] xfrm: iptfs: make room before copying a continuation in reassembly Steffen Klassert
2026-12-01 12:41 ` [PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy Steffen Klassert
2026-12-01 12:41 ` [PATCH 18/22] xfrm: Give GC list nodes their own storage Steffen Klassert
2026-12-01 12:41 ` [PATCH 19/22] xfrm: Serialize device state teardown Steffen Klassert
2026-12-01 12:41 ` [PATCH 20/22] xfrm: Wait for an RCU grace period before freeing device state Steffen Klassert
2026-12-01 12:41 ` [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush" Steffen Klassert
2026-12-01 12:41 ` [PATCH 22/22] xfrm: Serialize offload stats updates with x->lock Steffen Klassert
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=20261201124252.1163254-3-steffen.klassert@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=netdev@vger.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