* [PATCH 0/6] pull request (net): ipsec 2026-06-10
@ 2026-06-10 14:07 Steffen Klassert
2026-06-10 14:07 ` [PATCH 1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags() Steffen Klassert
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Steffen Klassert @ 2026-06-10 14:07 UTC (permalink / raw)
To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev
1) xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags()
Propagate SKBFL_SHARED_FRAG when paged fragments are moved between
skbs so ESP can decide whether in-place crypto is safe.
2) xfrm: iptfs: fix use-after-free on first_skb in __input_process_payload
Replace the unlocked read of xtfs->ra_newskb with a local flag so a
concurrent reassembly can no longer free first_skb between
spin_unlock and the post-loop check.
3) xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx()
Prune the inexact bin under xfrm_policy_lock so a concurrent
xfrm_hash_rebuild() can no longer free it before xfrm_policy_kill()
dereferences it.
4) xfrm: iptfs: fix ABBA deadlock in iptfs_destroy_state()
Move hrtimer_cancel() for the output and drop timers ahead of their
spinlocks, breaking the softirq/lock cycle that could deadlock
against the timer callbacks on SMP.
5) xfrm: espintcp: do not reuse an in-progress partial send
Fail a new send when espintcp_push_msgs() returns with emsg->len
still set, so a blocking caller can no longer overwrite ctx->partial
while a previous transfer still owns it.
6) esp: fix page frag reference leak on skb_to_sgvec failure
Add a flag to esp_ssg_unref() to unconditionally unref the source
scatterlist, releasing the old page references that are otherwise
leaked when the second skb_to_sgvec() in esp_output_tail() fails.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 78ef59e7a6459b16f8102e0ee1c718443323d1af:
Merge branch 'wireguard-fixes-for-7-1-rc6' (2026-05-29 13:01:31 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git tags/ipsec-2026-06-10
for you to fetch changes up to 26aad08a928901296aabfbc7a33ecb951656bb98:
esp: fix page frag reference leak on skb_to_sgvec failure (2026-06-09 15:58:17 +0200)
----------------------------------------------------------------
ipsec-2026-06-10
----------------------------------------------------------------
Alessandro Schino (1):
esp: fix page frag reference leak on skb_to_sgvec failure
Sanghyun Park (1):
xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx()
Takao Sato (1):
xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags()
Tristan Madani (1):
xfrm: iptfs: fix ABBA deadlock in iptfs_destroy_state()
Wyatt Feng (1):
xfrm: espintcp: do not reuse an in-progress partial send
Zhenghang Xiao (1):
xfrm: iptfs: fix use-after-free on first_skb in __input_process_payload
net/ipv4/esp4.c | 17 +++++++++++------
net/ipv6/esp6.c | 17 +++++++++++------
net/xfrm/espintcp.c | 4 ++++
net/xfrm/xfrm_iptfs.c | 11 +++++++----
net/xfrm/xfrm_policy.c | 13 ++-----------
5 files changed, 35 insertions(+), 27 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags() 2026-06-10 14:07 [PATCH 0/6] pull request (net): ipsec 2026-06-10 Steffen Klassert @ 2026-06-10 14:07 ` Steffen Klassert 2026-06-11 10:10 ` patchwork-bot+netdevbpf 2026-06-10 14:07 ` [PATCH 2/6] xfrm: iptfs: fix use-after-free on first_skb in __input_process_payload Steffen Klassert ` (4 subsequent siblings) 5 siblings, 1 reply; 8+ messages in thread From: Steffen Klassert @ 2026-06-10 14:07 UTC (permalink / raw) To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev From: Takao Sato <takaosato1997@gmail.com> iptfs_consume_frags() transfers paged fragments from one socket buffer to another but fails to propagate the SKBFL_SHARED_FRAG flag. This is the same class of bug that was fixed in skb_try_coalesce() for CVE-2026-46300: when fragments backed by read-only page-cache pages are merged, the marker indicating their shared nature must be preserved so that ESP can decide correctly whether in-place encryption is safe. Apply the same two-line fix used in skb_try_coalesce() to iptfs_consume_frags(). Fixes: b96ba312e21c ("xfrm: iptfs: share page fragments of inner packets") Cc: stable@vger.kernel.org # 6.14+ Signed-off-by: Takao Sato <takaosato1997@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> --- net/xfrm/xfrm_iptfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index 6c6bbc040517..62ba828632f1 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -2168,6 +2168,8 @@ static void iptfs_consume_frags(struct sk_buff *to, struct sk_buff *from) memcpy(&toi->frags[toi->nr_frags], fromi->frags, sizeof(fromi->frags[0]) * fromi->nr_frags); toi->nr_frags += fromi->nr_frags; + if (fromi->nr_frags) + toi->flags |= fromi->flags & SKBFL_SHARED_FRAG; fromi->nr_frags = 0; from->data_len = 0; from->len = 0; -- 2.43.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags() 2026-06-10 14:07 ` [PATCH 1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags() Steffen Klassert @ 2026-06-11 10:10 ` patchwork-bot+netdevbpf 0 siblings, 0 replies; 8+ messages in thread From: patchwork-bot+netdevbpf @ 2026-06-11 10:10 UTC (permalink / raw) To: Steffen Klassert; +Cc: davem, kuba, herbert, netdev Hello: This series was applied to netdev/net.git (main) by Steffen Klassert <steffen.klassert@secunet.com>: On Wed, 10 Jun 2026 16:07:40 +0200 you wrote: > From: Takao Sato <takaosato1997@gmail.com> > > iptfs_consume_frags() transfers paged fragments from one socket buffer > to another but fails to propagate the SKBFL_SHARED_FRAG flag. This is > the same class of bug that was fixed in skb_try_coalesce() for > CVE-2026-46300: when fragments backed by read-only page-cache pages are > merged, the marker indicating their shared nature must be preserved so > that ESP can decide correctly whether in-place encryption is safe. > > [...] Here is the summary with links: - [1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags() https://git.kernel.org/netdev/net/c/e9096a5a170e - [2/6] xfrm: iptfs: fix use-after-free on first_skb in __input_process_payload https://git.kernel.org/netdev/net/c/eb48730bb827 - [3/6] xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx() https://git.kernel.org/netdev/net/c/7f2d76c9c032 - [4/6] xfrm: iptfs: fix ABBA deadlock in iptfs_destroy_state() https://git.kernel.org/netdev/net/c/c8a8a75b7334 - [5/6] xfrm: espintcp: do not reuse an in-progress partial send https://git.kernel.org/netdev/net/c/c381039ade2e - [6/6] esp: fix page frag reference leak on skb_to_sgvec failure https://git.kernel.org/netdev/net/c/26aad08a9289 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/6] xfrm: iptfs: fix use-after-free on first_skb in __input_process_payload 2026-06-10 14:07 [PATCH 0/6] pull request (net): ipsec 2026-06-10 Steffen Klassert 2026-06-10 14:07 ` [PATCH 1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags() Steffen Klassert @ 2026-06-10 14:07 ` Steffen Klassert 2026-06-10 14:07 ` [PATCH 3/6] xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx() Steffen Klassert ` (3 subsequent siblings) 5 siblings, 0 replies; 8+ messages in thread From: Steffen Klassert @ 2026-06-10 14:07 UTC (permalink / raw) To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev From: Zhenghang Xiao <kipreyyy@gmail.com> __input_process_payload() stores first_skb into xtfs->ra_newskb under drop_lock when starting partial reassembly, then unlocks and breaks out of the processing loop. The post-loop check reads xtfs->ra_newskb without the lock to decide whether first_skb is still owned: if (first_skb && first_iplen && !defer && first_skb != xtfs->ra_newskb) Between spin_unlock and this read, a concurrent CPU running iptfs_reassem_cont() (or the drop_timer hrtimer) can complete reassembly, NULL xtfs->ra_newskb, and free the skb. The check then evaluates first_skb != NULL as true, and pskb_trim/ip_summed/consume_skb operate on the freed skb — a use-after-free in skbuff_head_cache. Replace the unlocked read with a local bool that records whether first_skb was handed to the reassembly state in the current call. The flag is set after the existing spin_unlock, before the break, using the pointer equality that is stable at that point (first_skb == skb iff first_skb was stored in ra_newskb). Fixes: 3f3339885fb3 ("xfrm: iptfs: add reusing received skb for the tunnel egress packet") Signed-off-by: Zhenghang Xiao <kipreyyy@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> --- net/xfrm/xfrm_iptfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index 62ba828632f1..aea63a000d1d 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -954,6 +954,7 @@ static bool __input_process_payload(struct xfrm_state *x, u32 data, u32 first_iplen, iphlen, iplen, remaining, tail; u32 capturelen; u64 seq; + bool first_skb_partial = false; xtfs = x->mode_data; net = xs_net(x); @@ -1161,6 +1162,7 @@ static bool __input_process_payload(struct xfrm_state *x, u32 data, spin_unlock(&xtfs->drop_lock); + first_skb_partial = (first_skb == skb); break; } @@ -1172,7 +1174,7 @@ static bool __input_process_payload(struct xfrm_state *x, u32 data, /* this should not happen from the above code */ XFRM_INC_STATS(net, LINUX_MIB_XFRMINIPTFSERROR); - if (first_skb && first_iplen && !defer && first_skb != xtfs->ra_newskb) { + if (first_skb && first_iplen && !defer && !first_skb_partial) { /* first_skb is queued b/c !defer and not partial */ if (pskb_trim(first_skb, first_iplen)) { /* error trimming */ -- 2.43.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx() 2026-06-10 14:07 [PATCH 0/6] pull request (net): ipsec 2026-06-10 Steffen Klassert 2026-06-10 14:07 ` [PATCH 1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags() Steffen Klassert 2026-06-10 14:07 ` [PATCH 2/6] xfrm: iptfs: fix use-after-free on first_skb in __input_process_payload Steffen Klassert @ 2026-06-10 14:07 ` Steffen Klassert 2026-06-10 14:07 ` [PATCH 4/6] xfrm: iptfs: fix ABBA deadlock in iptfs_destroy_state() Steffen Klassert ` (2 subsequent siblings) 5 siblings, 0 replies; 8+ messages in thread From: Steffen Klassert @ 2026-06-10 14:07 UTC (permalink / raw) To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev From: Sanghyun Park <sanghyun.park.cnu@gmail.com> Fix the race by pruning the bin while still holding xfrm_policy_lock, before dropping it. Use __xfrm_policy_inexact_prune_bin() directly since the lock is already held. The wrapper xfrm_policy_inexact_prune_bin() becomes unused and is removed. Race: CPU0 (XFRM_MSG_DELPOLICY) CPU1 (XFRM_MSG_NEWSPDINFO) ========================== ========================== xfrm_policy_bysel_ctx(): spin_lock_bh(xfrm_policy_lock) bin = xfrm_policy_inexact_lookup() __xfrm_policy_unlink(pol) spin_unlock_bh(xfrm_policy_lock) xfrm_policy_kill(ret) // wide window, lock not held xfrm_hash_rebuild(): spin_lock_bh(xfrm_policy_lock) __xfrm_policy_inexact_flush(): kfree_rcu(bin) // bin freed spin_unlock_bh(xfrm_policy_lock) xfrm_policy_inexact_prune_bin(bin) // UAF: bin is freed Fixes: 6be3b0db6db8 ("xfrm: policy: add inexact policy search tree infrastructure") Signed-off-by: Sanghyun Park <sanghyun.park.cnu@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> --- net/xfrm/xfrm_policy.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index dd09d2063da2..959544425692 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1156,15 +1156,6 @@ static void __xfrm_policy_inexact_prune_bin(struct xfrm_pol_inexact_bin *b, bool } } -static void xfrm_policy_inexact_prune_bin(struct xfrm_pol_inexact_bin *b) -{ - struct net *net = read_pnet(&b->k.net); - - spin_lock_bh(&net->xfrm.xfrm_policy_lock); - __xfrm_policy_inexact_prune_bin(b, false); - spin_unlock_bh(&net->xfrm.xfrm_policy_lock); -} - static void __xfrm_policy_inexact_flush(struct net *net) { struct xfrm_pol_inexact_bin *bin, *t; @@ -1707,12 +1698,12 @@ xfrm_policy_bysel_ctx(struct net *net, const struct xfrm_mark *mark, u32 if_id, } ret = pol; } + if (bin && delete) + __xfrm_policy_inexact_prune_bin(bin, false); spin_unlock_bh(&net->xfrm.xfrm_policy_lock); if (ret && delete) xfrm_policy_kill(ret); - if (bin && delete) - xfrm_policy_inexact_prune_bin(bin); return ret; } EXPORT_SYMBOL(xfrm_policy_bysel_ctx); -- 2.43.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] xfrm: iptfs: fix ABBA deadlock in iptfs_destroy_state() 2026-06-10 14:07 [PATCH 0/6] pull request (net): ipsec 2026-06-10 Steffen Klassert ` (2 preceding siblings ...) 2026-06-10 14:07 ` [PATCH 3/6] xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx() Steffen Klassert @ 2026-06-10 14:07 ` Steffen Klassert 2026-06-10 14:07 ` [PATCH 5/6] xfrm: espintcp: do not reuse an in-progress partial send Steffen Klassert 2026-06-10 14:07 ` [PATCH 6/6] esp: fix page frag reference leak on skb_to_sgvec failure Steffen Klassert 5 siblings, 0 replies; 8+ messages in thread From: Steffen Klassert @ 2026-06-10 14:07 UTC (permalink / raw) To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev From: Tristan Madani <tristmd@gmail.com> iptfs_destroy_state() calls hrtimer_cancel() while holding a spinlock that the timer callback also acquires, leading to an ABBA deadlock on SMP systems. For the output timer (iptfs_timer): - iptfs_destroy_state() holds x->lock, calls hrtimer_cancel() - iptfs_delay_timer() callback takes x->lock For the drop timer (drop_timer): - iptfs_destroy_state() holds drop_lock, calls hrtimer_cancel() - iptfs_drop_timer() callback takes drop_lock Both timers use HRTIMER_MODE_REL_SOFT, so their callbacks run in softirq context. When hrtimer_cancel() is called for a soft timer that is currently executing on another CPU, hrtimer_cancel_wait_running() spins on softirq_expiry_lock -- the same lock held by the softirq running the callback. If the callback is blocked waiting for the spinlock held by the caller of hrtimer_cancel(), a circular dependency forms: CPU 0: holds lock_A -> waits for softirq_expiry_lock CPU 1: holds softirq_expiry_lock -> waits for lock_A Fix by calling hrtimer_cancel() before acquiring the respective locks. hrtimer_cancel() is safe to call without holding any lock and will wait for any in-progress callback to complete. For the output timer, the lock is still acquired afterwards to drain the packet queue. For the drop timer, the lock/unlock pair is removed entirely since it only existed to serialize with the timer callback, which hrtimer_cancel() already guarantees. Found by source code audit. Fixes: 4b3faf610cc6 ("xfrm: iptfs: add new iptfs xfrm mode impl") Cc: Christian Hopps <chopps@labn.net> Cc: Steffen Klassert <steffen.klassert@secunet.com> Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani <tristan@talencesecurity.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> --- net/xfrm/xfrm_iptfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index aea63a000d1d..ad810d1f97c0 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -2730,8 +2730,9 @@ static void iptfs_destroy_state(struct xfrm_state *x) if (!xtfs) return; - spin_lock_bh(&xtfs->x->lock); hrtimer_cancel(&xtfs->iptfs_timer); + + spin_lock_bh(&xtfs->x->lock); __skb_queue_head_init(&list); skb_queue_splice_init(&xtfs->queue, &list); spin_unlock_bh(&xtfs->x->lock); @@ -2739,9 +2740,7 @@ static void iptfs_destroy_state(struct xfrm_state *x) while ((skb = __skb_dequeue(&list))) kfree_skb(skb); - spin_lock_bh(&xtfs->drop_lock); hrtimer_cancel(&xtfs->drop_timer); - spin_unlock_bh(&xtfs->drop_lock); if (xtfs->ra_newskb) kfree_skb(xtfs->ra_newskb); -- 2.43.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] xfrm: espintcp: do not reuse an in-progress partial send 2026-06-10 14:07 [PATCH 0/6] pull request (net): ipsec 2026-06-10 Steffen Klassert ` (3 preceding siblings ...) 2026-06-10 14:07 ` [PATCH 4/6] xfrm: iptfs: fix ABBA deadlock in iptfs_destroy_state() Steffen Klassert @ 2026-06-10 14:07 ` Steffen Klassert 2026-06-10 14:07 ` [PATCH 6/6] esp: fix page frag reference leak on skb_to_sgvec failure Steffen Klassert 5 siblings, 0 replies; 8+ messages in thread From: Steffen Klassert @ 2026-06-10 14:07 UTC (permalink / raw) To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev From: Wyatt Feng <bronzed_45_vested@icloud.com> espintcp keeps a single in-flight transmit in ctx->partial. Before building a new sk_msg, espintcp_sendmsg() first tries to flush that state through espintcp_push_msgs(). For blocking callers, espintcp_push_msgs() may return success even when the previous partial send is still pending. espintcp_sendmsg() would then reinitialize emsg->skmsg and reuse ctx->partial while the old transfer still owns that state. Do not rebuild the send message when ctx->partial is still in progress. If espintcp_push_msgs() returns with emsg->len still set, fail the new send instead of overwriting the live partial state. This is a memory-safety fix: reusing the live partial-send state can leave a stale offset attached to a new sk_msg and lead to an out-of- bounds read in the send path. tcp_sendmsg_locked() already handles waiting for send buffer memory, so the fix here is just to preserve espintcp's one-message-at-a-time transmit state. Fixes: e27cca96cd68 ("xfrm: add espintcp (RFC 8229)") Cc: stable@kernel.org Reported-by: Yuan Tan <yuantan098@gmail.com> Reported-by: Yifan Wu <yifanwucs@gmail.com> Reported-by: Juefei Pu <tomapufckgml@gmail.com> Reported-by: Zhengchuan Liang <zcliangcn@gmail.com> Reported-by: Xin Liu <bird@lzu.edu.cn> Assisted-by: Codex:GPT-5.4 Signed-off-by: Wyatt Feng <bronzed_45_vested@icloud.com> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> --- net/xfrm/espintcp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c index a2756186e13a..d9035546375e 100644 --- a/net/xfrm/espintcp.c +++ b/net/xfrm/espintcp.c @@ -346,6 +346,10 @@ static int espintcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) err = -ENOBUFS; goto unlock; } + if (emsg->len) { + err = -ENOBUFS; + goto unlock; + } sk_msg_init(&emsg->skmsg); while (1) { -- 2.43.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] esp: fix page frag reference leak on skb_to_sgvec failure 2026-06-10 14:07 [PATCH 0/6] pull request (net): ipsec 2026-06-10 Steffen Klassert ` (4 preceding siblings ...) 2026-06-10 14:07 ` [PATCH 5/6] xfrm: espintcp: do not reuse an in-progress partial send Steffen Klassert @ 2026-06-10 14:07 ` Steffen Klassert 5 siblings, 0 replies; 8+ messages in thread From: Steffen Klassert @ 2026-06-10 14:07 UTC (permalink / raw) To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev From: Alessandro Schino <7991aleschino@gmail.com> In esp_output_tail(), when esp->inplace is false, the old skb page frags are replaced with a new page from the xfrm page_frag cache The source scatterlist (sg) is built from the old frags before the replacement, and esp_ssg_unref() is responsible for releasing the old page references after the crypto operation completes However, if the second skb_to_sgvec() call (which builds the destination scatterlist from the new page) fails, the code jumps to error_free which only calls kfree(tmp). The old page frag references captured in the source scatterlist are never released: 1 sg[] is built from old frags via skb_to_sgvec() (no extra get_page) 2 nr_frags is set to 1 and frag[0] is replaced with the new page 3 Second skb_to_sgvec() fails -> goto error_free Fix this by adding a bool parameter to esp_ssg_unref() that, when true, unconditionally unrefs the source scatterlist frags. Since req->src is not yet initialized by aead_request_set_crypt() at the point of the error, the source scatterlist is obtained directly via esp_req_sg() Existing callers pass false to preserve the original behavior The same issue exists in both esp4 and esp6 as the code is identical Fixes: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible") Fixes: 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible") Signed-off-by: Alessandro Schino <7991aleschino@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> --- net/ipv4/esp4.c | 17 +++++++++++------ net/ipv6/esp6.c | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 513c8215c947..dfc81ee969ae 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -96,7 +96,7 @@ static inline struct scatterlist *esp_req_sg(struct crypto_aead *aead, __alignof__(struct scatterlist)); } -static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb) +static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb, bool already_unref) { struct crypto_aead *aead = x->data; int extralen = 0; @@ -113,10 +113,13 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb) /* Unref skb_frag_pages in the src scatterlist if necessary. * Skip the first sg which comes from skb->data. */ - if (req->src != req->dst) - for (sg = sg_next(req->src); sg; sg = sg_next(sg)) + if (already_unref || req->src != req->dst) { + struct scatterlist *src = already_unref ? esp_req_sg(aead, req) : req->src; + + for (sg = sg_next(src); sg; sg = sg_next(sg)) skb_page_unref(page_to_netmem(sg_page(sg)), skb->pp_recycle); + } } #ifdef CONFIG_INET_ESPINTCP @@ -220,7 +223,7 @@ static void esp_output_done(void *data, int err) } tmp = ESP_SKB_CB(skb)->tmp; - esp_ssg_unref(x, tmp, skb); + esp_ssg_unref(x, tmp, skb, false); kfree(tmp); if (xo && (xo->flags & XFRM_DEV_RESUME)) { @@ -569,8 +572,10 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * err = skb_to_sgvec(skb, dsg, (unsigned char *)esph - skb->data, assoclen + ivlen + esp->clen + alen); - if (unlikely(err < 0)) + if (unlikely(err < 0)) { + esp_ssg_unref(x, tmp, skb, true); goto error_free; + } } if ((x->props.flags & XFRM_STATE_ESN)) @@ -602,7 +607,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * } if (sg != dsg) - esp_ssg_unref(x, tmp, skb); + esp_ssg_unref(x, tmp, skb, false); if (!err && x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP) err = esp_output_tail_tcp(x, skb); diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 57481e423e59..296b57926abb 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -113,7 +113,7 @@ static inline struct scatterlist *esp_req_sg(struct crypto_aead *aead, __alignof__(struct scatterlist)); } -static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb) +static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb, bool already_unref) { struct crypto_aead *aead = x->data; int extralen = 0; @@ -130,10 +130,13 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb) /* Unref skb_frag_pages in the src scatterlist if necessary. * Skip the first sg which comes from skb->data. */ - if (req->src != req->dst) - for (sg = sg_next(req->src); sg; sg = sg_next(sg)) + if (already_unref || req->src != req->dst) { + struct scatterlist *src = already_unref ? esp_req_sg(aead, req) : req->src; + + for (sg = sg_next(src); sg; sg = sg_next(sg)) skb_page_unref(page_to_netmem(sg_page(sg)), skb->pp_recycle); + } } #ifdef CONFIG_INET6_ESPINTCP @@ -254,7 +257,7 @@ static void esp_output_done(void *data, int err) } tmp = ESP_SKB_CB(skb)->tmp; - esp_ssg_unref(x, tmp, skb); + esp_ssg_unref(x, tmp, skb, false); kfree(tmp); esp_output_encap_csum(skb); @@ -600,8 +603,10 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info err = skb_to_sgvec(skb, dsg, (unsigned char *)esph - skb->data, assoclen + ivlen + esp->clen + alen); - if (unlikely(err < 0)) + if (unlikely(err < 0)) { + esp_ssg_unref(x, tmp, skb, true); goto error_free; + } } if ((x->props.flags & XFRM_STATE_ESN)) @@ -634,7 +639,7 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info } if (sg != dsg) - esp_ssg_unref(x, tmp, skb); + esp_ssg_unref(x, tmp, skb, false); if (!err && x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP) err = esp_output_tail_tcp(x, skb); -- 2.43.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-06-11 10:10 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-10 14:07 [PATCH 0/6] pull request (net): ipsec 2026-06-10 Steffen Klassert 2026-06-10 14:07 ` [PATCH 1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags() Steffen Klassert 2026-06-11 10:10 ` patchwork-bot+netdevbpf 2026-06-10 14:07 ` [PATCH 2/6] xfrm: iptfs: fix use-after-free on first_skb in __input_process_payload Steffen Klassert 2026-06-10 14:07 ` [PATCH 3/6] xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx() Steffen Klassert 2026-06-10 14:07 ` [PATCH 4/6] xfrm: iptfs: fix ABBA deadlock in iptfs_destroy_state() Steffen Klassert 2026-06-10 14:07 ` [PATCH 5/6] xfrm: espintcp: do not reuse an in-progress partial send Steffen Klassert 2026-06-10 14:07 ` [PATCH 6/6] esp: fix page frag reference leak on skb_to_sgvec failure Steffen Klassert
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox