pull request (net): ipsec 2026-06-10
Subsystems (3)
Steffen Klassert
maintainercover pull request (net): ipsec 2026-06-10
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(-)
Steffen Klassert
maintainerPATCH 1/6 xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags()
From: Takao Sato <[email protected]>
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().
--- net/xfrm/xfrm_iptfs.c | 2 ++ 1 file changed, 2 insertions(+)
net/xfrm/xfrm_iptfs.c +2 -0
@@ -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 ;
Signature · 1 line
2.43.0
Re: [PATCH 1/6] xfrm: iptfs: preserve shared-frag marker in iptfs_consume_frags()
This series was applied to netdev/net.git (main) by Steffen Klassert <[email protected]>:
Hello:
This series was applied to netdev/net.git (main) by Steffen Klassert <[email protected]>:
Quoted 10 lines · On Wed, 10 Jun 2026 16:07:40 +0200 you wrote:
From: Takao Sato <[email protected]>
iptfs_consume_frags()transfers paged fragments from one socket buffer to another but fails to propagate theSKBFL_SHARED_FRAGflag. This is the same class of bug that was fixed inskb_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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Steffen Klassert
maintainerPATCH 2/6 xfrm: iptfs: fix use-after-free on first_skb in __input_process_payload
In reply to Steffen KlassertFrom: Zhenghang Xiao <[email protected]>
__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).
--- net/xfrm/xfrm_iptfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/xfrm/xfrm_iptfs.c +3 -1
@@ -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 */
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 3/6 xfrm: policy: fix use-after-free on inexact bin in xfrm_policy_bysel_ctx()
In reply to Steffen KlassertFrom: Sanghyun Park <[email protected]>
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--- net/xfrm/xfrm_policy.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
net/xfrm/xfrm_policy.c +2 -11
@@ -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);
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 4/6 xfrm: iptfs: fix ABBA deadlock in iptfs_destroy_state()
In reply to Steffen KlassertFrom: Tristan Madani <[email protected]>
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.
--- net/xfrm/xfrm_iptfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/xfrm/xfrm_iptfs.c +2 -3
@@ -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);
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 5/6 xfrm: espintcp: do not reuse an in-progress partial send
In reply to Steffen KlassertFrom: Wyatt Feng <[email protected]>
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.
--- net/xfrm/espintcp.c | 4 ++++ 1 file changed, 4 insertions(+)
net/xfrm/espintcp.c +4 -0
@@ -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 ) {
Signature · 1 line
2.43.0
Steffen Klassert
maintainerPATCH 6/6 esp: fix page frag reference leak on skb_to_sgvec failure
In reply to Steffen KlassertFrom: Alessandro Schino <[email protected]>
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
--- net/ipv4/esp4.c | 17 +++++++++++------ net/ipv6/esp6.c | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-)
net/ipv4/esp4.c +11 -6
@@ -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);
net/ipv6/esp6.c +11 -6
@@ -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);
Signature · 1 line
2.43.0