Netdev List
 help / color / mirror / Atom feed
From: Juan Agustin Niccolini <juanagusnicco@gmail.com>
To: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	Christian Hopps <chopps@labn.net>,
	Antony Antony <antony.antony@secunet.com>,
	Sabrina Dubroca <sd@queasysnail.net>,
	Shaomin Chen <eeesssooo020@gmail.com>,
	Roshan Kumar <roshaen09@gmail.com>
Subject: [PATCH ipsec 2/4] xfrm: iptfs: look up the device of held packets again to fix a UAF
Date: Mon, 30 Nov 2026 22:21:58 -0500	[thread overview]
Message-ID: <20261201032200.37030-3-juanagusnicco@gmail.com> (raw)
In-Reply-To: <20261201032200.37030-1-juanagusnicco@gmail.com>

A packet held in the IP-TFS reorder window, or as the in-progress
reassembly packet, keeps skb->dev without a reference on the device.
If the device is deleted in the meantime, xfrm_input() reads the freed
net_device when the packet is released, a use-after-free:

  BUG: KASAN: slab-use-after-free in xfrm_input+0xbb/0x2620
  Read of size 8 at addr ff1100000efec100 by task swapper/0/0

The freed device's core_stats pointer is then used for a per-CPU
increment. Once the memory is reused for data the user controls, that
is an addition of a chosen value at a chosen kernel address, which is
enough to escalate privileges to root.

An unprivileged user can trigger this from a user and network
namespace, by sending through an IP-TFS SA with a sequence number
skipped and deleting the receiving device before the drop timer fires.

Fix this as ip_expire() does for IPv4 reassembly: record the ifindex
when a packet is saved in the reorder window, clear skb->dev, and look
the device up again when the packet is released, dropping it if the
device is gone. Since the previous patch, a held packet never outlives
its namespace, so the lookup runs on a live one. A completed inner
packet takes the device of the outer packet that completed it, as in
ip_frag_reasm().

I found this bug during an LLM-based audit. A syzbot report
and a previous proposed patch for this bug exist (see below).

Fixes: 6be02e3e4f37 ("xfrm: iptfs: handle reordering of received packets")
Fixes: 075694765446 ("xfrm: iptfs: handle received fragmented inner packets")
Cc: stable@vger.kernel.org
Reported-by: Roshan Kumar <roshaen09@gmail.com>
Link: https://lore.kernel.org/netdev/20260921083602.814584-1-roshaen09@gmail.com/
Reported-by: syzbot+0008ea314a1096dee2b6@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=0008ea314a1096dee2b6
Signed-off-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
---
Reproducer: https://github.com/AgusNicco/iptfs-uafs/blob/main/iptfs_reorder_uaf.c

I have an exploit that uses this bug to escalate privileges to root from
an unprivileged user. It is available to the maintainers on request.

 net/xfrm/xfrm_iptfs.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index 0dde380eb16c..da5729306a61 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -939,6 +939,7 @@ static u32 iptfs_reassem_cont(struct xfrm_iptfs_data *xtfs, u64 seq,
 	} else {
 		/* We are done with packet reassembly! */
 		iptfs_reassem_done(xtfs);
+		newskb->dev = skb->dev;
 		iptfs_complete_inner_skb(xtfs->x, newskb);
 		list_add_tail(&newskb->list, list);
 	}
@@ -1248,6 +1249,15 @@ static void iptfs_input_ordered(struct xfrm_state *x, struct sk_buff *skb)
 	xtfs = x->mode_data;
 	net = xs_net(x);
 
+	if (!skb->dev) {
+		skb->dev = dev_get_by_index_rcu(net, skb->skb_iif);
+		if (!skb->dev) {
+			XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
+			kfree_skb(skb);
+			return;
+		}
+	}
+
 	seq = __esp_seq(skb);
 
 	/* Large enough to hold both types of header */
@@ -1446,6 +1456,13 @@ static void iptfs_set_window_drop_times(struct xfrm_iptfs_data *xtfs, int index)
 			      IPTFS_HRTIMER_MODE);
 }
 
+static void __reorder_save(struct skb_wseq *s, struct sk_buff *skb)
+{
+	skb->skb_iif = skb->dev->ifindex;
+	skb->dev = NULL;
+	s->skb = skb;
+}
+
 static void __reorder_future_fits(struct xfrm_iptfs_data *xtfs,
 				  struct sk_buff *inskb,
 				  struct list_head *freelist)
@@ -1491,7 +1508,7 @@ static void __reorder_future_fits(struct xfrm_iptfs_data *xtfs,
 		return;
 	}
 
-	xtfs->w_saved[index].skb = inskb;
+	__reorder_save(&xtfs->w_saved[index], inskb);
 	xtfs->w_savedlen = max(savedlen, index + 1);
 	iptfs_set_window_drop_times(xtfs, index);
 }
@@ -1626,7 +1643,7 @@ static void __reorder_future_shifts(struct xfrm_iptfs_data *xtfs,
 
 	/* We've shifted. plug the packet in at the end. */
 	xtfs->w_savedlen = nslots - 1;
-	xtfs->w_saved[xtfs->w_savedlen - 1].skb = inskb;
+	__reorder_save(&xtfs->w_saved[xtfs->w_savedlen - 1], inskb);
 	iptfs_set_window_drop_times(xtfs, xtfs->w_savedlen - 1);
 
 	/* if we don't have a slot0 then we must wait for it */
@@ -1720,10 +1737,12 @@ static enum hrtimer_restart iptfs_drop_timer(struct hrtimer *me)
 		kfree_skb_reason(skb, SKB_DROP_REASON_FRAG_REASM_TIMEOUT);
 
 	if (count) {
+		rcu_read_lock();
 		list_for_each_entry_safe(skb, next, &list, list) {
 			skb_list_del_init(skb);
 			iptfs_input_ordered(x, skb);
 		}
+		rcu_read_unlock();
 	}
 
 	return HRTIMER_NORESTART;
-- 
2.53.0


  parent reply	other threads:[~2026-12-01  3:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  3:21 [PATCH ipsec 0/4] xfrm: iptfs: fix use-after-free by held and queued packets Juan Agustin Niccolini
2026-12-01  3:21 ` [PATCH ipsec 1/4] xfrm: iptfs: free held packets on SA delete to fix a netns UAF Juan Agustin Niccolini
2026-12-01  3:21 ` Juan Agustin Niccolini [this message]
2026-12-01  3:21 ` [PATCH ipsec 3/4] xfrm: iptfs: free queued " Juan Agustin Niccolini
2026-12-01  3:22 ` [PATCH ipsec 4/4] xfrm: iptfs: don't keep the input device of queued packets to fix a UAF Juan Agustin Niccolini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201032200.37030-3-juanagusnicco@gmail.com \
    --to=juanagusnicco@gmail.com \
    --cc=antony.antony@secunet.com \
    --cc=chopps@labn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=eeesssooo020@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=ipsec@lists.linux.dev \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=roshaen09@gmail.com \
    --cc=sd@queasysnail.net \
    --cc=steffen.klassert@secunet.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox