[PATCH ipsec 1/2] xfrm: iptfs: charge shared fragments to the inner packet's truesize
From: Andrii Tereshchenko
Date: Sat Nov 28 2026 - 21:01:00 EST
iptfs_skb_add_frags() gives an inner packet references to page fragments
of the outer packet and adds their length to its len and data_len, but
not to its truesize. Socket receive queues and IP fragment queues then
take these packets at a fraction of the memory they pin, and reassembling
inner IP fragments trips the truesize check in skb_try_coalesce(). Any
host whose large packets cross the tunnel can trigger it, on a receiver
whose NIC driver builds skbs with page fragments:
WARNING: net/core/skbuff.c:6355 at skb_try_coalesce+0x4bd/0x4d0
inet_frag_reasm_finish+0x12e/0x2e0
ipv6_frag_rcv+0x9b1/0xda0
With panic_on_warn that brings the receiver down. Charge each shared
fragment the bytes it references, as skb_segment() does for the
fragments it shares; their real truesize is not known here.
Made with an AI coding assistant, reviewed by the submitter.
Fixes: 5f2b6a909574 ("xfrm: iptfs: add skb-fragment sharing code")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Andrii Tereshchenko <opensource@xxxxxxxxxx>
---
Tested in KVM guests with 2/2 on ipsec master: without this patch it
trips the warning and finds a socket charged 1.9 MB for 2.9 MB of
queued datagrams; with it and panic_on_warn=1 it passes, two boots
each way, with lockdep, KASAN and UBSAN clean and xfrm_policy.sh /
xfrm_state.sh passing. Under KCSAN-strict it reports nothing beyond
the unpatched baseline (tick_nohz boot noise; nothing in xfrm). The
proposed IP-TFS KUnit tests cover this too (iptfs_add_frags_test and
two more).
Found by an AI code review agent. Validated with the 2/2 selftest on
ipsec master, no kernel change or fault injection. Tested against
that selftest.
net/xfrm/xfrm_iptfs.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index 0313a43aa8a97..0b9642208c71f 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -460,6 +460,12 @@ static bool iptfs_skb_can_add_frags(const struct sk_buff *skb,
* that the destination @skb is compatible with the walk and has space in the
* array for the to be added frag references.
*
+ * The truesize of the source fragments is not known here, so @skb is charged
+ * for the bytes it references, as skb_segment() does for the fragments it
+ * shares. The source keeps its truesize: from here on it never enters
+ * socket, fragment or qdisc memory accounting, so the bytes are charged
+ * once.
+ *
* Return: The number of bytes not added to @skb b/c we reached the end of the
* walk before adding all of @len.
*/
@@ -495,12 +499,14 @@ static int iptfs_skb_add_frags(struct sk_buff *skb,
tofrag->len = len;
skb->len += len;
skb->data_len += len;
+ skb->truesize += len;
return 0;
}
/* advance to next source fragment */
len -= fraglen; /* careful, use dst bv_len */
skb->len += fraglen; /* careful, " " " */
skb->data_len += fraglen; /* careful, " " " */
+ skb->truesize += fraglen; /* careful, " " " */
walk->past += frag->len; /* careful, use src bv_len */
walk->fragi++;
}
--
2.53.0