From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796095334; b=FhkVoWT8hunWyQl9Cakj3XjNl0TkvwghXJfe+gwielMs167DnuahkB9wbKNTuWW+IstI +bMkUSmN1xvjI8lDoWd+kuGW9fXjtFHJGmf+rpsuiKoflGy+SwhxkiNFfGO+vRo+Xw6vm Eve/AYcu4Z1gO0PU3TaRtln2xPw0Jal5wqsEirg69suxW5Ur3j3FjJaet1HGvHIp39YTO MAsy2WuJugg+55z3AvSbRC/2xPXt0n1fEA7mzL+ncOj4QNyMoo1mMkECiiHhRovblexgP 1r8Z++bavPNWNFTRbx7taqmNKgNRiz52lsAFsZle9LwrzdNAdZZ2PcoBNR0A7l95PtA== 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-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=hwsWFa32l55Vbqsg33iqK5DtHeOO+Cw4mAe/pWkDfqRIkxFWaC6Hqw+nf5mqdG3XI6t/ A6FzSiHhf5P30gCBLgmB6zysf7wMjxQcuMzTas6TYyTRNBEKt0MLikDCQvmvSNGExWHoi wcjOFKy0k6LejED0Q3W66tfUjHb6Y98dUfBTh8d9BGa2L/5XoJlsgl0mt4lDIe1/DHXt0 wfM+p6jMgFwq4WPM8h3ZO/HeHW6MdkiLY8NfuEZseDAtF48hIZO7znpbHKV3ojsBz4Q1v n/cRq8rvTZzx4ImILgSxair9pIGpzw0HcNev73gK6ws6wJimAeLjJPXin3ZdQp0u1pQ== 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=SG7bPAJl; arc=none smtp.remote-ip=74.125.224.44 Received: from mail-yx1-f44.google.com (mail-yx1-f44.google.com [74.125.224.44]) (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 CDA60606A32D for ; Tue, 1 Dec 2026 03:22:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CDA60606A32D 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=SG7bPAJl Received: by mail-yx1-f44.google.com with SMTP id 956f58d0204a3-67da3d03263so11434196d50.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=vger.kernel.org; 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=SG7bPAJl8bEZfdYsH3SQ+ysqjPSwCIhX82kdGKHcq5p7HUTcA43o49EWkluSgXwH+6 X//4e4YxGLxUtyGK3T3SoWsajiB5JQrhVlL9GAt3vosSSG5aXVNzj7S5xzgszCCQKRSt Yj44YvX6I8uPDLSGh/51XvX6sXWoGIQmtM9rbR0tp936EZG8Mk2fuEik9y6X5FS/2puh zlH2+wR8Q/ybiMJMmdgPZvdzeg34pwBXw1K2wpe6skVfXFy6PUkHDa54zIJVz3KOoeeB RqYcTrtkPCin30/XUyL9jlWTmKzFaGYu9CIac/I9ZReAzygaBnvE8XRIGhdiXho8+oBN EJjg== 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=FZmfr9S6K0XmveNbVSTAmXh7X+2j3afCt2CgjWk79JUamVMZGZmZAovKCnqeDLe1YK VPv0C0bJHjkQ+YEjs0TiDvi6jXhw9D8uHUNZyZp7WIXhMurK6L2vnWh0xRvkiz7Fw8X6 PFOB+IWppDhwXkjSf5oNTbRjSj+BcfCRSNeK9tKajp8GNVJwizJqBK2n+tUdFidv2YIY xDFH/Y9hgb26GBS7Ore1v0ptcHYN/UrUgkbpR+NRT8I4VU4EnlrQaOPrSB1GzMX5/221 iCuNQ/cKQXUime7DXZP/oUcuWdXf3KOcYNOc4PjFOpdYE5sybfzycT1nhrHy+/tjg2Vt VWGQ== X-Gm-Message-State: APuU4Z8zZ9VdI0n5+Rc/4paGBJwj5GZTAWVT6gd93YvqbIxrKtUCJFlv xyLWNbLNLptFuDoSY+/ocG6Sm+FnkaYlMpDyoDg3gZdnrxG5FEdUIMkq X-Gm-Gg: AZFdTZfckyf641C+avOWkk6cnuRB8CBlNGXGsE9TkwpDndHApzpD0i4CXSH89WBiksa EH70Q60LCM3RhBenqF3R2fcEuT/3MFOfhtvwsdYexpqUdhcPMwuy61gtknu9llXYrMuW+ZFFGvf VSV7Xmjiat4FWDiZoVCILN4mxBHKibUyjY/+4paVUpxZ3SrHw7LWLuUWe+bnmwE15tRuD4C0WH5 MS+8m6wxYul42Xw2TTChJXk4Cn2P3cqdS7w6ygXHU+3qI61xB+/tj+kswNCLaI0a62/UfUAuLUu e39gOv3g5kwlzKJXf3XbMqF8jyoL+AcFzEnANT/2Wwp891rRhl5+pUajSpuXXig+C9yO93QzdR/ OXDvF9vYASTR2Tx7rNqz4QwicbHZ54iNIypZmcaiucSCrojGyIu8K+sCY2iw6rc0el867fNJBo9 XUR32EWukDTza4Oi4d0EjA6t2tr3PQuxCUa7YSLPWOrOwu+wETdcdg2HRIrQ0rWmh5bb2yFkOEE XvhOHmXOJ2KDMnMXJbkYNUVnnYAZ+6/kuT7ro4OoEWZiTZ17G6w5BkoowE4hteNAJzPAEKHJ+u5 R1Sp+/9nntQBOKA0PrhpQnYHvTyvF7bpg2tCRcLM11nWb5XCWDe8 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: netdev@vger.kernel.org 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