Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796095337; b=BEnYLsNP+Uul+7lNoqVsBSNbRc/AJ91NeCx02/PqujgLI7oRoviYW0CpA2PZq3YcE+Yd obbbs3OBKNGUveUPxgTx25XLRcNsQZZtWM8OH3cedHZg+F7zQSgE5vqFDC4PhQYiZPqg1 lh/ftoJkBOZ/ZfXnEFRCRSuHgah1XCtF0gy2ecvBOr2jSLlgjQdQ/oCVNMSXYmF5gHgsF E/oewLxkSfqk+fISyHHCUJuX1X70zGSFIUSRRXlM/Kla+yA3mtLBog2uZ/J1r7lJEWLKQ FbQX2Oj8SdArdFL6LlzQFwh4K9QCH9TDUUpOWfS1K+qG1u9Yk+0bzmKgZXyQ4CpvVuA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796095337; 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=7pnP2ln4JQlXuLwaFCbEmunrRfwNdp2ysnAZSg3o/ig=; b=urmtjSsHQYE5PItQQaoFTXJxU5+czsl5Mi/ir0gFyxQ8lTVrfpc4+9ktHkW9HDC67Blh oDEJAHuNR2XPCgCBacud2obrjMP0Zu3C4h0aJSFBwnR2pTc0Y5TjjhVKp4xDVjkBjOfLt DKT1XIzxlv57RuSeTnDJoUX4+2AU31uFpC+ZTGYEfJp94wR5fLm3YZ66ZhA/s2Kpyekf1 mfmIcCQov600LqBqWhuL/csqToSvWV90UK9B42l4Y7RSiuQua/rY8D1GjAzm+TR40JTxA cYP9gxv26byU6wITx4j5NCCTt9gd77+5zNdpexEetXAl7d3/0tLWW/EA1I8E2gIT6GA== 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=j54zeEJ5; arc=none smtp.remote-ip=209.85.128.177 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 CB247606A331 for ; Tue, 1 Dec 2026 03:22:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CB247606A331 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=j54zeEJ5 Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-8b4d543b6b6so67345427b3.3 for ; Mon, 30 Nov 2026 19:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796095336; x=1796700136; 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=7pnP2ln4JQlXuLwaFCbEmunrRfwNdp2ysnAZSg3o/ig=; b=j54zeEJ5LnlpLA6dy4X3cXWtShX2yMLfCvnQMyqD/pJ/S4jQPgiqZQHpJdTt2CuGdO SAelFsnk+piPuiybEAV5InwWu8eE5wOw1VOa0gl5736jofyYhIa23b2AHVQrMQNs7xaL JgNU8wkvqcwQfnA0LRQeV0eZf/aQw7FmW6fxzJzkSCf1btUfJ2Ws9MV7n6PyOjigrRdE Oy0aJvpkibiMFGCA7D1a0i6hqZDvH67KM9PJnTL1V+va/vhJnE0/blNzDasU/MZu3R/1 IlABmSqCiWB68WrxiKu6WiTVaBudYoqnQmstVdaynmTJyxSTy9/9IHmMH1X9WdLnxOX1 nuSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796095336; x=1796700136; 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=7pnP2ln4JQlXuLwaFCbEmunrRfwNdp2ysnAZSg3o/ig=; b=t3/sXEgDE8L66ean4WYe3kxyDc/y06PUV5oh6w9yuoIq83tOhhaRt6Mw3DCkKcLgtn tBnM4MmCmB273LMoRQ8UYEbH47EDxsQvmPZPyrFmrvUSf5HDpvct9cABDnX5w0Af6VOW C23W1Hza5yHMCsFJDTZ045ug7ukzQVt88SVy/xmYSogH7Hrs6j6zrakjQlpo/Y+YHhtt tZO3TMX5ci5reSizwZoD8IJoYyXTgYD0Snty2UOOr4hGSN6yie3hoOQc5VYEU9OfW65+ TOvfZTUEpsANFUePxrMbyrPB34emw9CU4B1gMX09BtBcfiEtAlMaO9Y5cgIPizB7nMAR A60w== X-Forwarded-Encrypted: i=1; AL+hErElf616nKv7dvHd3rYQVzdrwDrtXawrlzImx4FdeYPHsG4iL9Kx5TXzdCzYUgMjJscKpX2SCw==@lists.linux.dev X-Gm-Message-State: APuU4Z8+jbAB1HrSqcoT2f/HzpY1ZALGYoDw+zvezzXDke+2reuHLcNV aGusvduWo63/cUfLhuMufNHUl868ev9Zk1WMut7pzoMYD7ugVoQUokuc X-Gm-Gg: AZFdTZcftjXDXgL+FuHV+9IgDoXbUsJb+ipDmE2AbQ2pS5VVMknYpNTh50BqMQNIkru D9wa7sm01EahQQ+5+vTVrCbF49m7ocExtAjM5KpQ+pzqTB8lQhFcgDifMOTA8LNtyV1Bf7PNqRZ gPbPNSttxE/Rfmi3JtjVDl39fVUQR/G3ds5kaSfpi0UVav86DOTyYp8FxqCKOmwres7mJUNDCWR MQjWkLfVG+ywLOQXjkStdS690okMPWRwckVHJUU3ZnNIDC96ARVvEIXfWfnm5UjAYEL2E4rLpmk 6CyQAqSACr8tTW8T/v4wl1iDc+Clyj+PaqCxCGRF+2e+ZuLWJDdHTLCZVTj5YChGaenr1SmrGaM ptRm2ZDPrpJkOhkmqEoaMASOKCemDoL79mdn6UNC498qD/5AHvJmgv7SgG5UJlRVP7RJEcFiRVw VdDlwRtwF4Ks10DOgmYfwaJkxfV9jz93zkUuN/Nh2STMl0jfriQ3dZ4ou35cXq7ChS9pywicsNh /cCFedoi7+8qLUXE2m12uSuE+Bhe/cD2FyskgBtb7/oeoaIC/HqPw+Vv+yf7mBCEFOcgpmjluRJ pqSD7HA6Su+MduQ3SFBWM7nuBc5obSmUf74Dcdy6S44CYNcHpA19 X-Received: by 2002:a05:690c:9a09:b0:8b4:f1a7:4190 with SMTP id 00721157ae682-8b520514f38mr142670737b3.104.1796095335857; Mon, 30 Nov 2026 19:22:15 -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.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Nov 2026 19:22:14 -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 3/4] xfrm: iptfs: free queued packets on SA delete to fix a netns UAF Date: Mon, 30 Nov 2026 22:21:59 -0500 Message-ID: <20261201032200.37030-4-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 IP-TFS sends outgoing packets from a timer: iptfs_output_collect() queues them on xtfs->queue, and iptfs_timer sends them after the configured delay. A queued packet keeps its SA alive through its xfrm route, and IP-TFS frees the queue and stops iptfs_timer only when the SA is destroyed, which cannot happen while the packets hold it. A forwarded packet has no socket that would keep the namespace alive. So when the network namespace is dismantled with a packet queued, the SA is deleted but survives, and iptfs_timer later sends the packet after the namespace has been freed, a use-after-free of struct net: BUG: KASAN: slab-use-after-free in xfrm_output_resume+0xdd2/0x1bf0 Read of size 8 at addr ff1100000d3c3ec0 by task swapper/0/0 Releasing the packet's route then reads the route counter from the same freed struct net. Namespace exit had already destroyed it, so the per-CPU access faults in timer context and the machine panics. An unprivileged user can trigger this from a user and network namespace, by forwarding a packet into an IP-TFS SA with a long send delay and leaving the namespace before the timer fires. Fix this in the delete_state callback added earlier in this series: free the queued packets and cancel iptfs_timer without waiting for it, and drop packets that reach iptfs_output_collect() once the SA is no longer valid, as xfrm_output_one() does. Since namespace exit now deletes the SAs in pre_exit, the queued packets release their routes before the xfrm dst_ops are torn down. Fixes: 0e4fbf013fa5 ("xfrm: iptfs: add user packet (tunnel ingress) handling") Cc: stable@vger.kernel.org Signed-off-by: Juan Agustin Niccolini --- Reproducer: https://github.com/AgusNicco/iptfs-uafs/blob/main/iptfs_output_netns_uaf.c net/xfrm/xfrm_iptfs.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c index da5729306a61..320de30ed8bd 100644 --- a/net/xfrm/xfrm_iptfs.c +++ b/net/xfrm/xfrm_iptfs.c @@ -1930,6 +1930,13 @@ static int iptfs_output_collect(struct net *net, struct sock *sk, struct sk_buff */ spin_lock_bh(&x->lock); + if (unlikely(x->km.state != XFRM_STATE_VALID)) { + spin_unlock_bh(&x->lock); + XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEINVALID); + kfree_skb_list(segs); + return -EINVAL; + } + skb_list_walk_safe(segs, skb, nskb) { skb_mark_not_on_list(skb); @@ -2788,6 +2795,10 @@ static void iptfs_delete_state(struct xfrm_state *x) __skb_queue_head_init(&list); + skb_queue_splice_init(&xtfs->queue, &list); + xtfs->queue_size = 0; + hrtimer_try_to_cancel(&xtfs->iptfs_timer); + spin_lock(&xtfs->drop_lock); WRITE_ONCE(xtfs->dead, true); if (xtfs->ra_newskb) { -- 2.53.0