From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796095337; b=gYd3zHrdfIXrxDiCqDpgahiFDRXS7n9gDeK65jclDq/aXX0UFac+8+hmgTuHZaSwJxGm I/2F9TdStoScVOvdF+ftmwiK3j887UiXCAtOoCgLVBe+xFDh0FdCPIRgxgWihjLNUwcS0 vY0/lW/nlZTLnyx8RPF4q+82oDC+4uyusVOZ008Goa+nvC+IQ+5c6u+pOf67T6LVQl6+U yuXXlqpxsRD7UwmHO/eHaQTGd3xIDHboJCrRVKqVz6QZzL1i0CfxHUx21hWATwutA6D/l NDbqbYx1NpuqjsUXqDAQxDTuVH6TjoJAJzGJjk9XFP9gqIAGVU87wNAH/fCIV85WZqg== 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-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=mHSg/aH0wMi3ODUhw+I1Gt5gvIXGnSzIhF9Godjm0qSxEKySsI2p0WuG8V4ZQQyBX/sh hpvlqatkHC5KKSQhfkv6Z3rCYaKL3eWUrZMLnDnCuJriFhAmsdhD18B/dzkbSP0pEva+c xdaKI96p8SxMoWuK7Fa45QIAAnT38zFTXJu30PDSz+6vtJguJMVH5sYR1hxjSW7IGy6QX raB4h7kHftn7iWXUzInh5PFF6GkptFAQ1fHRoPPxEbsRSEvzGxKAPvpg3Cg81V4W8CrOs L5bxrXmWAdWF/sMweo+xWt6UdfyClIzihmGXSSZd2bvJ8Ve8W2rKXmANMQdGpe60fWw== 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=KaZQEK7i; arc=none smtp.remote-ip=209.85.128.181 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (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 C74B8606A330 for ; Tue, 1 Dec 2026 03:22:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C74B8606A330 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=KaZQEK7i Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-8b360828905so105298687b3.2 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=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=7pnP2ln4JQlXuLwaFCbEmunrRfwNdp2ysnAZSg3o/ig=; b=KaZQEK7iLgLy7aPZJxyGqzAX40/6gZp9ucAe17NIhf7XSuHfobrgFOFwSWBio/NQnI ft1KhkL5D2LwAotn+xTU73a21iHP60XL+a1SbRaXfTOYo0kyjKuoJeDTgfA+fUCtZmWi Opj9CZnovSK3y4mJZK8cdiIgV0YFXkGh7X+VsWqJP3JGvl6ryiCxCWGYx6Hr79965xpV T9dEMif5W2MCzzVEPjACjxW2zjs2TfXhnXMbHS+6ZNExVE64sTQCjUnzs94S7K3TVYCk topViIw0nfnf0MffORtBCE3jmVZsfNFyyHq/rZ3E+Xvob/BIYHGirSNlhT0AJeOthgau PaWQ== 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=tt0dB+Ksw/zmA8+IzRMrKvMsV99vBLqQWeyKmOlmICIFi/7vLYUbR4z4HhBo0nmHHC uz47goirvQtcS4sXrdLvlI2BNdFNYzI4GbmW4BehlwhqExDRGxniM8JE5VexVA3kz4wV 19zsLxlJUF+nG2M7aVdl5X8yZaPv7IkQOa5qHn4+LTxn8wpL/Xxh0ukAW6leJOkHdUX9 PsjtNc5quc8LwX6adY1T7JjhFtvwaagrtdEKeMtjh4xpPH2qPWaAGFIhZBpSkQb0QHJa zRW/+ziMFw5LYlMGP9QrmnhSIHQ0Lj0H0AsaHVF0Il6jfRsGRZhrZpduLhNvF/Dbdb+P Vi+g== X-Gm-Message-State: APuU4Z89ahmWC+MRIXkkLeDQpopOX+8/C3fpwYzfGpn3GMbBDwqmrlv2 RCS4K1JWKzrLi42sZk/SlXxpH75eQvLCw2DRLh6y4mB1hhAOVVDBRP32 X-Gm-Gg: AZFdTZcepXCmY5uZ5M0rQHSG/gWdZJzlSb/PNEZc8Ax3t1jy7dilt16axm9CPJVWN7r Dcq4CntjNrOIqJmDjiWURwiBkeAZwQPDiVwZ4gqDVMFFKOrO+PPZWYlOgRh989cjD9HRmHQNd/7 AL9OziWwHxQZPUdU5J2CPGU7SkMJxOA8TZoByA22Dd0ofsbsjZPPROb5A/dCAnjLz7DKz186Y1t NoTk2InTwhtnxUmsInagBXbLw37EYM8i38AJeVDXXrtYMbAUqdYNf7vPV83PG9QxQMJO9Kq+/rI iaBvNtpiBp7SI0q409QA/VVRYeFPYJ3DvwqwmQwWMlgDkQzR0xEkUgibARDhKHyhsBpOH5fAN4X El3cWKdo0NDHqIya7uorXwBRsv5zNOzDTFlKq5CU29qm8YXtAzrOFhOYTRi4vlHa8pNq8MZSTEb tCIGiHiBOVTVt8tCzDHqfhe8voZlbEueXbijExAj34SxZhBIufxkuup4yOV02Ifae75/EpHR/id 95ruUwTTDUCNj20s2oyLK7a5b/XFaxZnqKF2toyfTI8dkVXqWfZxpuensbifLosQGTcDwCc0OUP caOiQSvlqS2rTDGVf5yq8nCdvgQa+AxfFvu9DmBADGYbPhROLGnK 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: 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 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