xfrm: esp: restore combined single-frag length gate
Subsystems (3)
PATCH 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 net] xfrm: esp: restore combined single-frag length gate
The ESP out-of-place fast path still consumes the combined post-trailer skb->data_len as a single destination frag in esp_output_tail()/ esp6_output_tail(). The head-side gate must therefore reject any case where ALIGN(skb->data_len + tailen, L1_CACHE_BYTES) exceeds PAGE_SIZE, otherwise skb_page_frag_refill() may fall back to a single page and the destination sg will overrun it.
Restore a combined-length page gate before entering the page-frag fast path for both IPv4 and IPv6.
---
net/ipv4/esp4.c | 5 +++-- net/ipv6/esp6.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
net/ipv4/esp4.c +3 -2
@@ -410,6 +410,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *struct page *page;struct sk_buff *trailer;int tailen = esp->tailen; +unsigned int allocsize;/* this is non-NULL only with TCP/UDP Encapsulation */ if (x->encap) {
@@ -419,8 +420,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 ) + allocsize =ALIGN (skb->data_len + tailen,L1_CACHE_BYTES ); +if (allocsize >PAGE_SIZE ) goto cow;if (!skb_cloned (skb)) {
net/ipv6/esp6.c +3 -2
@@ -440,6 +440,7 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_infostruct page *page;struct sk_buff *trailer;int tailen = esp->tailen; +unsigned int allocsize;if (x->encap) {int err =esp6_output_encap (x, skb, esp);
@@ -448,8 +449,8 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_inforeturn err; } -if (ALIGN (tailen,L1_CACHE_BYTES ) >PAGE_SIZE || -ALIGN (skb->data_len,L1_CACHE_BYTES ) >PAGE_SIZE ) + allocsize =ALIGN (skb->data_len + tailen,L1_CACHE_BYTES ); +if (allocsize >PAGE_SIZE ) goto cow;if (!skb_cloned (skb)) {
Signature · 1 line
2.43.0
Hello,
note: patches to xfrm should go through the "ipsec" tree, not "net" (with the subject prefix [PATCH ipsec]).
Quoted 11 lines · tanjingguo
From
1e6d45378b272fe2f1fce48ed89d6eaa415c00c2Mon Sep 17 00:00:00 2001
From: Jingguo Tan <[email protected]>
Date: Mon, 18 May 2026 17:06:48 +0800
Subject: [PATCH net] xfrm: esp: restore combined single-frag length gateThe ESP out-of-place fast path still consumes the combined post-trailer
skb->data_lenas a single destination frag in esp_output_tail()/esp6_output_tail(). The head-side gate must therefore reject any case whereALIGN(skb->data_len + tailen, L1_CACHE_BYTES)exceedsPAGE_SIZE, otherwiseskb_page_frag_refill()may fall back to a single page and the destination sg will overrun it.
If I'm following correctly, the issue comes from the skb_len_add(tailen)? So esp_output_tail() does skb_page_frag_refill() with [what we checked in esp_output_head() + tailen]?
Quoted 19 lines
Restore a combined-length page gate before entering the page-frag fast path for both IPv4 and IPv6.
Fixes 5bd8baab087d ("esp: limit skb_page_frag_refill use to a single page")Signed-off-by Lin Ma <[email protected]>Signed-off-by Chenyuan Mi <[email protected]>Signed-off-by Jingguo Tan <[email protected]>---
net/ipv4/esp4.c | 5 +++-- net/ipv6/esp6.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)net/ipv4/esp4.c +0
-0
net/ipv4/esp4.c int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * · line 413
Quoted 4 lines
net/ipv4/esp4.c +1
-0@@ -410,6 +410,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *struct page *page;struct sk_buff *trailer;int tailen = esp->tailen; +unsigned int allocsize;
nit: there's already an allocsize variable in this function. no shadowing please.
Signature · 1 line
Sabrina