* [PATCH ipsec 0/3] xfrm: iptfs: fix the outer packet size arithmetic
@ 2026-11-29 4:50 Andrii Tereshchenko
2026-11-29 4:50 ` [PATCH ipsec 1/3] xfrm: iptfs: don't let the inner MTU wrap around Andrii Tereshchenko
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Andrii Tereshchenko @ 2026-11-29 4:50 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Willem de Bruijn, Christian Hopps, netdev, ipsec, linux-kernel,
stable
Three bugs in how IP-TFS sizes its outer packets:
1/3 the inner MTU wraps around when the SA's overhead exceeds the path
MTU; with ESP offload an unprivileged user can panic the kernel.
2/3 ESP pads the IP-TFS header that the inner MTU leaves out, so full
outer packets of AES-CBC SAs exceed the MTU and are dropped.
3/3 pkt_size leaves out ESP's padding, trailer and ICV, and is not
converted again when the SA is migrated.
All three were found by an AI code review agent and reproduced on
ipsec master in KVM guests; each patch says how it was tested. 1/3 was
reported privately to the IPsec maintainers and security@kernel.org on
2026-11-20. A selftest for all three follows once 1/3 is in the
stable trees.
Andrii Tereshchenko
Andrii Tereshchenko (3):
xfrm: iptfs: don't let the inner MTU wrap around
xfrm: iptfs: count the IP-TFS header in the ESP padding
xfrm: iptfs: keep outer packets within pkt_size
net/xfrm/xfrm_iptfs.c | 50 +++++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 18 deletions(-)
base-commit: 1213df0bc5993e479706c5eba5830243d778f164
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH ipsec 1/3] xfrm: iptfs: don't let the inner MTU wrap around
2026-11-29 4:50 [PATCH ipsec 0/3] xfrm: iptfs: fix the outer packet size arithmetic Andrii Tereshchenko
@ 2026-11-29 4:50 ` Andrii Tereshchenko
2026-11-30 4:52 ` netdev-bot+sashiko
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 ` [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size Andrii Tereshchenko
2 siblings, 1 reply; 6+ messages in thread
From: Andrii Tereshchenko @ 2026-11-29 4:50 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Willem de Bruijn, Christian Hopps, netdev, ipsec, linux-kernel,
stable
__iptfs_get_inner_mtu() subtracts the SA's overhead from the outer MTU
without checking that it fits. With an IPv4 MTU of 68 and AES-CBC-256
with HMAC-SHA512-256 (80 bytes of overhead) it wraps to almost 4G,
IP-TFS builds oversized packets, and with ESP offload esp_xmit() panics
on a fragment of one. An unprivileged user can set this up in a user
namespace:
skbuff: skb_under_panic: ... len:66 put:-14 ... dev:v0
esp_xmit+0x398/0x7c0
validate_xmit_xfrm+0x65d/0x710
Return 0 when no data fits and drop such packets; the get_inner_mtu
callback then returns 1, as xfrm_state_mtu() 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 with ESP offload
built in, without kernel changes or fault injection: an SA that uid
65534 set up in namespaces of its own over a 68-byte MTU panics the
kernel on 2 of 2 boots. The reproducer is available to the maintainers
on request.
Tested: with this series the same setup survives 2 of 2 boots with
panic_on_warn=1, and IP-TFS drops the packets (XfrmOutError).
Not tested: an IPv6 outer header, hardware ESP offload, the existing
net selftests.
net/xfrm/xfrm_iptfs.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index 0313a43aa8a97..c204f41a57f59 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -2215,10 +2215,11 @@ static void iptfs_output_queued(struct xfrm_state *x, struct sk_buff_head *list)
skb->protocol = x->outer_mode.family == AF_INET ? htons(ETH_P_IP) :
htons(ETH_P_IPV6);
- if (skb->len > mtu && xtfs->cfg.dont_frag) {
+ if (!mtu || (skb->len > mtu && xtfs->cfg.dont_frag)) {
/* We handle this case before enqueueing so we are only
* here b/c MTU changed after we enqueued before we
- * dequeued, just drop these.
+ * dequeued, just drop these. An mtu of 0 means that the
+ * outer MTU cannot carry any data at all.
*/
XFRM_INC_STATS(xs_net(x), LINUX_MIB_XFRMOUTERROR);
@@ -2490,17 +2491,25 @@ static int iptfs_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
* @x: xfrm state.
* @outer_mtu: the outer mtu
*
- * Return: Correct MTU taking in to account the encap overhead.
+ * Return: Correct MTU taking in to account the encap overhead, or 0 if the
+ * outer MTU leaves no room for data.
*/
static u32 __iptfs_get_inner_mtu(struct xfrm_state *x, int outer_mtu)
{
struct crypto_aead *aead;
- u32 blksize;
+ u32 blksize, overhead, payload;
aead = x->data;
blksize = ALIGN(crypto_aead_blocksize(aead), 4);
- return ((outer_mtu - x->props.header_len - crypto_aead_authsize(aead)) &
- ~(blksize - 1)) - 2;
+ overhead = x->props.header_len + crypto_aead_authsize(aead);
+ if (outer_mtu <= overhead)
+ return 0;
+
+ payload = (outer_mtu - overhead) & ~(blksize - 1);
+ if (payload <= 2)
+ return 0;
+
+ return payload - 2;
}
/**
@@ -2517,7 +2526,8 @@ static u32 iptfs_get_inner_mtu(struct xfrm_state *x, int outer_mtu)
/* If not dont-frag we have no MTU */
if (!xtfs->cfg.dont_frag)
return x->outer_mode.family == AF_INET ? IP_MAX_MTU : IP6_MAX_MTU;
- return __iptfs_get_inner_mtu(x, outer_mtu);
+ /* Like xfrm_state_mtu() for the other modes, never return 0 */
+ return __iptfs_get_inner_mtu(x, outer_mtu) ?: 1;
}
/**
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH ipsec 2/3] xfrm: iptfs: count the IP-TFS header in the ESP padding
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
2026-11-29 4:50 ` [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size Andrii Tereshchenko
2 siblings, 0 replies; 6+ messages in thread
From: Andrii Tereshchenko @ 2026-11-29 4:50 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Willem de Bruijn, Christian Hopps, netdev, ipsec, linux-kernel,
stable
__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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size
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
2026-11-30 4:52 ` netdev-bot+sashiko
2 siblings, 1 reply; 6+ messages in thread
From: Andrii Tereshchenko @ 2026-11-29 4:50 UTC (permalink / raw)
To: Steffen Klassert, Herbert Xu, David S. Miller
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Willem de Bruijn, Christian Hopps, netdev, ipsec, linux-kernel,
stable
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH ipsec 1/3] xfrm: iptfs: don't let the inner MTU wrap around
2026-11-29 4:50 ` [PATCH ipsec 1/3] xfrm: iptfs: don't let the inner MTU wrap around Andrii Tereshchenko
@ 2026-11-30 4:52 ` netdev-bot+sashiko
0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 4:52 UTC (permalink / raw)
To: opensource
Cc: steffen.klassert, herbert, davem, edumazet, kuba, pabeni, horms,
willemb, chopps, netdev, ipsec, linux-kernel, stable
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] This patch makes __iptfs_get_inner_mtu() return 0 when nothing
fits.
- [Low] The kernel-doc of iptfs_get_inner_mtu()
(net/xfrm/xfrm_iptfs.c:2535) still says 'Return: Correct MTU taking in…
--
xfrm: iptfs: don't let the inner MTU wrap around
This patch makes __iptfs_get_inner_mtu() return 0 instead of wrapping
around when the outer MTU is too small for the SA overhead. It also drops
such packets in iptfs_output_queued(). The get_inner_mtu callback raises
the 0 to 1, as xfrm_state_mtu() does.
> diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
> index 76272b0a18296..ea88c6618ca73 100644
> --- a/net/xfrm/xfrm_iptfs.c
> +++ b/net/xfrm/xfrm_iptfs.c
[ ... ]
> @@ -2505,17 +2506,25 @@ static int iptfs_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
> * @x: xfrm state.
> * @outer_mtu: the outer mtu
> *
> - * Return: Correct MTU taking in to account the encap overhead.
> + * Return: Correct MTU taking in to account the encap overhead, or 0 if the
> + * outer MTU leaves no room for data.
> */
> static u32 __iptfs_get_inner_mtu(struct xfrm_state *x, int outer_mtu)
> {
> struct crypto_aead *aead;
> - u32 blksize;
> + u32 blksize, overhead, payload;
>
> aead = x->data;
> blksize = ALIGN(crypto_aead_blocksize(aead), 4);
> - return ((outer_mtu - x->props.header_len - crypto_aead_authsize(aead)) &
> - ~(blksize - 1)) - 2;
> + overhead = x->props.header_len + crypto_aead_authsize(aead);
> + if (outer_mtu <= overhead)
> + return 0;
> +
> + payload = (outer_mtu - overhead) & ~(blksize - 1);
> + if (payload <= 2)
> + return 0;
> +
> + return payload - 2;
> }
[Severity: Low]
Only iptfs_get_inner_mtu() raises the new 0 return value to 1.
iptfs_get_cur_pmtu() is the other caller, and it passes the raw value
through:
net/xfrm/xfrm_iptfs.c:iptfs_get_cur_pmtu() {
...
u32 pmtu = __iptfs_get_inner_mtu(x, xdst->child_mtu_cached);
if (payload_mtu && payload_mtu < pmtu)
pmtu = payload_mtu;
return pmtu;
}
Take a dont_frag SA whose outer MTU is at most the overhead, such as the
IPv4 MTU 68 with AES-CBC-256/HMAC-SHA512-256 case from the commit
message. In that case iptfs_output_collect() passes pmtu == 0 to
iptfs_is_too_big(). That function treats every packet as too big and
reports the 0:
net/xfrm/xfrm_iptfs.c:iptfs_is_too_big() {
...
if (sk)
xfrm_local_error(skb, pmtu);
else if (ip_hdr(skb)->version == 4)
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(pmtu));
else
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, pmtu);
...
}
Would this put an MTU of 0 in the ICMP FRAG_NEEDED and PKT_TOOBIG
messages and in the socket error queue? For the same SA,
xfrm_state_mtu() reports 1.
Before this patch the value wrapped to about 4G, so this path never ran
for this configuration. iptfs_output_queued() drops on !mtu without
reporting any MTU, so this enqueue path is the only place that reports 0.
The later patches in the series leave iptfs_get_cur_pmtu() and
iptfs_is_too_big() unchanged here. After "xfrm: iptfs: keep outer packets
within pkt_size", iptfs_get_cur_pmtu() still returns 0 when
child_mtu_cached leaves no room.
The packets are dropped either way, so only the reported value differs.
Should iptfs_get_cur_pmtu() or iptfs_is_too_big() use the same "?: 1"
floor so both paths report the same MTU?
>
> /**
> @@ -2532,7 +2541,8 @@ static u32 iptfs_get_inner_mtu(struct xfrm_state *x, int outer_mtu)
> /* If not dont-frag we have no MTU */
> if (!xtfs->cfg.dont_frag)
> return x->outer_mode.family == AF_INET ? IP_MAX_MTU : IP6_MAX_MTU;
> - return __iptfs_get_inner_mtu(x, outer_mtu);
> + /* Like xfrm_state_mtu() for the other modes, never return 0 */
> + return __iptfs_get_inner_mtu(x, outer_mtu) ?: 1;
> }
[Severity: Low]
This isn't a bug, but the kernel-doc above iptfs_get_inner_mtu() still
says:
* Return: Correct MTU taking in to account the encap overhead.
The function now also returns 1 when the outer MTU can't carry any data.
The patch updated the Return: line of __iptfs_get_inner_mtu() for its 0
case. Could this Return: line mention the 1 case too? The later patches
in the series don't change this comment either.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/8cfaaaca-0668-485f-bc87-f9fde6c4b25d%40mid.andrii.net
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size
2026-11-29 4:50 ` [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size Andrii Tereshchenko
@ 2026-11-30 4:52 ` netdev-bot+sashiko
0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 4:52 UTC (permalink / raw)
To: opensource
Cc: steffen.klassert, herbert, davem, edumazet, kuba, pabeni, horms,
willemb, chopps, netdev, ipsec, linux-kernel, stable
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] This patch checks pkt_size only once, in iptfs_user_init(),
against the header_len the SA has when it is created.
--
xfrm: iptfs: keep outer packets within pkt_size
This commit removes payload_mtu. iptfs_get_cur_pmtu() now converts
XFRMA_IPTFS_PKT_SIZE into an inner data budget with
__iptfs_get_inner_mtu() each time it is used, so ESP padding, trailer
and ICV are counted, and header_len changes from SA migration are
picked up. iptfs_user_init() also refuses a pkt_size that leaves no
room for data.
> diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
> index 9ecc2a39b6543..172da3940a32f 100644
> --- a/net/xfrm/xfrm_iptfs.c
> +++ b/net/xfrm/xfrm_iptfs.c
[ ... ]
> @@ -1812,11 +1810,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;
> }
> @@ -2589,13 +2589,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)) {
[Severity: Medium]
This check only runs when the SA is created, against the header_len the
SA has at that point. Is it also needed on the migration path, given that
the new comment in iptfs_get_cur_pmtu() says migration can change
header_len?
On migration, xfrm_state_migrate_create() goes through
xfrm_state_clone_and_setup()->iptfs_clone_state(). That function
kmemdup()s orig->mode_data, so cfg.pkt_size is copied unchanged:
net/xfrm/xfrm_iptfs.c:iptfs_clone_state() {
...
xtfs = kmemdup(orig->mode_data, sizeof(*xtfs), GFP_KERNEL);
...
}
xfrm_state_clone_and_setup() then sets x->props.family = m->new_family
and may set a new encap. After that, xfrm_init_state() rebuilds
header_len. iptfs_init_state() takes the clone branch, and
iptfs_user_init() is not called again:
net/xfrm/xfrm_iptfs.c:iptfs_init_state() {
if (x->mode_data) {
/* We have arrived here from xfrm_state_clone() */
xtfs = x->mode_data;
} else {
...
__iptfs_init_state(x, xtfs);
...
}
Take AES-GCM as an example. On IPv4 the overhead is 52 bytes with 4-byte
alignment, so iptfs_user_init() accepts a pkt_size of 60 to 79. After
migration to IPv6 the overhead becomes 72. __iptfs_get_inner_mtu(x,
pkt_size) then returns 0, and iptfs_get_cur_pmtu() returns
min(pmtu, 0) = 0. UDP encap adds 8 bytes and opens a similar window.
With pmtu == 0, could every outbound packet on the migrated SA be
dropped? Without dont_frag, iptfs_output_queued() drops each one here,
and only LINUX_MIB_XFRMOUTERROR is incremented:
if (!mtu || (skb->len > mtu && xtfs->cfg.dont_frag)) {
With dont_frag set, iptfs_output_collect()->iptfs_is_too_big() would
send ICMP_FRAG_NEEDED or ICMPV6_PKT_TOOBIG advertising an MTU of 0, or
call xfrm_local_error(skb, 0), for every packet.
Before this patch, the stale payload_mtu stayed non-zero, so traffic
kept flowing after such a migration. iptfs_get_inner_mtu() keeps a
"?: 1" floor so it never returns 0. iptfs_get_cur_pmtu() has no
equivalent.
Could the pkt_size check be repeated in the clone path of
iptfs_init_state() after __iptfs_init_state() recomputes header_len, so
that such a migration fails instead of creating an SA that drops all
traffic?
> 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;
> }
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/8cfaaaca-0668-485f-bc87-f9fde6c4b25d%40mid.andrii.net
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-30 4:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-30 4:52 ` netdev-bot+sashiko
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 ` [PATCH ipsec 3/3] xfrm: iptfs: keep outer packets within pkt_size Andrii Tereshchenko
2026-11-30 4:52 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox