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 2/3] xfrm: iptfs: count the IP-TFS header in the ESP padding
Date: Sat, 28 Nov 2026 21:50:10 -0700 [thread overview]
Message-ID: <b29b7bec-1cad-412d-a8ae-403ee82259f9@mid.andrii.net> (raw)
In-Reply-To: <8cfaaaca-0668-485f-bc87-f9fde6c4b25d@mid.andrii.net>
__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@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: 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
next prev 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 ` Andrii Tereshchenko [this message]
2026-11-29 4:50 ` [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size 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=b29b7bec-1cad-412d-a8ae-403ee82259f9@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®