[PATCH ipsec v2] xfrm: esp: restore combined single-frag length ga=

From: Jingguo Tan

Date: Mon May 18 2026 - 05:06:48 EST


The ESP out-of-place fast path appends the trailer in esp_output_head()
before esp_output_tail() allocates the destination page frag. The
head-side gate currently checks skb->data_len and tailen separately, but
the tail code allocates a single destination frag from the combined
post-trailer skb->data_len.

Reject the page-frag fast path when the combined aligned length exceeds a
page. Otherwise skb_page_frag_refill() may fall back to a single page while
the destination sg still spans the combined skb->data_len.

Restore this combined-length page gate for both IPv4 and IPv6.

Fixes: 5bd8baab087d ("esp: limit skb_page_frag_refill use to a single page"=
)
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lin Ma <malin89@xxxxxxxxxx>
Signed-off-by: Chenyuan Mi <michenyuan@xxxxxxxxxx>
Signed-off-by: Jingguo Tan <tanjingguo@xxxxxxxxxx>
---
Changes in v2:
- Use the ipsec tree subject prefix.
- Clarify that esp_output_tail() allocates after esp_output_head() append=
s
tailen.
- Avoid shadowing the existing allocsize variable.
- v1: https://lore.kernel.org/netdev/ag7kxJ39XQaVY1Mb@krikkit/T/#t

net/ipv4/esp4.c | 4 ++--
net/ipv6/esp6.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 6a5febbdbee49..c62dfe049ee7 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -419,8 +419,8 @@ int esp_output_head(struct xfrm_state *x, struct sk_buf=
f *skb, struct esp_info *
return err;
}
=20
- if (ALIGN(tailen, L1_CACHE_BYTES) > PAGE_SIZE ||
- ALIGN(skb->data_len, L1_CACHE_BYTES) > PAGE_SIZE)
+ if (ALIGN(skb->data_len + tailen, L1_CACHE_BYTES) >
+ PAGE_SIZE)
goto cow;
=20
if (!skb_cloned(skb)) {
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 9c06c5a1419dc..2516a4dc6d78 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -448,8 +448,8 @@ int esp6_output_head(struct xfrm_state *x, struct sk_bu=
ff *skb, struct esp_info
return err;
}
=20
- if (ALIGN(tailen, L1_CACHE_BYTES) > PAGE_SIZE ||
- ALIGN(skb->data_len, L1_CACHE_BYTES) > PAGE_SIZE)
+ if (ALIGN(skb->data_len + tailen, L1_CACHE_BYTES) >
+ PAGE_SIZE)
goto cow;
=20
if (!skb_cloned(skb)) {
--=20
2.43.0