mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrii Tereshchenko <opensource@andrii.net>
To: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Simon Horman <horms@kernel.org>,
	Christian Hopps <chopps@labn.net>,
	netdev@vger.kernel.org, ipsec@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Andrii Tereshchenko <opensource@andrii.net>,
	stable@vger.kernel.org
Subject: [PATCH ipsec 1/2] xfrm: iptfs: charge shared fragments to the inner packet's truesize
Date: Sat, 28 Nov 2026 19:00:43 -0700	[thread overview]
Message-ID: <18d5643f-80ac-426d-9c41-9c23de7ef087@mid.andrii.net> (raw)
In-Reply-To: <11df3eb5-b410-41bb-9198-b6c64654d029@mid.andrii.net>

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


  reply	other threads:[~2026-11-29  2:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  2:00 [PATCH ipsec 0/2] " Andrii Tereshchenko
2026-11-29  2:00 ` Andrii Tereshchenko [this message]
2026-11-29  2:00 ` [PATCH ipsec 2/2] selftests: net: test the truesize of IP-TFS inner packets Andrii Tereshchenko

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=18d5643f-80ac-426d-9c41-9c23de7ef087@mid.andrii.net \
    --to=opensource@andrii.net \
    --cc=chopps@labn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=ipsec@lists.linux.dev \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /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

all inboxes | Powered by JetHome®