[PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size

From: Andrii Tereshchenko

Date: Sat Nov 28 2026 - 23:50:38 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Andrii Tereshchenko <opensource@xxxxxxxxxx>
---
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