[PATCH ipsec 2/3] xfrm: iptfs: count the IP-TFS header in the ESP padding
From: Andrii Tereshchenko
Date: Sat Nov 28 2026 - 23:50:39 EST
__iptfs_get_inner_mtu() aligns the room left for data to the cipher
block size without the 4-byte IP-TFS header, which header_len counts but
which ESP pads together with the data. With AES-CBC suites, ESP then
pads full outer packets past the MTU by up to 12 bytes: 1512 bytes on a
1500-byte IPv4 path with HMAC-SHA1-96. Their outer header has DF set,
so they are dropped, and forwarded traffic that fills outer packets is
lost; a TCP connection through such an SA moves no data. AEADs such as
AES-GCM are not affected.
Count the IP-TFS header (x->props.enc_hdr_len) in the aligned region,
as ESP does.
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: of 200 datagrams of 1500 bytes that a gateway forwarded into
an AES-CBC, HMAC-SHA1-96 SA over 1500-byte links, none arrived.
Tested: with this patch all 200 arrive, and the largest outer packet
is 1496 bytes.
Not tested: hardware ESP offload, the existing net selftests.
net/xfrm/xfrm_iptfs.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index c204f41a57f59..bd4d445428d6c 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -2501,15 +2501,20 @@ static u32 __iptfs_get_inner_mtu(struct xfrm_state *x, int outer_mtu)
aead = x->data;
blksize = ALIGN(crypto_aead_blocksize(aead), 4);
- overhead = x->props.header_len + crypto_aead_authsize(aead);
+ /* ESP pads the IP-TFS header (enc_hdr_len), the data and its own
+ * 2-byte trailer together to blksize, so the IP-TFS header belongs
+ * to the aligned payload, not to the overhead.
+ */
+ overhead = x->props.header_len - x->props.enc_hdr_len +
+ crypto_aead_authsize(aead);
if (outer_mtu <= overhead)
return 0;
payload = (outer_mtu - overhead) & ~(blksize - 1);
- if (payload <= 2)
+ if (payload <= x->props.enc_hdr_len + 2)
return 0;
- return payload - 2;
+ return payload - x->props.enc_hdr_len - 2;
}
/**
--
2.53.0