mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH ipsec 0/2] xfrm: iptfs: charge shared fragments to the inner packet's truesize
@ 2026-11-29  2:00 Andrii Tereshchenko
  2026-11-29  2:00 ` [PATCH ipsec 1/2] " Andrii Tereshchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Andrii Tereshchenko @ 2026-11-29  2:00 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman, Christian Hopps, netdev, ipsec, linux-kernel,
	Andrii Tereshchenko

1/2 makes the inner packets that share the outer packet's page fragments
pay for them in truesize. Without it, any sender whose large packets
cross the tunnel can trip a WARN in skb_try_coalesce() on the receiver,
and receive queues hold more than they are charged for. 2/2 adds a
selftest.

Andrii Tereshchenko (2):
  xfrm: iptfs: charge shared fragments to the inner packet's truesize
  selftests: net: test the truesize of IP-TFS inner packets

 MAINTAINERS                                   |   1 +
 net/xfrm/xfrm_iptfs.c                         |   8 +
 tools/testing/selftests/net/.gitignore        |   1 +
 tools/testing/selftests/net/Makefile          |   2 +
 tools/testing/selftests/net/config            |   2 +
 .../selftests/net/xfrm_iptfs_truesize.c       | 297 ++++++++++++++++++
 .../selftests/net/xfrm_iptfs_truesize.sh      | 135 ++++++++
 7 files changed, 446 insertions(+)
 create mode 100644 tools/testing/selftests/net/xfrm_iptfs_truesize.c
 create mode 100755 tools/testing/selftests/net/xfrm_iptfs_truesize.sh


base-commit: 1213df0bc5993e479706c5eba5830243d778f164
-- 
2.53.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH ipsec 1/2] xfrm: iptfs: charge shared fragments to the inner packet's truesize
  2026-11-29  2:00 [PATCH ipsec 0/2] xfrm: iptfs: charge shared fragments to the inner packet's truesize Andrii Tereshchenko
@ 2026-11-29  2:00 ` Andrii Tereshchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andrii Tereshchenko @ 2026-11-29  2:00 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman, Christian Hopps, netdev, ipsec, linux-kernel,
	Andrii Tereshchenko, stable

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@vger.kernel.org
Signed-off-by: Andrii Tereshchenko <opensource@andrii.net>
---
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29  2:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29  2:00 [PATCH ipsec 0/2] xfrm: iptfs: charge shared fragments to the inner packet's truesize Andrii Tereshchenko
2026-11-29  2:00 ` [PATCH ipsec 1/2] " Andrii Tereshchenko

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®