[PATCH ipsec 1/2] xfrm: iptfs: don't modify the shared info of cloned skbs on output
From: Andrii Tereshchenko
Date: Tue Nov 17 2026 - 19:55:13 EST
TCP that a host sends through its own IP-TFS SA can panic the kernel
when segments are retransmitted.
iptfs_output_queued() aggregates inner packets by appending them to
skb_shinfo(skb)->frag_list of the first one. It appends even when that
skb is a clone, which shares its skb_shared_info with the original.
For local TCP it is one: tcp_transmit_skb() sends a clone of the skb
that stays on the retransmit queue. Appending to the clone therefore
sets a frag_list on TCP's skb that its len and data_len do not count.
ESP copies the head before sending, but the original keeps the stale
list.
When TCP retransmits that skb, the new clone carries the stale
frag_list. If the clone is then appended behind another first skb,
iptfs_rehome_fraglist() moves the stale list to that skb and subtracts
its length from the clone's len and data_len, which wrap below zero
when the list is longer than the segment. ESP copies the clone in
skb_cow_data() and skb_put() panics:
skbuff: skb_over_panic: ... len:-340 put:-340 ... end:0x180 dev:<NULL>
kernel BUG at net/core/skbuff.c:215!
CPU: 3 UID: 0 PID: 0 Comm: swapper/3 Not tainted 7.4.0-rc3 #5
RIP: 0010:skb_panic+0xbe/0xc0
Call Trace:
<IRQ>
skb_put.cold+0x1f/0x1f
skb_copy+0xfc/0x180
skb_cow_data+0xc5/0x630
esp_output_head+0x38a/0xb40
esp_output+0x1c5/0x390
xfrm_output_resume+0x113c/0x22a0
iptfs_delay_timer+0xdb7/0x1990
__hrtimer_run_queues+0x16d/0x340
hrtimer_run_softirq+0x136/0x210
handle_softirqs+0x162/0x420
Unclone the first skb before appending to it. ESP copies a cloned head
anyway, so this moves that copy earlier and does not add one. Send a
cloned first skb on its own when it already has a frag_list or cannot
be uncloned: uncloning the head does not unshare the skbs on its
frag_list, and appending writes to the last of them. For the same
reason stop aggregating at a cloned skb that has a frag_list; it
becomes the next first skb. Do not let iptfs_consume_frags() take the
page frags of a cloned skb, because that empties the frags array the
original still uses.
A first skb that was a clone can now take the page frags of the skbs
behind it, where it always used the frag_list before.
The panic was observed on a machine in real use while rolling out
andrii.cloud. It was reproduced on an unmodified v7.4-rc3 built with
KASAN, in a KVM guest, without fault injection. Three network
namespaces form a client, an IP-TFS gateway and an HTTPS server that
is the other IP-TFS endpoint. Clients fetch a 50 KB page for 40
seconds and netem drops 5% of the packets sent to the client, so that
the server retransmits through its SA. The boots ran with the server's
normal segment size or with the client advertising an MSS of 130. Most
boots of the unpatched kernel crashed: some with this panic, the
others with the use-after-free that the next patch fixes. With only
the next patch applied, a few boots at MSS 130 still crashed, all with
this panic. With the series applied, no boot crashed. Kernel selftests
were not run; none of them covers IP-TFS.
The analysis and the patch were produced with an AI coding assistant
and reviewed by the submitter.
Fixes: 0e4fbf013fa5 ("xfrm: iptfs: add user packet (tunnel ingress) handling")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Andrii Tereshchenko <opensource@xxxxxxxxxx>
---
net/xfrm/xfrm_iptfs.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index 0313a43aa..95ba73013 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -2234,6 +2234,19 @@ static void iptfs_output_queued(struct xfrm_state *x, struct sk_buff_head *list)
if (iptfs_first_skb(&skb, xtfs, mtu))
continue;
+ /* A clone shares skb_shinfo(), and with it the frag_list we
+ * are about to append to, with its original, e.g. the skb TCP
+ * keeps for retransmission. A cloned head that has a frag_list,
+ * or that we cannot unclone, is sent on its own rather than
+ * aggregated; the skbs on a frag_list stay shared with the
+ * original even after an unclone, so they are never appended.
+ */
+ if (skb_cloned(skb) &&
+ (skb_has_frag_list(skb) || skb_unclone(skb, GFP_ATOMIC))) {
+ xfrm_output(NULL, skb);
+ continue;
+ }
+
/* If fragmentation was required the returned skb is the last
* IPTFS fragment in the chain, and it's IPTFS header blkoff has
* been set just past the end of the fragment data.
@@ -2273,6 +2286,13 @@ static void iptfs_output_queued(struct xfrm_state *x, struct sk_buff_head *list)
if (skb2->len > remaining)
break;
+ /* Appending re-homes skb2's frag_list, which a clone
+ * shares with its original. Leave such an skb to be
+ * sent on its own as the next head.
+ */
+ if (skb_cloned(skb2) && skb_has_frag_list(skb2))
+ break;
+
__skb_unlink(skb2, list);
/* Consider the buffer Tx'd and no longer owned */
@@ -2292,10 +2312,13 @@ static void iptfs_output_queued(struct xfrm_state *x, struct sk_buff_head *list)
/* skb->pp_recycle is passed to __skb_flag_unref for all
* frag pages so we can only share pages with skb's who
* match ourselves.
+ *
+ * iptfs_consume_frags() empties skb2's frags, which a
+ * clone shares with its original.
*/
shi2 = skb_shinfo(skb2);
if (share_ok &&
- (shi2->frag_list ||
+ (skb_cloned(skb2) || shi2->frag_list ||
(!skb2->head_frag && skb_headlen(skb)) ||
skb->pp_recycle != skb2->pp_recycle ||
skb_zcopy(skb2) ||
--
2.53.0