Skip to contentSkip to conversation

xfrm: esp: restore combined single-frag length gate

PATCH Applied tanjingguo 3 participants 3 messages May 21 – May 26

Subsystems (3)
lore
Share & tools
lore

tanjingguo

author
#0 lore raw

PATCH v2 1/1 xfrm: esp: restore combined single-frag length gate

From 1e6d45378b272fe2f1fce48ed89d6eaa415c00c2 Mon Sep 17 00:00:00 2001
From: Jingguo Tan <[email protected]>
Date: Mon, 18 May 2026 17:06:48 +0800
Subject: [PATCH ipsec v2] xfrm: esp: restore combined single-frag length gate

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")

---
Changes in v2:
- Use the ipsec tree subject prefix.
- Clarify that esp_output_tail() allocates after esp_output_head() appends 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(-)
net/ipv4/esp4.c +2 -2
index 6a5febbdbee49..c62dfe049ee7 100644
@@ -419,8 +419,8 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 			return err;
 	}
 
-	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;
 
 	if (!skb_cloned(skb)) {
net/ipv6/esp6.c +2 -2
index 9c06c5a1419dc..2516a4dc6d78 100644
@@ -448,8 +448,8 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
 			return err;
 	}
 
-	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;
 
 	if (!skb_cloned(skb)) {
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw

Note that you must respect a 24-hour delay between reposts of the same patch:
https://docs.kernel.org/process/maintainer-netdev.html#tl-dr

Quoted 4 lines · tanjingguo

Changes in v2:
- Use the ipsec tree subject prefix.
- Clarify that esp_output_tail() allocates after esp_output_head() appends tailen.

Thanks for the clarification.

Quoted 12 lines

- 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(-)
net/ipv4/esp4.c +0 -0
index 6a5febbdbee49..c62dfe049ee7 100644

net/ipv4/esp4.c int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * · line 424

Quoted 8 lines
net/ipv4/esp4.c +2 -2
@@ -419,8 +419,8 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 			return err;
 	}
 
-	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;

nit: you didn't need to wrap here, the total length of this line is under 80 columns.

But other than that, the fix looks correct to me:

I don't know if Steffen will require a repost or apply this directly, so please wait at least the standard 24 hours.

Thanks,

Signature · 1 line
Sabrina
maintainer Applied
#2 lore raw
Quoted 36 lines · Sabrina Dubroca

Note that you must respect a 24-hour delay between reposts of the same patch:
https://docs.kernel.org/process/maintainer-netdev.html#tl-dr

Quoted 4 lines · tanjingguo

Changes in v2:
- Use the ipsec tree subject prefix.
- Clarify that esp_output_tail() allocates after esp_output_head() appends tailen.

Thanks for the clarification.

Quoted 12 lines

- 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(-)
net/ipv4/esp4.c +0 -0
index 6a5febbdbee49..c62dfe049ee7 100644

net/ipv4/esp4.c int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * · line 424

Quoted 8 lines
net/ipv4/esp4.c +2 -2
@@ -419,8 +419,8 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 			return err;
 	}
 
-	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;

nit: you didn't need to wrap here, the total length of this line is under 80 columns.

Quoted 5 lines

But other than that, the fix looks correct to me:

I don't know if Steffen will require a repost or apply this directly, so please wait at least the standard 24 hours.

I've applied it directly, thanks everyone!