Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796095334; b=DWFhOamnGrIUqiJC7ym4jXtnfzRfIGEJIAWhalCY6tMQnIrMjyCXVLturC+tiCcnJDS1 ayqw5o6sble4iV1HSqR18VafOtQwfqyoGIkSdtkT9BCNqD73ZL4C49dCZJZexMkfn87VJ M4SgEyxd3wS72qSXitV7ByZ34GRYpwJ/tt1jHESCUJCcEcrOZyRby+bxm7OqdIg1tVXcH RLMq5CcjErN0kInEJe2tXkdHJoS5Dnz8huGfpSwwqDlp9BjUL3wrDsgI0hR1Y4sB5FjCa jvj+aDdQ6WmQZAB9H4cN69T5xDndpvTUXSPHL8DE+gVqFi/9QIpBoPf0yXqixDD7HIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796095334; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=8QMxQ2EaiARSv9t79RMwUb0uHPjseoQ3LpegArnAN3M=; b=eM3G88PfzHWWiBTevgtWbA/8TY1t+27z2bTgmizt/XItCh/SRRyyqbL2F0enp/rN7llD jkoFT3IWgrPufqXAh9k4vQB91jXxIht1AmXdZsUWpn0Ez+voVn2P9Vdx05vMHb0YTlIrQ ppNK7UPHpjN6BQ7TmRLLH6194M2uNrb19hRuvUQ4oWKW3ccuzKhxrwvYowv1Gdr240iZ7 D+vxBKSi6TJCt71ixCI1gKk1zGvXJTU1fNaFOWw3jiK+ZM+e0n2mA4lwuya3QIaAzNmuT fjG98ESePLSQhvub2i0ihY6CAo2hLByXV4KN0Y6f8xZyRrxkb9lwazeTm6LnL2JsmYA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=duixS93Z; arc=none smtp.remote-ip=74.125.224.45 Received: from mail-yx1-f45.google.com (mail-yx1-f45.google.com [74.125.224.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9594606A325 for ; Tue, 1 Dec 2026 03:22:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B9594606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=duixS93Z Received: by mail-yx1-f45.google.com with SMTP id 956f58d0204a3-67da3d03263so11434197d50.1 for ; Mon, 30 Nov 2026 19:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796095333; x=1796700133; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8QMxQ2EaiARSv9t79RMwUb0uHPjseoQ3LpegArnAN3M=; b=duixS93Zkgs97yzJUwx9GYXi5VBfZdrNPAKbQuMvywCqLvJJliBihVNxt3extkwQPT hnut5O0ziJHO4E2fngs6ZwsyjOg5WGYodmdiMmGAOssCJUb/2vhqN+xIG1iDjMaZNVJX H9WDTW9xUP1ocitByL3jyAk+TkaocZw8I/P7BHMrPy8O9zIXuaxFXUACUZA+HSuv1E2Q uR+sZLb9Zs0WIUy/iqZHO2O1awTd9f3WoDDTD7d7TpS1qgCckjq4VqQxwBGAhIJvwqpD +C4q7EhysOvyR70wEGK0VT2Gpox2gthEZuVhAaxvMB99ze4xj1ybLt/7L8DrbJaT7V7x W3+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796095333; x=1796700133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8QMxQ2EaiARSv9t79RMwUb0uHPjseoQ3LpegArnAN3M=; b=uYSBH4BWohXktXskYkdWpVsUdw5owOIpQzHa02tgVLNDqDq0HI1OdJ9nltFIvRDxff ErU285FM6rciQfHIdQhLAxviYTd+lx56cBlTW2Wz6v4d1iRtgDK1s7dvIUlRup/a1U3t RD6rYWqOW5zOEbVWRUyA+s2AHIjwU7auXpCGnFemyR8T4ZhgRpUogMePyEizugynmS/e /WBzfDEs0KvsexgCSHymt2yhJE0QdHV0leLAdZAmWUlK44pii1QdBnkaL4Md22dcWfi+ ZABcSW1GVgSxxmPUtKnnnp5Rr5DgbyFajMv9DgSX5E/VtNpVla1P+OeP5i95ca3DQ8HD AAeQ== X-Forwarded-Encrypted: i=1; AL+hErFTp19Wmx+x5qRZgYSQLAPBiMOCjdrNer9z0EdxA3JlprRX3PtY/jkVZkjSe2JFIxnh9pWSew==@lists.linux.dev X-Gm-Message-State: APuU4Z90yj6Xpmp4E1lqGHpahCJfKFFP7r7kn94J200gRegN4wpy2pZ+ KzGxwmiRGwN/DE7DqRUfeBrZ7bTqcv6xOBjEDCStPfRCs8xBb0j1Zehb X-Gm-Gg: AZFdTZdauD5+b6LqpnmOiW+viZiwaT+fLwMl63l8IkU4KhYAX/LP5WtRuohHrgF0SWA Ngi0DnzFiuMMkHBQdBOhMaTtzfnvFXjB8tko7pHmqpZDhltELmMzlvfqmSTat0SLqwBbhrA8Xbv XB9cCRoqMu0IMCySBkZWpQtMRHdqsaZTCeSMjyJFEUbWRprQIf9o0xcblXDh6KUhQfk6beLdFjg RvAClmwSEto5nx45eZ1mIHU7xqk+m/Tv9aYVEvfZTzjt+ZMrorJ/XfDz38uilJBCty0ubyUe63V m3eVsF/7gnj6OTh87B5vSznlV95sO8sm6msgk/GOd2Rl/zJ/6kV2sJJGZHRxi66yqxKtZvIwj4h i3PE5/3kh+LVtOWrdz1deMVVy+vFh00+ifJzvVqfVSXq3Ljp/92KlsO6WDygW2EOygqGo+sW7gU PHKN/TfcPMvWLnnB2ls5150/pPn7Ielv0XW5CiIQ4o1JYprqlUd+gQ5NrAEdpKXGUgf1aqt8ePK wWzxIdv/nYB1qGcJu0XByFuJrEi3pRrU5jT7N1+n20yhnbQ3T71Vmy/kvxcjPTwJOBnlASIchns ONCkCfD9R1xY+XnmaRJ9sNc8zOnf16OxLBX/IF7rJxvDVOTws5cy X-Received: by 2002:a05:690e:1907:b0:67d:b7ed:26d2 with SMTP id 956f58d0204a3-67df42b5a51mr12155924d50.21.1796095332718; Mon, 30 Nov 2026 19:22:12 -0800 (PST) Received: from VPN-156-19.vpn.usf.edu ([2607:fe50:0:f802::4046]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67df30e4407sm16484916d50.0.2026.11.30.19.22.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Nov 2026 19:22:11 -0800 (PST) From: Juan Agustin Niccolini To: Steffen Klassert , Herbert Xu , "David S . Miller" Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Christian Hopps , Antony Antony , Sabrina Dubroca , Shaomin Chen , Roshan Kumar 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 Message-ID: <20261201032200.37030-3-juanagusnicco@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201032200.37030-1-juanagusnicco@gmail.com> References: <20261201032200.37030-1-juanagusnicco@gmail.com> X-Mailing-List: ipsec@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- 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