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>,
	Simon Horman <horms@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Christian Hopps <chopps@labn.net>,
	netdev@vger.kernel.org, ipsec@lists.linux.dev,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size
Date: Sat, 28 Nov 2026 21:50:11 -0700	[thread overview]
Message-ID: <d72476bc-56b1-4d0a-8e1b-e21107a51564@mid.andrii.net> (raw)
In-Reply-To: <8cfaaaca-0668-485f-bc87-f9fde6c4b25d@mid.andrii.net>

XFRMA_IPTFS_PKT_SIZE is the size of the outer packet, but
iptfs_user_init() turns it into a data budget by taking away only
header_len, not ESP's padding, trailer and ICV. Full outer packets are
therefore larger than pkt_size, 1020 bytes for 1000 with AES-GCM, and
on a path that pkt_size was set to fit, for example one that filters
ICMP, they are dropped without a trace. The budget is also kept when
the SA is migrated to another family or encapsulation, which changes
header_len: moving it to IPv6 adds another 20 bytes.

Drop payload_mtu, convert pkt_size with __iptfs_get_inner_mtu() each
time it is used, and refuse a pkt_size that leaves no room for data.

Made with an AI coding assistant, reviewed by the submitter.

Fixes: 4b3faf610cc6 ("xfrm: iptfs: add new iptfs xfrm mode impl")
Cc: stable@vger.kernel.org
Signed-off-by: Andrii Tereshchenko <opensource@andrii.net>
---
Found by an AI code review agent.
Validated in KVM guests on unmodified ipsec master, without kernel
changes: with AES-GCM and a pkt_size of 1000, none of 200 forwarded
datagrams crossed a router whose next link has an MTU of 1000 and
which sends no ICMP errors, and a pkt_size of 50 was accepted.
Tested: with this patch all 200 cross and a pkt_size of 50 is refused.
The migration case was tested with a KUnit case of my own, not posted.
Not tested: hardware ESP offload, the existing net selftests.

 net/xfrm/xfrm_iptfs.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index bd4d445428d6c..49b761d0a6be1 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -133,7 +133,6 @@ struct skb_wseq {
  * @init_delay_ns: nanoseconds to wait to send initial IPTFS packet.
  * @iptfs_timer: output timer.
  * @iptfs_settime: time the output timer was set.
- * @payload_mtu: max payload size.
  * @w_seq_set: true after first seq received.
  * @w_wantseq: waiting for this seq number as next to process (in order).
  * @w_saved: the saved buf array (reorder window).
@@ -158,7 +157,6 @@ struct xfrm_iptfs_data {
 	u64 init_delay_ns;	    /* nanoseconds */
 	struct hrtimer iptfs_timer; /* output timer */
 	time64_t iptfs_settime;	    /* time timer was set */
-	u32 payload_mtu;	    /* max payload size */
 
 	/* Tunnel input reordering */
 	bool w_seq_set;		  /* true after first seq received */
@@ -1804,11 +1802,13 @@ static int iptfs_get_cur_pmtu(struct xfrm_state *x, struct xfrm_iptfs_data *xtfs
 			      struct sk_buff *skb)
 {
 	struct xfrm_dst *xdst = (struct xfrm_dst *)skb_dst(skb);
-	u32 payload_mtu = xtfs->payload_mtu;
 	u32 pmtu = __iptfs_get_inner_mtu(x, xdst->child_mtu_cached);
 
-	if (payload_mtu && payload_mtu < pmtu)
-		pmtu = payload_mtu;
+	/* Converted here rather than once, as migration can change
+	 * header_len.
+	 */
+	if (xtfs->cfg.pkt_size)
+		pmtu = min(pmtu, __iptfs_get_inner_mtu(x, xtfs->cfg.pkt_size));
 
 	return pmtu;
 }
@@ -2574,13 +2574,12 @@ static int iptfs_user_init(struct net *net, struct xfrm_state *x,
 	}
 	if (attrs[XFRMA_IPTFS_PKT_SIZE]) {
 		xc->pkt_size = nla_get_u32(attrs[XFRMA_IPTFS_PKT_SIZE]);
-		if (!xc->pkt_size) {
-			xtfs->payload_mtu = 0;
-		} else if (xc->pkt_size > x->props.header_len) {
-			xtfs->payload_mtu = xc->pkt_size - x->props.header_len;
-		} else {
+		/* pkt_size is the whole outer packet, ESP padding, trailer
+		 * and ICV included; iptfs_get_cur_pmtu() converts it.
+		 */
+		if (xc->pkt_size && !__iptfs_get_inner_mtu(x, xc->pkt_size)) {
 			NL_SET_ERR_MSG(extack,
-				       "Packet size must be 0 or greater than IPTFS/ESP header length");
+				       "Packet size must be 0 or greater than IPTFS/ESP overhead");
 			return -EINVAL;
 		}
 	}
-- 
2.53.0


      parent reply	other threads:[~2026-11-29  4:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  4:50 [PATCH ipsec 0/3] xfrm: iptfs: fix the outer packet size arithmetic Andrii Tereshchenko
2026-11-29  4:50 ` [PATCH ipsec 1/3] xfrm: iptfs: don't let the inner MTU wrap around Andrii Tereshchenko
2026-11-29  4:50 ` [PATCH ipsec 2/3] xfrm: iptfs: count the IP-TFS header in the ESP padding Andrii Tereshchenko
2026-11-29  4:50 ` Andrii Tereshchenko [this message]

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=d72476bc-56b1-4d0a-8e1b-e21107a51564@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=willemb@google.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®